Add AI model pricing, Bedrock provider, and InferenceProvider/ModelFamily split (#18155)

## Summary

- **Model pricing overhaul**: All model constants updated with accurate
pricing in dollars per 1M tokens, including cached input rates, cache
creation rates, and tiered >200k context pricing
- **New providers**: Added Google (Gemini 3.x), Mistral, and AWS Bedrock
as inference providers. Bedrock serves Claude Opus 4.6 and Sonnet 4.6
via AWS, with proper credential handling following the existing S3/SES
pattern
- **InferenceProvider/ModelFamily split**: Refactored `ModelProvider`
into two orthogonal enums — `InferenceProvider` (who serves the model:
auth, SDK, metadata format) and `ModelFamily` (who created it: token
counting semantics). This eliminates growing `||` chains for token
normalization checks like `excludesCachedTokens`
- **Billing improvements**: Reasoning tokens charged at output rate,
cache token discounts applied accurately, real errors thrown to Sentry
on billing failures

## Test plan

- [x] All existing unit tests updated and passing (23 tests across 3
test files)
- [x] Lint passes for both twenty-server and twenty-front
- [ ] CI checks pass


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Félix Malfait
2026-02-22 14:39:04 +01:00
committed by GitHub
parent a900b4a4b4
commit 41f09c5a4c
37 changed files with 1462 additions and 383 deletions
@@ -19,6 +19,7 @@ import { type WorkspaceAuthContext } from 'src/engine/core-modules/auth/types/wo
import { ToolCategory } from 'src/engine/core-modules/tool-provider/enums/tool-category.enum';
import { ToolRegistryService } from 'src/engine/core-modules/tool-provider/services/tool-registry.service';
import { type AgentExecutionResult } from 'src/engine/metadata-modules/ai/ai-agent-execution/types/agent-execution-result.type';
import { extractCacheCreationTokensFromSteps } from 'src/engine/metadata-modules/ai/ai-billing/utils/extract-cache-creation-tokens.util';
import {
AgentException,
AgentExceptionCode,
@@ -185,6 +186,10 @@ export class AgentAsyncExecutorService {
},
});
const cacheCreationTokens = extractCacheCreationTokensFromSteps(
textResponse.steps,
);
const agentSchema =
agent?.responseFormat?.type === 'json'
? agent.responseFormat.schema
@@ -194,6 +199,7 @@ export class AgentAsyncExecutorService {
return {
result: { response: textResponse.text },
usage: textResponse.usage,
cacheCreationTokens,
};
}
@@ -222,6 +228,7 @@ export class AgentAsyncExecutorService {
(textResponse.usage?.totalTokens ?? 0) +
(output.usage?.totalTokens ?? 0),
},
cacheCreationTokens,
};
} catch (error) {
if (error instanceof AgentException) {
@@ -3,4 +3,5 @@ import { type LanguageModelUsage } from 'ai';
export interface AgentExecutionResult {
result: object;
usage: LanguageModelUsage;
cacheCreationTokens: number;
}