api.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. export type ApiProvider = "anthropic" | "openrouter" | "bedrock" | "vertex" | "openai"
  2. export interface ApiHandlerOptions {
  3. apiModelId?: string
  4. apiKey?: string // anthropic
  5. openRouterApiKey?: string
  6. awsAccessKey?: string
  7. awsSecretKey?: string
  8. awsSessionToken?: string
  9. awsRegion?: string
  10. vertexProjectId?: string
  11. vertexRegion?: string
  12. openAiBaseUrl?: string
  13. openAiApiKey?: string
  14. openAiModelId?: string
  15. }
  16. export type ApiConfiguration = ApiHandlerOptions & {
  17. apiProvider?: ApiProvider
  18. }
  19. // Models
  20. export interface ModelInfo {
  21. maxTokens: number
  22. contextWindow: number
  23. supportsImages: boolean
  24. supportsPromptCache: boolean
  25. inputPrice: number
  26. outputPrice: number
  27. cacheWritesPrice?: number
  28. cacheReadsPrice?: number
  29. }
  30. // Anthropic
  31. // https://docs.anthropic.com/en/docs/about-claude/models
  32. export type AnthropicModelId = keyof typeof anthropicModels
  33. export const anthropicDefaultModelId: AnthropicModelId = "claude-3-5-sonnet-20240620"
  34. export const anthropicModels = {
  35. "claude-3-5-sonnet-20240620": {
  36. maxTokens: 8192,
  37. contextWindow: 200_000,
  38. supportsImages: true,
  39. supportsPromptCache: true,
  40. inputPrice: 3.0, // $3 per million input tokens
  41. outputPrice: 15.0, // $15 per million output tokens
  42. cacheWritesPrice: 3.75, // $3.75 per million tokens
  43. cacheReadsPrice: 0.3, // $0.30 per million tokens
  44. },
  45. "claude-3-opus-20240229": {
  46. maxTokens: 4096,
  47. contextWindow: 200_000,
  48. supportsImages: true,
  49. supportsPromptCache: true,
  50. inputPrice: 15.0,
  51. outputPrice: 75.0,
  52. cacheWritesPrice: 18.75,
  53. cacheReadsPrice: 1.5,
  54. },
  55. "claude-3-sonnet-20240229": {
  56. maxTokens: 4096,
  57. contextWindow: 200_000,
  58. supportsImages: true,
  59. supportsPromptCache: false,
  60. inputPrice: 3.0,
  61. outputPrice: 15.0,
  62. },
  63. "claude-3-haiku-20240307": {
  64. maxTokens: 4096,
  65. contextWindow: 200_000,
  66. supportsImages: true,
  67. supportsPromptCache: true,
  68. inputPrice: 0.25,
  69. outputPrice: 1.25,
  70. cacheWritesPrice: 0.3,
  71. cacheReadsPrice: 0.03,
  72. },
  73. } as const satisfies Record<string, ModelInfo> // as const assertion makes the object deeply readonly
  74. // AWS Bedrock
  75. // https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html
  76. export type BedrockModelId = keyof typeof bedrockModels
  77. export const bedrockDefaultModelId: BedrockModelId = "anthropic.claude-3-5-sonnet-20240620-v1:0"
  78. export const bedrockModels = {
  79. "anthropic.claude-3-5-sonnet-20240620-v1:0": {
  80. maxTokens: 8192,
  81. contextWindow: 200_000,
  82. supportsImages: true,
  83. supportsPromptCache: false,
  84. inputPrice: 3.0,
  85. outputPrice: 15.0,
  86. },
  87. "anthropic.claude-3-opus-20240229-v1:0": {
  88. maxTokens: 4096,
  89. contextWindow: 200_000,
  90. supportsImages: true,
  91. supportsPromptCache: false,
  92. inputPrice: 15.0,
  93. outputPrice: 75.0,
  94. },
  95. "anthropic.claude-3-sonnet-20240229-v1:0": {
  96. maxTokens: 4096,
  97. contextWindow: 200_000,
  98. supportsImages: true,
  99. supportsPromptCache: false,
  100. inputPrice: 3.0,
  101. outputPrice: 15.0,
  102. },
  103. "anthropic.claude-3-haiku-20240307-v1:0": {
  104. maxTokens: 4096,
  105. contextWindow: 200_000,
  106. supportsImages: true,
  107. supportsPromptCache: false,
  108. inputPrice: 0.25,
  109. outputPrice: 1.25,
  110. },
  111. } as const satisfies Record<string, ModelInfo>
  112. // OpenRouter
  113. // https://openrouter.ai/models?order=newest&supported_parameters=tools
  114. export type OpenRouterModelId = keyof typeof openRouterModels
  115. export const openRouterDefaultModelId: OpenRouterModelId = "anthropic/claude-3.5-sonnet:beta"
  116. export const openRouterModels = {
  117. "anthropic/claude-3.5-sonnet:beta": {
  118. maxTokens: 8192,
  119. contextWindow: 200_000,
  120. supportsImages: true,
  121. supportsPromptCache: false,
  122. inputPrice: 3.0,
  123. outputPrice: 15.0,
  124. },
  125. "anthropic/claude-3-opus:beta": {
  126. maxTokens: 4096,
  127. contextWindow: 200_000,
  128. supportsImages: true,
  129. supportsPromptCache: false,
  130. inputPrice: 15,
  131. outputPrice: 75,
  132. },
  133. "anthropic/claude-3-sonnet:beta": {
  134. maxTokens: 4096,
  135. contextWindow: 200_000,
  136. supportsImages: true,
  137. supportsPromptCache: false,
  138. inputPrice: 3,
  139. outputPrice: 15,
  140. },
  141. "anthropic/claude-3-haiku:beta": {
  142. maxTokens: 4096,
  143. contextWindow: 200_000,
  144. supportsImages: true,
  145. supportsPromptCache: false,
  146. inputPrice: 0.25,
  147. outputPrice: 1.25,
  148. },
  149. "openai/gpt-4o-2024-08-06": {
  150. maxTokens: 16384,
  151. contextWindow: 128_000,
  152. supportsImages: true,
  153. supportsPromptCache: false,
  154. inputPrice: 2.5,
  155. outputPrice: 10,
  156. },
  157. "openai/gpt-4o-mini-2024-07-18": {
  158. maxTokens: 16384,
  159. contextWindow: 128_000,
  160. supportsImages: true,
  161. supportsPromptCache: false,
  162. inputPrice: 0.15,
  163. outputPrice: 0.6,
  164. },
  165. "openai/gpt-4-turbo": {
  166. maxTokens: 4096,
  167. contextWindow: 128_000,
  168. supportsImages: true,
  169. supportsPromptCache: false,
  170. inputPrice: 10,
  171. outputPrice: 30,
  172. },
  173. // llama 3.1 models cannot use tools yet
  174. // "meta-llama/llama-3.1-405b-instruct": {
  175. // maxTokens: 2048,
  176. // supportsImages: false,
  177. // inputPrice: 2.7,
  178. // outputPrice: 2.7,
  179. // },
  180. // "meta-llama/llama-3.1-70b-instruct": {
  181. // maxTokens: 2048,
  182. // supportsImages: false,
  183. // inputPrice: 0.52,
  184. // outputPrice: 0.75,
  185. // },
  186. // "meta-llama/llama-3.1-8b-instruct": {
  187. // maxTokens: 2048,
  188. // supportsImages: false,
  189. // inputPrice: 0.06,
  190. // outputPrice: 0.06,
  191. // },
  192. // OpenRouter needs to fix mapping gemini 1.5 responses for tool calls properly, they return content with line breaks formatted wrong (too many escapes), and throw errors for being in the wrong order when they're not. They also cannot handle feedback given to a request with multiple tools. Giving feedback to one tool use requests works fine. ("Please ensure that function response turn comes immediately after a function call turn. And the number of function response parts should be equal to number of function call parts of the function call turn.")
  193. // "google/gemini-pro-1.5": {
  194. // maxTokens: 8192,
  195. // supportsImages: false, // "Function Calling is not supported with non-text input"
  196. // inputPrice: 2.5,
  197. // outputPrice: 7.5,
  198. // },
  199. // "google/gemini-flash-1.5": {
  200. // maxTokens: 8192,
  201. // supportsImages: false, // "Function Calling is not supported with non-text input"
  202. // inputPrice: 0.25,
  203. // outputPrice: 0.75,
  204. // },
  205. // "google/gemini-pro": {
  206. // maxTokens: 8192,
  207. // supportsImages: false, // "Function Calling is not supported with non-text input"
  208. // inputPrice: 0.125,
  209. // outputPrice: 0.375,
  210. // },
  211. // while deepseek coder can use tools, it may sometimes send tool invocation as a text block
  212. "deepseek/deepseek-coder": {
  213. maxTokens: 4096,
  214. contextWindow: 128_000,
  215. supportsImages: false,
  216. supportsPromptCache: false,
  217. inputPrice: 0.14,
  218. outputPrice: 0.28,
  219. },
  220. // mistral models can use tools but aren't great at going step-by-step and proceeding to the next step
  221. "mistralai/mistral-large": {
  222. maxTokens: 8192,
  223. contextWindow: 128_000,
  224. supportsImages: false,
  225. supportsPromptCache: false,
  226. inputPrice: 3,
  227. outputPrice: 9,
  228. },
  229. // This model is not capable of complex system/tool prompts
  230. // "mistralai/mistral-7b-instruct-v0.1": {
  231. // maxTokens: 4096,
  232. // supportsImages: false,
  233. // inputPrice: 0.06,
  234. // outputPrice: 0.06,
  235. // },
  236. // cohere models are not capable of complex system/tool prompts
  237. // "cohere/command-r-plus": {
  238. // maxTokens: 4000,
  239. // supportsImages: false,
  240. // inputPrice: 3,
  241. // outputPrice: 15,
  242. // },
  243. // "cohere/command-r": {
  244. // maxTokens: 4000,
  245. // supportsImages: false,
  246. // inputPrice: 0.5,
  247. // outputPrice: 1.5,
  248. // },
  249. } as const satisfies Record<string, ModelInfo>
  250. // Vertex AI
  251. // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude
  252. export type VertexModelId = keyof typeof vertexModels
  253. export const vertexDefaultModelId: VertexModelId = "claude-3-5-sonnet@20240620"
  254. export const vertexModels = {
  255. "claude-3-5-sonnet@20240620": {
  256. maxTokens: 8192,
  257. contextWindow: 200_000,
  258. supportsImages: true,
  259. supportsPromptCache: false,
  260. inputPrice: 3.0,
  261. outputPrice: 15.0,
  262. },
  263. "claude-3-opus@20240229": {
  264. maxTokens: 4096,
  265. contextWindow: 200_000,
  266. supportsImages: true,
  267. supportsPromptCache: false,
  268. inputPrice: 15.0,
  269. outputPrice: 75.0,
  270. },
  271. "claude-3-sonnet@20240229": {
  272. maxTokens: 4096,
  273. contextWindow: 200_000,
  274. supportsImages: true,
  275. supportsPromptCache: false,
  276. inputPrice: 3.0,
  277. outputPrice: 15.0,
  278. },
  279. "claude-3-haiku@20240307": {
  280. maxTokens: 4096,
  281. contextWindow: 200_000,
  282. supportsImages: true,
  283. supportsPromptCache: false,
  284. inputPrice: 0.25,
  285. outputPrice: 1.25,
  286. },
  287. } as const satisfies Record<string, ModelInfo>
  288. export const openAiModelInfoSaneDefaults: ModelInfo = {
  289. maxTokens: -1,
  290. contextWindow: 128_000,
  291. supportsImages: true,
  292. supportsPromptCache: false,
  293. inputPrice: 0,
  294. outputPrice: 0,
  295. }