Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * What a live run cost. |
| 3 | * |
| 4 | * Claude Code reports its own cost. The minimal loop does not, so its cost is |
| 5 | * worked out from the token counts and the list prices below. |
| 6 | */ |
| 7 | |
| 8 | export interface Usage { |
| 9 | readonly costUsd: number; |
| 10 | readonly inputTokens: number; |
| 11 | readonly outputTokens: number; |
| 12 | readonly cacheReadTokens: number; |
| 13 | readonly cacheWriteTokens: number; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * USD per million tokens: Anthropic list prices as of 2026-11, with cache |
| 18 | * reads at 0.1x and 5-minute cache writes at 1.25x the input price. Only the |
| 19 | * models a live run may call (see `model-proxy.ts`) are listed. |
| 20 | */ |
| 21 | const PRICES: Readonly< |
| 22 | Record<string, { input: number; output: number; cacheRead: number; cacheWrite: number }> |
| 23 | > = { |
| 24 | // Prompts up to 100K tokens; a journey's prompt stays well under that. |
| 25 | 'claude-haiku-5-5': { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 }, |
| 26 | 'claude-opus-5-5': { input: 4, output: 20, cacheRead: 0.2, cacheWrite: 5 }, |
| 27 | }; |
| 28 | |
| 29 | export const ZERO_USAGE: Usage = { |
| 30 | costUsd: 0, |
| 31 | inputTokens: 0, |
| 32 | outputTokens: 0, |
| 33 | cacheReadTokens: 0, |
| 34 | cacheWriteTokens: 0, |
| 35 | }; |
| 36 | |
| 37 | export const addTokens = ( |
| 38 | usage: Usage, |
| 39 | model: string, |
| 40 | tokens: { input: number; output: number; cacheRead?: number; cacheWrite?: number } |
| 41 | ): Usage => { |
| 42 | // A replayed model (a fixture's `hand-authored`, a rehearsal stand-in) costs nothing. |
| 43 | const price = PRICES[model] ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }; |
| 44 | const cacheRead = tokens.cacheRead ?? 0; |
| 45 | const cacheWrite = tokens.cacheWrite ?? 0; |
| 46 | return { |
| 47 | costUsd: |
| 48 | usage.costUsd + |
| 49 | (tokens.input * price.input + |
| 50 | tokens.output * price.output + |
| 51 | cacheRead * price.cacheRead + |
| 52 | cacheWrite * price.cacheWrite) / |
| 53 | 1e6, |
| 54 | inputTokens: usage.inputTokens + tokens.input, |
| 55 | outputTokens: usage.outputTokens + tokens.output, |
| 56 | cacheReadTokens: usage.cacheReadTokens + cacheRead, |
| 57 | cacheWriteTokens: usage.cacheWriteTokens + cacheWrite, |
| 58 | }; |
| 59 | }; |