api.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. export type ApiProvider =
  2. | "anthropic"
  3. | "openrouter"
  4. | "bedrock"
  5. | "vertex"
  6. | "openai"
  7. | "ollama"
  8. | "gemini"
  9. | "openai-native"
  10. export interface ApiHandlerOptions {
  11. apiModelId?: string
  12. apiKey?: string // anthropic
  13. anthropicBaseUrl?: string
  14. openRouterApiKey?: string
  15. openRouterModelId?: string
  16. openRouterModelInfo?: ModelInfo
  17. awsAccessKey?: string
  18. awsSecretKey?: string
  19. awsSessionToken?: string
  20. awsRegion?: string
  21. awsUseCrossRegionInference?: boolean
  22. vertexProjectId?: string
  23. vertexRegion?: string
  24. openAiBaseUrl?: string
  25. openAiApiKey?: string
  26. openAiModelId?: string
  27. ollamaModelId?: string
  28. ollamaBaseUrl?: string
  29. geminiApiKey?: string
  30. openAiNativeApiKey?: string
  31. azureApiVersion?: string
  32. }
  33. export type ApiConfiguration = ApiHandlerOptions & {
  34. apiProvider?: ApiProvider
  35. }
  36. // Models
  37. export interface ModelInfo {
  38. maxTokens?: number
  39. contextWindow?: number
  40. supportsImages?: boolean
  41. supportsComputerUse?: boolean
  42. supportsPromptCache: boolean // this value is hardcoded for now
  43. inputPrice?: number
  44. outputPrice?: number
  45. cacheWritesPrice?: number
  46. cacheReadsPrice?: number
  47. description?: string
  48. }
  49. // Anthropic
  50. // https://docs.anthropic.com/en/docs/about-claude/models
  51. export type AnthropicModelId = keyof typeof anthropicModels
  52. export const anthropicDefaultModelId: AnthropicModelId = "claude-3-5-sonnet-20241022"
  53. export const anthropicModels = {
  54. "claude-3-5-sonnet-20241022": {
  55. maxTokens: 8192,
  56. contextWindow: 200_000,
  57. supportsImages: true,
  58. supportsComputerUse: true,
  59. supportsPromptCache: true,
  60. inputPrice: 3.0, // $3 per million input tokens
  61. outputPrice: 15.0, // $15 per million output tokens
  62. cacheWritesPrice: 3.75, // $3.75 per million tokens
  63. cacheReadsPrice: 0.3, // $0.30 per million tokens
  64. },
  65. "claude-3-5-haiku-20241022": {
  66. maxTokens: 8192,
  67. contextWindow: 200_000,
  68. supportsImages: false,
  69. supportsPromptCache: true,
  70. inputPrice: 1.0,
  71. outputPrice: 5.0,
  72. cacheWritesPrice: 1.25,
  73. cacheReadsPrice: 0.1,
  74. },
  75. "claude-3-opus-20240229": {
  76. maxTokens: 4096,
  77. contextWindow: 200_000,
  78. supportsImages: true,
  79. supportsPromptCache: true,
  80. inputPrice: 15.0,
  81. outputPrice: 75.0,
  82. cacheWritesPrice: 18.75,
  83. cacheReadsPrice: 1.5,
  84. },
  85. "claude-3-haiku-20240307": {
  86. maxTokens: 4096,
  87. contextWindow: 200_000,
  88. supportsImages: true,
  89. supportsPromptCache: true,
  90. inputPrice: 0.25,
  91. outputPrice: 1.25,
  92. cacheWritesPrice: 0.3,
  93. cacheReadsPrice: 0.03,
  94. },
  95. } as const satisfies Record<string, ModelInfo> // as const assertion makes the object deeply readonly
  96. // AWS Bedrock
  97. // https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html
  98. export type BedrockModelId = keyof typeof bedrockModels
  99. export const bedrockDefaultModelId: BedrockModelId = "anthropic.claude-3-5-sonnet-20241022-v2:0"
  100. export const bedrockModels = {
  101. "anthropic.claude-3-5-sonnet-20241022-v2:0": {
  102. maxTokens: 8192,
  103. contextWindow: 200_000,
  104. supportsImages: true,
  105. supportsComputerUse: true,
  106. supportsPromptCache: false,
  107. inputPrice: 3.0,
  108. outputPrice: 15.0,
  109. },
  110. "anthropic.claude-3-5-haiku-20241022-v1:0": {
  111. maxTokens: 8192,
  112. contextWindow: 200_000,
  113. supportsImages: false,
  114. supportsPromptCache: false,
  115. inputPrice: 1.0,
  116. outputPrice: 5.0,
  117. },
  118. "anthropic.claude-3-5-sonnet-20240620-v1:0": {
  119. maxTokens: 8192,
  120. contextWindow: 200_000,
  121. supportsImages: true,
  122. supportsPromptCache: false,
  123. inputPrice: 3.0,
  124. outputPrice: 15.0,
  125. },
  126. "anthropic.claude-3-opus-20240229-v1:0": {
  127. maxTokens: 4096,
  128. contextWindow: 200_000,
  129. supportsImages: true,
  130. supportsPromptCache: false,
  131. inputPrice: 15.0,
  132. outputPrice: 75.0,
  133. },
  134. "anthropic.claude-3-sonnet-20240229-v1:0": {
  135. maxTokens: 4096,
  136. contextWindow: 200_000,
  137. supportsImages: true,
  138. supportsPromptCache: false,
  139. inputPrice: 3.0,
  140. outputPrice: 15.0,
  141. },
  142. "anthropic.claude-3-haiku-20240307-v1:0": {
  143. maxTokens: 4096,
  144. contextWindow: 200_000,
  145. supportsImages: true,
  146. supportsPromptCache: false,
  147. inputPrice: 0.25,
  148. outputPrice: 1.25,
  149. },
  150. } as const satisfies Record<string, ModelInfo>
  151. // OpenRouter
  152. // https://openrouter.ai/models?order=newest&supported_parameters=tools
  153. export const openRouterDefaultModelId = "anthropic/claude-3.5-sonnet:beta" // will always exist in openRouterModels
  154. export const openRouterDefaultModelInfo: ModelInfo = {
  155. maxTokens: 8192,
  156. contextWindow: 200_000,
  157. supportsImages: true,
  158. supportsComputerUse: true,
  159. supportsPromptCache: true,
  160. inputPrice: 3.0,
  161. outputPrice: 15.0,
  162. cacheWritesPrice: 3.75,
  163. cacheReadsPrice: 0.3,
  164. description:
  165. "The new Claude 3.5 Sonnet delivers better-than-Opus capabilities, faster-than-Sonnet speeds, at the same Sonnet prices. Sonnet is particularly good at:\n\n- Coding: New Sonnet scores ~49% on SWE-Bench Verified, higher than the last best score, and without any fancy prompt scaffolding\n- Data science: Augments human data science expertise; navigates unstructured data while using multiple tools for insights\n- Visual processing: excelling at interpreting charts, graphs, and images, accurately transcribing text to derive insights beyond just the text alone\n- Agentic tasks: exceptional tool use, making it great at agentic tasks (i.e. complex, multi-step problem solving tasks that require engaging with other systems)\n\n#multimodal\n\n_This is a faster endpoint, made available in collaboration with Anthropic, that is self-moderated: response moderation happens on the provider's side instead of OpenRouter's. For requests that pass moderation, it's identical to the [Standard](/anthropic/claude-3.5-sonnet) variant._",
  166. }
  167. // Vertex AI
  168. // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude
  169. export type VertexModelId = keyof typeof vertexModels
  170. export const vertexDefaultModelId: VertexModelId = "claude-3-5-sonnet-v2@20241022"
  171. export const vertexModels = {
  172. "claude-3-5-sonnet-v2@20241022": {
  173. maxTokens: 8192,
  174. contextWindow: 200_000,
  175. supportsImages: true,
  176. supportsComputerUse: true,
  177. supportsPromptCache: false,
  178. inputPrice: 3.0,
  179. outputPrice: 15.0,
  180. },
  181. "claude-3-5-sonnet@20240620": {
  182. maxTokens: 8192,
  183. contextWindow: 200_000,
  184. supportsImages: true,
  185. supportsPromptCache: false,
  186. inputPrice: 3.0,
  187. outputPrice: 15.0,
  188. },
  189. "claude-3-5-haiku@20241022": {
  190. maxTokens: 8192,
  191. contextWindow: 200_000,
  192. supportsImages: false,
  193. supportsPromptCache: false,
  194. inputPrice: 1.0,
  195. outputPrice: 5.0,
  196. },
  197. "claude-3-opus@20240229": {
  198. maxTokens: 4096,
  199. contextWindow: 200_000,
  200. supportsImages: true,
  201. supportsPromptCache: false,
  202. inputPrice: 15.0,
  203. outputPrice: 75.0,
  204. },
  205. "claude-3-haiku@20240307": {
  206. maxTokens: 4096,
  207. contextWindow: 200_000,
  208. supportsImages: true,
  209. supportsPromptCache: false,
  210. inputPrice: 0.25,
  211. outputPrice: 1.25,
  212. },
  213. } as const satisfies Record<string, ModelInfo>
  214. export const openAiModelInfoSaneDefaults: ModelInfo = {
  215. maxTokens: -1,
  216. contextWindow: 128_000,
  217. supportsImages: true,
  218. supportsPromptCache: false,
  219. inputPrice: 0,
  220. outputPrice: 0,
  221. }
  222. // Gemini
  223. // https://ai.google.dev/gemini-api/docs/models/gemini
  224. export type GeminiModelId = keyof typeof geminiModels
  225. export const geminiDefaultModelId: GeminiModelId = "gemini-1.5-flash-002"
  226. export const geminiModels = {
  227. "gemini-1.5-flash-002": {
  228. maxTokens: 8192,
  229. contextWindow: 1_048_576,
  230. supportsImages: true,
  231. supportsPromptCache: false,
  232. inputPrice: 0,
  233. outputPrice: 0,
  234. },
  235. "gemini-1.5-flash-exp-0827": {
  236. maxTokens: 8192,
  237. contextWindow: 1_048_576,
  238. supportsImages: true,
  239. supportsPromptCache: false,
  240. inputPrice: 0,
  241. outputPrice: 0,
  242. },
  243. "gemini-1.5-flash-8b-exp-0827": {
  244. maxTokens: 8192,
  245. contextWindow: 1_048_576,
  246. supportsImages: true,
  247. supportsPromptCache: false,
  248. inputPrice: 0,
  249. outputPrice: 0,
  250. },
  251. "gemini-1.5-pro-002": {
  252. maxTokens: 8192,
  253. contextWindow: 2_097_152,
  254. supportsImages: true,
  255. supportsPromptCache: false,
  256. inputPrice: 0,
  257. outputPrice: 0,
  258. },
  259. "gemini-1.5-pro-exp-0827": {
  260. maxTokens: 8192,
  261. contextWindow: 2_097_152,
  262. supportsImages: true,
  263. supportsPromptCache: false,
  264. inputPrice: 0,
  265. outputPrice: 0,
  266. },
  267. } as const satisfies Record<string, ModelInfo>
  268. // OpenAI Native
  269. // https://openai.com/api/pricing/
  270. export type OpenAiNativeModelId = keyof typeof openAiNativeModels
  271. export const openAiNativeDefaultModelId: OpenAiNativeModelId = "gpt-4o"
  272. export const openAiNativeModels = {
  273. // don't support tool use yet
  274. "o1-preview": {
  275. maxTokens: 32_768,
  276. contextWindow: 128_000,
  277. supportsImages: true,
  278. supportsPromptCache: false,
  279. inputPrice: 15,
  280. outputPrice: 60,
  281. },
  282. "o1-mini": {
  283. maxTokens: 65_536,
  284. contextWindow: 128_000,
  285. supportsImages: true,
  286. supportsPromptCache: false,
  287. inputPrice: 3,
  288. outputPrice: 12,
  289. },
  290. "gpt-4o": {
  291. maxTokens: 4_096,
  292. contextWindow: 128_000,
  293. supportsImages: true,
  294. supportsPromptCache: false,
  295. inputPrice: 5,
  296. outputPrice: 15,
  297. },
  298. "gpt-4o-mini": {
  299. maxTokens: 16_384,
  300. contextWindow: 128_000,
  301. supportsImages: true,
  302. supportsPromptCache: false,
  303. inputPrice: 0.15,
  304. outputPrice: 0.6,
  305. },
  306. } as const satisfies Record<string, ModelInfo>
  307. // Azure OpenAI
  308. // https://learn.microsoft.com/en-us/azure/ai-services/openai/api-version-deprecation
  309. // https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs
  310. export const azureOpenAiDefaultApiVersion = "2024-08-01-preview"