The src/
directory contains the per-LLM provider costs calculation code. Please help keep this code up to date by submitting PRs when costs change
-
Add new cost data to the
costs/src/
directory. If provider folder exists, add to its index.ts. If not, create a new folder with the provider name and an index.ts and export a cost objectExample:
File name:
costs/src/anthropic/index.ts
export const costs: ModelRow[] = [ { model: { operator: "equals", value: "claude-instant-1", }, cost: { prompt_token: 0.00000163, completion_token: 0.0000551, }, }, ];
We can match in 3 ways:
equals
: The model name must be exactly the same as the valuestartsWith
: The model name must start with the valueincludes
: The model name must include the value
Use what is most appropriate for the model
cost object is the cost per token for prompt and completion
-
Import the new cost data into
src/providers/mappings.ts
and add it to theproviders
arrayExample:
File name:
src/providers/mappings.ts
import { costs as anthropicCosts } from "./providers/anthropic"; // 1. Add the pattern for the API so it is a valid gateway. const anthropicPattern = /^https:\/\/api\.anthropic\.com/; // 2. Add Anthropic pattern, provider tag, and costs array from the generated list export const providers: { pattern: RegExp; provider: string; costs?: ModelRow[]; }[] = [ // ... { pattern: anthropicPattern, provider: "ANTHROPIC", costs: anthropicCosts, }, // ... ];
-
Run
yarn test -- -u
in thecost/
directory to update the snapshot tests -
Run
yarn copy
in thecost/
directory to copy the cost data into other directories