@mastra/core 0.18.1-alpha.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/dist/agent/agent.d.ts +19 -9
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +11 -11
  5. package/dist/agent/index.d.ts +1 -1
  6. package/dist/agent/index.d.ts.map +1 -1
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/input-processor/index.cjs +6 -6
  9. package/dist/agent/input-processor/index.js +1 -1
  10. package/dist/agent/types.d.ts +13 -8
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/ai-tracing/exporters/default.d.ts +2 -2
  13. package/dist/ai-tracing/exporters/default.d.ts.map +1 -1
  14. package/dist/ai-tracing/index.cjs +32 -32
  15. package/dist/ai-tracing/index.js +1 -1
  16. package/dist/ai-tracing/types.d.ts +2 -2
  17. package/dist/ai-tracing/types.d.ts.map +1 -1
  18. package/dist/{chunk-ITD7IHN5.js → chunk-2DGWSOVQ.js} +23 -5
  19. package/dist/chunk-2DGWSOVQ.js.map +1 -0
  20. package/dist/{chunk-4PK4GBYZ.cjs → chunk-2GHLV754.cjs} +5 -4
  21. package/dist/chunk-2GHLV754.cjs.map +1 -0
  22. package/dist/{chunk-LL2X7QT7.js → chunk-3WFH6YRI.js} +4 -4
  23. package/dist/{chunk-LL2X7QT7.js.map → chunk-3WFH6YRI.js.map} +1 -1
  24. package/dist/chunk-45CV4JYJ.cjs +4 -0
  25. package/dist/{chunk-VBPPPQO3.cjs.map → chunk-45CV4JYJ.cjs.map} +1 -1
  26. package/dist/{chunk-SEZBEL3U.js → chunk-4BEHJSL6.js} +4 -4
  27. package/dist/{chunk-SEZBEL3U.js.map → chunk-4BEHJSL6.js.map} +1 -1
  28. package/dist/chunk-4LSFAAZW.js +3 -0
  29. package/dist/{chunk-CE73R5W7.js.map → chunk-4LSFAAZW.js.map} +1 -1
  30. package/dist/{chunk-XUAWHRUO.cjs → chunk-4R2TBRS7.cjs} +37 -112
  31. package/dist/chunk-4R2TBRS7.cjs.map +1 -0
  32. package/dist/{chunk-ITBUHG4U.cjs → chunk-4VNAMG7K.cjs} +6 -6
  33. package/dist/{chunk-ITBUHG4U.cjs.map → chunk-4VNAMG7K.cjs.map} +1 -1
  34. package/dist/{chunk-B4REUTZB.js → chunk-5BQOHHCI.js} +5 -5
  35. package/dist/{chunk-B4REUTZB.js.map → chunk-5BQOHHCI.js.map} +1 -1
  36. package/dist/{chunk-FXLZYRV7.js → chunk-5HCVPQTD.js} +3 -3
  37. package/dist/{chunk-FXLZYRV7.js.map → chunk-5HCVPQTD.js.map} +1 -1
  38. package/dist/chunk-5M6ZTQJN.js +1374 -0
  39. package/dist/chunk-5M6ZTQJN.js.map +1 -0
  40. package/dist/{chunk-SW7WPHZ2.cjs → chunk-7E4ESNZS.cjs} +5 -5
  41. package/dist/{chunk-SW7WPHZ2.cjs.map → chunk-7E4ESNZS.cjs.map} +1 -1
  42. package/dist/{chunk-NTS6B2I2.cjs → chunk-A4RAEU6X.cjs} +2 -2
  43. package/dist/{chunk-NTS6B2I2.cjs.map → chunk-A4RAEU6X.cjs.map} +1 -1
  44. package/dist/{chunk-QUB6MWXZ.cjs → chunk-BCWRUNMS.cjs} +38 -37
  45. package/dist/chunk-BCWRUNMS.cjs.map +1 -0
  46. package/dist/{chunk-245ANI3P.js → chunk-BUY5X7DT.js} +4 -4
  47. package/dist/{chunk-245ANI3P.js.map → chunk-BUY5X7DT.js.map} +1 -1
  48. package/dist/{chunk-6ZVNL435.js → chunk-COC64XPP.js} +9 -8
  49. package/dist/chunk-COC64XPP.js.map +1 -0
  50. package/dist/{chunk-6X4FZVGT.cjs → chunk-CQ73JM2N.cjs} +10 -10
  51. package/dist/{chunk-6X4FZVGT.cjs.map → chunk-CQ73JM2N.cjs.map} +1 -1
  52. package/dist/{chunk-7UEBC5KM.cjs → chunk-DRVSEV5Y.cjs} +25 -65
  53. package/dist/chunk-DRVSEV5Y.cjs.map +1 -0
  54. package/dist/{chunk-2TQHRYRK.cjs → chunk-EPMJYNEK.cjs} +4 -4
  55. package/dist/{chunk-2TQHRYRK.cjs.map → chunk-EPMJYNEK.cjs.map} +1 -1
  56. package/dist/{chunk-TKFLL33F.cjs → chunk-F6EJEELE.cjs} +9 -9
  57. package/dist/{chunk-TKFLL33F.cjs.map → chunk-F6EJEELE.cjs.map} +1 -1
  58. package/dist/{chunk-4DNSY645.js → chunk-FV3SA5TI.js} +3 -3
  59. package/dist/{chunk-4DNSY645.js.map → chunk-FV3SA5TI.js.map} +1 -1
  60. package/dist/{chunk-EJ2FU45N.js → chunk-FV4QVXO4.js} +2 -2
  61. package/dist/{chunk-EJ2FU45N.js.map → chunk-FV4QVXO4.js.map} +1 -1
  62. package/dist/{chunk-CKZK2EPZ.cjs → chunk-HNBU4PI7.cjs} +4 -4
  63. package/dist/{chunk-CKZK2EPZ.cjs.map → chunk-HNBU4PI7.cjs.map} +1 -1
  64. package/dist/{chunk-O6PQYYT6.cjs → chunk-HQPFM22N.cjs} +63 -45
  65. package/dist/chunk-HQPFM22N.cjs.map +1 -0
  66. package/dist/{chunk-36DRWGP4.js → chunk-IAXAPVOP.js} +4 -4
  67. package/dist/{chunk-36DRWGP4.js.map → chunk-IAXAPVOP.js.map} +1 -1
  68. package/dist/{chunk-5ZMC3NEO.js → chunk-JKLLXBOY.js} +46 -39
  69. package/dist/chunk-JKLLXBOY.js.map +1 -0
  70. package/dist/{chunk-WVRSMHE5.cjs → chunk-K4AYIXVH.cjs} +4 -4
  71. package/dist/{chunk-WVRSMHE5.cjs.map → chunk-K4AYIXVH.cjs.map} +1 -1
  72. package/dist/{chunk-SALFMUAY.cjs → chunk-LZBVDMVQ.cjs} +19 -19
  73. package/dist/{chunk-SALFMUAY.cjs.map → chunk-LZBVDMVQ.cjs.map} +1 -1
  74. package/dist/{chunk-RPFJBB5X.js → chunk-N4PK4MOG.js} +4 -4
  75. package/dist/{chunk-RPFJBB5X.js.map → chunk-N4PK4MOG.js.map} +1 -1
  76. package/dist/{chunk-QBTRGHUF.cjs → chunk-NHJVMZIL.cjs} +19 -19
  77. package/dist/{chunk-QBTRGHUF.cjs.map → chunk-NHJVMZIL.cjs.map} +1 -1
  78. package/dist/{chunk-BJZWMVNW.js → chunk-OBIF7QD5.js} +3 -3
  79. package/dist/{chunk-BJZWMVNW.js.map → chunk-OBIF7QD5.js.map} +1 -1
  80. package/dist/{chunk-VZLNVGYM.cjs → chunk-PG6ZNDSR.cjs} +21 -21
  81. package/dist/{chunk-VZLNVGYM.cjs.map → chunk-PG6ZNDSR.cjs.map} +1 -1
  82. package/dist/{chunk-XWJWU5OM.js → chunk-PJ6HF3KW.js} +16 -56
  83. package/dist/chunk-PJ6HF3KW.js.map +1 -0
  84. package/dist/{chunk-NG2XDPDY.js → chunk-RAXBZZKS.js} +4 -3
  85. package/dist/chunk-RAXBZZKS.js.map +1 -0
  86. package/dist/chunk-RFGQ3EQV.js +3 -0
  87. package/dist/chunk-RFGQ3EQV.js.map +1 -0
  88. package/dist/{chunk-73S2WYSD.cjs → chunk-RNIY63FP.cjs} +85 -78
  89. package/dist/chunk-RNIY63FP.cjs.map +1 -0
  90. package/dist/{chunk-ROU7YJLG.js → chunk-RYFQKXXS.js} +3 -3
  91. package/dist/{chunk-ROU7YJLG.js.map → chunk-RYFQKXXS.js.map} +1 -1
  92. package/dist/{chunk-C73WLCY3.cjs → chunk-S7UXT3V4.cjs} +21 -3
  93. package/dist/chunk-S7UXT3V4.cjs.map +1 -0
  94. package/dist/{chunk-R5GESRGB.js → chunk-SJMKDSRF.js} +37 -112
  95. package/dist/chunk-SJMKDSRF.js.map +1 -0
  96. package/dist/{chunk-YWXSGDDO.cjs → chunk-SQQMX4VC.cjs} +6 -6
  97. package/dist/{chunk-YWXSGDDO.cjs.map → chunk-SQQMX4VC.cjs.map} +1 -1
  98. package/dist/chunk-TCHOIK53.cjs +4 -0
  99. package/dist/chunk-TCHOIK53.cjs.map +1 -0
  100. package/dist/chunk-TIBULEK6.cjs +1379 -0
  101. package/dist/chunk-TIBULEK6.cjs.map +1 -0
  102. package/dist/{chunk-WECJNCGT.cjs → chunk-UTEH2LCJ.cjs} +19 -19
  103. package/dist/{chunk-WECJNCGT.cjs.map → chunk-UTEH2LCJ.cjs.map} +1 -1
  104. package/dist/{chunk-VGU5ZYYG.js → chunk-VWO3JJXC.js} +4 -4
  105. package/dist/{chunk-VGU5ZYYG.js.map → chunk-VWO3JJXC.js.map} +1 -1
  106. package/dist/{chunk-MCOVMKIS.js → chunk-WHFNGECY.js} +21 -4
  107. package/dist/chunk-WHFNGECY.js.map +1 -0
  108. package/dist/{chunk-NTXNE4YR.js → chunk-XG3SFWOH.js} +3 -3
  109. package/dist/{chunk-NTXNE4YR.js.map → chunk-XG3SFWOH.js.map} +1 -1
  110. package/dist/error/index.cjs +5 -5
  111. package/dist/error/index.d.ts.map +1 -1
  112. package/dist/error/index.js +1 -1
  113. package/dist/error/utils.d.ts +8 -0
  114. package/dist/error/utils.d.ts.map +1 -0
  115. package/dist/eval/index.cjs +3 -3
  116. package/dist/eval/index.js +1 -1
  117. package/dist/index.cjs +84 -67
  118. package/dist/index.cjs.map +1 -1
  119. package/dist/index.js +18 -17
  120. package/dist/index.js.map +1 -1
  121. package/dist/integration/index.cjs +3 -3
  122. package/dist/integration/index.js +1 -1
  123. package/dist/llm/index.cjs +20 -0
  124. package/dist/llm/index.d.ts +3 -1
  125. package/dist/llm/index.d.ts.map +1 -1
  126. package/dist/llm/index.js +1 -1
  127. package/dist/llm/model/gateways/base.d.ts +42 -0
  128. package/dist/llm/model/gateways/base.d.ts.map +1 -0
  129. package/dist/llm/model/gateways/index.d.ts +3 -0
  130. package/dist/llm/model/gateways/index.d.ts.map +1 -0
  131. package/dist/llm/model/gateways/models-dev.d.ts +11 -0
  132. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -0
  133. package/dist/llm/model/index.d.ts +2 -0
  134. package/dist/llm/model/index.d.ts.map +1 -1
  135. package/dist/llm/model/model.loop.d.ts.map +1 -1
  136. package/dist/llm/model/openai-compatible.d.ts +32 -0
  137. package/dist/llm/model/openai-compatible.d.ts.map +1 -0
  138. package/dist/llm/model/provider-registry.generated.d.ts +462 -0
  139. package/dist/llm/model/provider-registry.generated.d.ts.map +1 -0
  140. package/dist/llm/model/shared.types.d.ts +8 -0
  141. package/dist/llm/model/shared.types.d.ts.map +1 -1
  142. package/dist/loop/index.cjs +2 -2
  143. package/dist/loop/index.js +1 -1
  144. package/dist/loop/network/index.d.ts.map +1 -1
  145. package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
  146. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  147. package/dist/loop/test-utils/options.d.ts.map +1 -1
  148. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  149. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  150. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  151. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  152. package/dist/loop/workflows/agentic-execution/index.d.ts +99 -0
  153. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  154. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +66 -0
  155. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  156. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +33 -0
  157. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  158. package/dist/loop/workflows/agentic-loop/index.d.ts +99 -0
  159. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  160. package/dist/loop/workflows/run-state.d.ts +5 -0
  161. package/dist/loop/workflows/run-state.d.ts.map +1 -1
  162. package/dist/loop/workflows/schema.d.ts +38 -0
  163. package/dist/loop/workflows/schema.d.ts.map +1 -1
  164. package/dist/mastra/index.cjs +2 -2
  165. package/dist/mastra/index.d.ts.map +1 -1
  166. package/dist/mastra/index.js +1 -1
  167. package/dist/memory/index.cjs +4 -4
  168. package/dist/memory/index.js +1 -1
  169. package/dist/network/vNext/index.cjs +30 -30
  170. package/dist/network/vNext/index.cjs.map +1 -1
  171. package/dist/network/vNext/index.js +3 -3
  172. package/dist/network/vNext/index.js.map +1 -1
  173. package/dist/processors/index.cjs +10 -10
  174. package/dist/processors/index.js +1 -1
  175. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  176. package/dist/processors/processors/moderation.d.ts.map +1 -1
  177. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  178. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  179. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  180. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  181. package/dist/relevance/index.cjs +4 -4
  182. package/dist/relevance/index.js +1 -1
  183. package/dist/scores/index.cjs +9 -9
  184. package/dist/scores/index.js +2 -2
  185. package/dist/scores/scoreTraces/index.cjs +57 -68
  186. package/dist/scores/scoreTraces/index.cjs.map +1 -1
  187. package/dist/scores/scoreTraces/index.js +48 -59
  188. package/dist/scores/scoreTraces/index.js.map +1 -1
  189. package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  190. package/dist/scores/scoreTraces/utils.d.ts +4 -8
  191. package/dist/scores/scoreTraces/utils.d.ts.map +1 -1
  192. package/dist/scores/types.d.ts +8 -4
  193. package/dist/scores/types.d.ts.map +1 -1
  194. package/dist/server/index.cjs +7 -7
  195. package/dist/server/index.js +2 -2
  196. package/dist/storage/base.d.ts +14 -5
  197. package/dist/storage/base.d.ts.map +1 -1
  198. package/dist/storage/constants.d.ts.map +1 -1
  199. package/dist/storage/domains/observability/base.d.ts +5 -5
  200. package/dist/storage/domains/observability/base.d.ts.map +1 -1
  201. package/dist/storage/domains/observability/inmemory.d.ts +7 -7
  202. package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
  203. package/dist/storage/domains/scores/base.d.ts +8 -0
  204. package/dist/storage/domains/scores/base.d.ts.map +1 -1
  205. package/dist/storage/domains/scores/inmemory.d.ts +8 -0
  206. package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
  207. package/dist/storage/index.cjs +94 -64
  208. package/dist/storage/index.cjs.map +1 -1
  209. package/dist/storage/index.js +59 -29
  210. package/dist/storage/index.js.map +1 -1
  211. package/dist/storage/mock.d.ts +9 -0
  212. package/dist/storage/mock.d.ts.map +1 -1
  213. package/dist/storage/types.d.ts +2 -0
  214. package/dist/storage/types.d.ts.map +1 -1
  215. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  216. package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
  217. package/dist/stream/aisdk/v5/output.d.ts +7 -0
  218. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  219. package/dist/stream/base/output.d.ts.map +1 -1
  220. package/dist/stream/index.cjs +4 -4
  221. package/dist/stream/index.js +1 -1
  222. package/dist/stream/types.d.ts +12 -12
  223. package/dist/stream/types.d.ts.map +1 -1
  224. package/dist/telemetry/index.cjs +7 -7
  225. package/dist/telemetry/index.js +1 -1
  226. package/dist/test-utils/llm-mock.cjs +2 -2
  227. package/dist/test-utils/llm-mock.js +1 -1
  228. package/dist/tools/index.cjs +4 -4
  229. package/dist/tools/index.js +1 -1
  230. package/dist/tools/is-vercel-tool.cjs +2 -2
  231. package/dist/tools/is-vercel-tool.js +1 -1
  232. package/dist/tools/tool.d.ts +2 -4
  233. package/dist/tools/tool.d.ts.map +1 -1
  234. package/dist/tools/types.d.ts +1 -1
  235. package/dist/tools/types.d.ts.map +1 -1
  236. package/dist/tts/index.cjs +2 -2
  237. package/dist/tts/index.js +1 -1
  238. package/dist/{types.d.ts → types/dynamic-argument.d.ts} +3 -3
  239. package/dist/types/dynamic-argument.d.ts.map +1 -0
  240. package/dist/types/index.cjs +4 -0
  241. package/dist/types/index.cjs.map +1 -0
  242. package/dist/types/index.d.ts +2 -0
  243. package/dist/types/index.d.ts.map +1 -0
  244. package/dist/types/index.js +3 -0
  245. package/dist/types/index.js.map +1 -0
  246. package/dist/utils.cjs +17 -17
  247. package/dist/utils.js +1 -1
  248. package/dist/vector/index.cjs +4 -4
  249. package/dist/vector/index.js +1 -1
  250. package/dist/voice/index.cjs +4 -4
  251. package/dist/voice/index.js +1 -1
  252. package/dist/workflows/default.d.ts.map +1 -1
  253. package/dist/workflows/evented/index.cjs +10 -10
  254. package/dist/workflows/evented/index.js +1 -1
  255. package/dist/workflows/index.cjs +12 -12
  256. package/dist/workflows/index.js +1 -1
  257. package/dist/workflows/legacy/index.cjs +22 -22
  258. package/dist/workflows/legacy/index.js +1 -1
  259. package/dist/workflows/types.d.ts +11 -1
  260. package/dist/workflows/types.d.ts.map +1 -1
  261. package/dist/workflows/workflow.d.ts +6 -3
  262. package/dist/workflows/workflow.d.ts.map +1 -1
  263. package/package.json +4 -4
  264. package/types.d.ts +1 -0
  265. package/dist/chunk-4PK4GBYZ.cjs.map +0 -1
  266. package/dist/chunk-5ZMC3NEO.js.map +0 -1
  267. package/dist/chunk-6ZVNL435.js.map +0 -1
  268. package/dist/chunk-73S2WYSD.cjs.map +0 -1
  269. package/dist/chunk-7UEBC5KM.cjs.map +0 -1
  270. package/dist/chunk-C73WLCY3.cjs.map +0 -1
  271. package/dist/chunk-CE73R5W7.js +0 -3
  272. package/dist/chunk-ITD7IHN5.js.map +0 -1
  273. package/dist/chunk-MCOVMKIS.js.map +0 -1
  274. package/dist/chunk-NG2XDPDY.js.map +0 -1
  275. package/dist/chunk-O6PQYYT6.cjs.map +0 -1
  276. package/dist/chunk-QUB6MWXZ.cjs.map +0 -1
  277. package/dist/chunk-R5GESRGB.js.map +0 -1
  278. package/dist/chunk-VBPPPQO3.cjs +0 -4
  279. package/dist/chunk-XUAWHRUO.cjs.map +0 -1
  280. package/dist/chunk-XWJWU5OM.js.map +0 -1
  281. package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,1374 @@
1
+ // src/llm/model/provider-registry.generated.ts
2
+ var PROVIDER_REGISTRY = {
3
+ "moonshotai-cn": {
4
+ url: "https://api.moonshot.cn/v1/chat/completions",
5
+ apiKeyEnvVar: "MOONSHOT_API_KEY",
6
+ apiKeyHeader: "Authorization",
7
+ name: "Moonshot AI (China)",
8
+ models: ["kimi-k2-0711-preview", "kimi-k2-0905-preview", "kimi-k2-turbo-preview"],
9
+ docUrl: "https://platform.moonshot.cn/docs/api/chat"
10
+ },
11
+ lucidquery: {
12
+ url: "https://lucidquery.com/api/v1/chat/completions",
13
+ apiKeyEnvVar: "LUCIDQUERY_API_KEY",
14
+ apiKeyHeader: "Authorization",
15
+ name: "LucidQuery AI",
16
+ models: ["lucidnova-rf1-100b", "lucidquery-nexus-coder"],
17
+ docUrl: "https://lucidquery.com/api/docs"
18
+ },
19
+ moonshotai: {
20
+ url: "https://api.moonshot.ai/v1/chat/completions",
21
+ apiKeyEnvVar: "MOONSHOT_API_KEY",
22
+ apiKeyHeader: "Authorization",
23
+ name: "Moonshot AI",
24
+ models: ["kimi-k2-0711-preview", "kimi-k2-0905-preview", "kimi-k2-turbo-preview"],
25
+ docUrl: "https://platform.moonshot.ai/docs/api/chat"
26
+ },
27
+ "zai-coding-plan": {
28
+ url: "https://api.z.ai/api/coding/paas/v4/chat/completions",
29
+ apiKeyEnvVar: "ZHIPU_API_KEY",
30
+ apiKeyHeader: "Authorization",
31
+ name: "Z.AI Coding Plan",
32
+ models: ["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v", "glm-4.6"],
33
+ docUrl: "https://docs.z.ai/devpack/overview"
34
+ },
35
+ alibaba: {
36
+ url: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",
37
+ apiKeyEnvVar: "DASHSCOPE_API_KEY",
38
+ apiKeyHeader: "Authorization",
39
+ name: "Alibaba",
40
+ models: ["qwen3-coder-plus"],
41
+ docUrl: "https://www.alibabacloud.com/help/en/model-studio/models"
42
+ },
43
+ xai: {
44
+ url: "https://api.x.ai/v1/chat/completions",
45
+ apiKeyEnvVar: "XAI_API_KEY",
46
+ apiKeyHeader: "Authorization",
47
+ name: "xAI",
48
+ models: [
49
+ "grok-2",
50
+ "grok-2-1212",
51
+ "grok-2-latest",
52
+ "grok-2-vision",
53
+ "grok-2-vision-1212",
54
+ "grok-2-vision-latest",
55
+ "grok-3",
56
+ "grok-3-fast",
57
+ "grok-3-fast-latest",
58
+ "grok-3-latest",
59
+ "grok-3-mini",
60
+ "grok-3-mini-fast",
61
+ "grok-3-mini-fast-latest",
62
+ "grok-3-mini-latest",
63
+ "grok-4",
64
+ "grok-4-fast",
65
+ "grok-4-fast-non-reasoning",
66
+ "grok-beta",
67
+ "grok-code-fast-1",
68
+ "grok-vision-beta"
69
+ ],
70
+ docUrl: "https://docs.x.ai/docs/models"
71
+ },
72
+ nvidia: {
73
+ url: "https://integrate.api.nvidia.com/v1/chat/completions",
74
+ apiKeyEnvVar: "NVIDIA_API_KEY",
75
+ apiKeyHeader: "Authorization",
76
+ name: "Nvidia",
77
+ models: [
78
+ "black-forest-labs/flux.1-dev",
79
+ "deepseek-ai/deepseek-v3.1",
80
+ "google/gemma-3-27b-it",
81
+ "microsoft/phi-4-mini-instruct",
82
+ "moonshotai/kimi-k2-instruct",
83
+ "nvidia/cosmos-nemotron-34b",
84
+ "nvidia/llama-3.1-nemotron-ultra-253b-v1",
85
+ "nvidia/nemoretriever-ocr-v1",
86
+ "nvidia/parakeet-tdt-0.6b-v2",
87
+ "openai/gpt-oss-120b",
88
+ "openai/whisper-large-v3",
89
+ "qwen/qwen3-235b-a22b",
90
+ "qwen/qwen3-coder-480b-a35b-instruct"
91
+ ],
92
+ docUrl: "https://docs.api.nvidia.com/nim/"
93
+ },
94
+ upstage: {
95
+ url: "https://api.upstage.ai/chat/completions",
96
+ apiKeyEnvVar: "UPSTAGE_API_KEY",
97
+ apiKeyHeader: "Authorization",
98
+ name: "Upstage",
99
+ models: ["solar-mini", "solar-pro2"],
100
+ docUrl: "https://developers.upstage.ai/docs/apis/chat"
101
+ },
102
+ groq: {
103
+ url: "https://api.groq.com/openai/v1/chat/completions",
104
+ apiKeyEnvVar: "GROQ_API_KEY",
105
+ apiKeyHeader: "Authorization",
106
+ name: "Groq",
107
+ models: [
108
+ "deepseek-r1-distill-llama-70b",
109
+ "gemma2-9b-it",
110
+ "llama-3.1-8b-instant",
111
+ "llama-3.3-70b-versatile",
112
+ "llama-guard-3-8b",
113
+ "llama3-70b-8192",
114
+ "llama3-8b-8192",
115
+ "meta-llama/llama-4-maverick-17b-128e-instruct",
116
+ "meta-llama/llama-4-scout-17b-16e-instruct",
117
+ "meta-llama/llama-guard-4-12b",
118
+ "mistral-saba-24b",
119
+ "moonshotai/kimi-k2-instruct",
120
+ "moonshotai/kimi-k2-instruct-0905",
121
+ "openai/gpt-oss-120b",
122
+ "openai/gpt-oss-20b",
123
+ "qwen-qwq-32b",
124
+ "qwen/qwen3-32b"
125
+ ],
126
+ docUrl: "https://console.groq.com/docs/models"
127
+ },
128
+ "github-copilot": {
129
+ url: "https://api.githubcopilot.com/chat/completions",
130
+ apiKeyEnvVar: "GITHUB_TOKEN",
131
+ apiKeyHeader: "Authorization",
132
+ name: "GitHub Copilot",
133
+ models: [
134
+ "claude-3.5-sonnet",
135
+ "claude-3.7-sonnet",
136
+ "claude-3.7-sonnet-thought",
137
+ "claude-opus-4",
138
+ "claude-opus-41",
139
+ "claude-sonnet-4",
140
+ "claude-sonnet-4.5",
141
+ "gemini-2.0-flash-001",
142
+ "gemini-2.5-pro",
143
+ "gpt-4.1",
144
+ "gpt-4o",
145
+ "gpt-5",
146
+ "gpt-5-codex",
147
+ "gpt-5-mini",
148
+ "grok-code-fast-1",
149
+ "o3",
150
+ "o3-mini",
151
+ "o4-mini"
152
+ ],
153
+ docUrl: "https://docs.github.com/en/copilot"
154
+ },
155
+ mistral: {
156
+ url: "https://api.mistral.ai/v1/chat/completions",
157
+ apiKeyEnvVar: "MISTRAL_API_KEY",
158
+ apiKeyHeader: "Authorization",
159
+ name: "Mistral",
160
+ models: [
161
+ "codestral-latest",
162
+ "devstral-medium-2507",
163
+ "devstral-small-2505",
164
+ "devstral-small-2507",
165
+ "magistral-medium-latest",
166
+ "magistral-small",
167
+ "ministral-3b-latest",
168
+ "ministral-8b-latest",
169
+ "mistral-large-latest",
170
+ "mistral-medium-2505",
171
+ "mistral-medium-2508",
172
+ "mistral-medium-latest",
173
+ "mistral-nemo",
174
+ "mistral-small-latest",
175
+ "open-mistral-7b",
176
+ "open-mixtral-8x22b",
177
+ "open-mixtral-8x7b",
178
+ "pixtral-12b",
179
+ "pixtral-large-latest"
180
+ ],
181
+ docUrl: "https://docs.mistral.ai/getting-started/models/"
182
+ },
183
+ vercel: {
184
+ url: "https://ai-gateway.vercel.sh/v1/chat/completions",
185
+ apiKeyEnvVar: "AI_GATEWAY_API_KEY",
186
+ apiKeyHeader: "Authorization",
187
+ name: "Vercel AI Gateway",
188
+ models: [
189
+ "amazon/nova-lite",
190
+ "amazon/nova-micro",
191
+ "amazon/nova-pro",
192
+ "anthropic/claude-3-5-haiku",
193
+ "anthropic/claude-3-haiku",
194
+ "anthropic/claude-3-opus",
195
+ "anthropic/claude-3.5-sonnet",
196
+ "anthropic/claude-3.7-sonnet",
197
+ "anthropic/claude-4-1-opus",
198
+ "anthropic/claude-4-opus",
199
+ "anthropic/claude-4-sonnet",
200
+ "anthropic/claude-4.5-sonnet",
201
+ "cerebras/qwen3-coder",
202
+ "deepseek/deepseek-r1",
203
+ "deepseek/deepseek-r1-distill-llama-70b",
204
+ "google/gemini-2.0-flash",
205
+ "google/gemini-2.0-flash-lite",
206
+ "google/gemini-2.5-flash",
207
+ "google/gemini-2.5-pro",
208
+ "meta/llama-3.3-70b",
209
+ "meta/llama-4-maverick",
210
+ "meta/llama-4-scout",
211
+ "mistral/codestral",
212
+ "mistral/magistral-medium",
213
+ "mistral/magistral-small",
214
+ "mistral/ministral-3b",
215
+ "mistral/ministral-8b",
216
+ "mistral/mistral-large",
217
+ "mistral/mistral-small",
218
+ "mistral/mixtral-8x22b-instruct",
219
+ "mistral/pixtral-12b",
220
+ "mistral/pixtral-large",
221
+ "moonshotai/kimi-k2",
222
+ "morph/morph-v3-fast",
223
+ "morph/morph-v3-large",
224
+ "openai/gpt-4-turbo",
225
+ "openai/gpt-4.1",
226
+ "openai/gpt-4.1-mini",
227
+ "openai/gpt-4.1-nano",
228
+ "openai/gpt-4o",
229
+ "openai/gpt-4o-mini",
230
+ "openai/gpt-5",
231
+ "openai/gpt-5-codex",
232
+ "openai/gpt-5-mini",
233
+ "openai/gpt-5-nano",
234
+ "openai/gpt-oss-120b",
235
+ "openai/gpt-oss-20b",
236
+ "openai/o1",
237
+ "openai/o3",
238
+ "openai/o3-mini",
239
+ "openai/o4-mini",
240
+ "vercel/v0-1.0-md",
241
+ "vercel/v0-1.5-md",
242
+ "xai/grok-2",
243
+ "xai/grok-2-vision",
244
+ "xai/grok-3",
245
+ "xai/grok-3-fast",
246
+ "xai/grok-3-mini",
247
+ "xai/grok-3-mini-fast",
248
+ "xai/grok-4",
249
+ "xai/grok-4-fast",
250
+ "xai/grok-4-fast-non-reasoning",
251
+ "xai/grok-code-fast-1"
252
+ ],
253
+ docUrl: "https://github.com/vercel/ai/tree/5eb85cc45a259553501f535b8ac79a77d0e79223/packages/gateway"
254
+ },
255
+ deepseek: {
256
+ url: "https://api.deepseek.com/chat/completions",
257
+ apiKeyEnvVar: "DEEPSEEK_API_KEY",
258
+ apiKeyHeader: "Authorization",
259
+ name: "DeepSeek",
260
+ models: ["deepseek-chat", "deepseek-reasoner"],
261
+ docUrl: "https://platform.deepseek.com/api-docs/pricing"
262
+ },
263
+ "alibaba-cn": {
264
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
265
+ apiKeyEnvVar: "DASHSCOPE_API_KEY",
266
+ apiKeyHeader: "Authorization",
267
+ name: "Alibaba (China)",
268
+ models: ["qwen3-coder-plus"],
269
+ docUrl: "https://www.alibabacloud.com/help/en/model-studio/models"
270
+ },
271
+ venice: {
272
+ url: "https://api.venice.ai/api/v1/chat/completions",
273
+ apiKeyEnvVar: "VENICE_API_KEY",
274
+ apiKeyHeader: "Authorization",
275
+ name: "Venice AI",
276
+ models: [
277
+ "deepseek-coder-v2-lite",
278
+ "deepseek-r1-671b",
279
+ "dolphin-2.9.2-qwen2-72b",
280
+ "llama-3.1-405b",
281
+ "llama-3.2-3b",
282
+ "llama-3.3-70b",
283
+ "mistral-31-24b",
284
+ "qwen-2.5-coder-32b",
285
+ "qwen-2.5-qwq-32b",
286
+ "qwen-2.5-vl",
287
+ "qwen3-235b",
288
+ "qwen3-4b",
289
+ "venice-uncensored"
290
+ ],
291
+ docUrl: "https://docs.venice.ai"
292
+ },
293
+ chutes: {
294
+ url: "https://llm.chutes.ai/v1/chat/completions",
295
+ apiKeyEnvVar: "CHUTES_API_KEY",
296
+ apiKeyHeader: "Authorization",
297
+ name: "Chutes",
298
+ models: [
299
+ "Qwen/Qwen3-235B-A22B-Instruct-2507",
300
+ "Qwen/Qwen3-235B-A22B-Thinking-2507",
301
+ "Qwen/Qwen3-30B-A3B",
302
+ "Qwen/Qwen3-30B-A3B-Instruct-2507",
303
+ "Qwen/Qwen3-30B-A3B-Thinking-2507",
304
+ "Qwen/Qwen3-Coder-30B-A3B-Instruct",
305
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
306
+ "Qwen/Qwen3-Next-80B-A3B-Instruct",
307
+ "Qwen/Qwen3-Next-80B-A3B-Thinking",
308
+ "chutesai/Devstral-Small-2505",
309
+ "chutesai/Mistral-Small-3.2-24B-Instruct-2506",
310
+ "deepseek-ai/DeepSeek-R1-0528",
311
+ "deepseek-ai/DeepSeek-R1-0528-Qwen3-8B",
312
+ "deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
313
+ "deepseek-ai/DeepSeek-V3-0324",
314
+ "deepseek-ai/DeepSeek-V3.1",
315
+ "deepseek-ai/DeepSeek-V3.1-Terminus",
316
+ "deepseek-ai/DeepSeek-V3.1-turbo",
317
+ "deepseek-ai/DeepSeek-V3.1:THINKING",
318
+ "meituan-longcat/LongCat-Flash-Chat-FP8",
319
+ "moonshotai/Kimi-Dev-72B",
320
+ "moonshotai/Kimi-K2-Instruct-0905",
321
+ "moonshotai/Kimi-K2-Instruct-75k",
322
+ "moonshotai/Kimi-VL-A3B-Thinking",
323
+ "openai/gpt-oss-120b",
324
+ "tngtech/DeepSeek-R1T-Chimera",
325
+ "tngtech/DeepSeek-TNG-R1T2-Chimera",
326
+ "zai-org/GLM-4.5-Air",
327
+ "zai-org/GLM-4.5-FP8",
328
+ "zai-org/GLM-4.5-turbo"
329
+ ],
330
+ docUrl: "https://llm.chutes.ai/v1/models"
331
+ },
332
+ cortecs: {
333
+ url: "https://api.cortecs.ai/v1/chat/completions",
334
+ apiKeyEnvVar: "CORTECS_API_KEY",
335
+ apiKeyHeader: "Authorization",
336
+ name: "Cortecs",
337
+ models: [
338
+ "claude-sonnet-4",
339
+ "deepseek-v3-0324",
340
+ "gemini-2.5-pro",
341
+ "gpt-4.1",
342
+ "gpt-oss-120b",
343
+ "kimi-k2-instruct",
344
+ "llama-3.1-405b-instruct",
345
+ "nova-pro-v1",
346
+ "qwen3-32b",
347
+ "qwen3-coder-480b-a35b-instruct"
348
+ ],
349
+ docUrl: "https://api.cortecs.ai/v1/models"
350
+ },
351
+ "github-models": {
352
+ url: "https://models.github.ai/inference/chat/completions",
353
+ apiKeyEnvVar: "GITHUB_TOKEN",
354
+ apiKeyHeader: "Authorization",
355
+ name: "GitHub Models",
356
+ models: [
357
+ "ai21-labs/ai21-jamba-1.5-large",
358
+ "ai21-labs/ai21-jamba-1.5-mini",
359
+ "cohere/cohere-command-a",
360
+ "cohere/cohere-command-r",
361
+ "cohere/cohere-command-r-08-2024",
362
+ "cohere/cohere-command-r-plus",
363
+ "cohere/cohere-command-r-plus-08-2024",
364
+ "core42/jais-30b-chat",
365
+ "deepseek/deepseek-r1",
366
+ "deepseek/deepseek-r1-0528",
367
+ "deepseek/deepseek-v3-0324",
368
+ "meta/llama-3.2-11b-vision-instruct",
369
+ "meta/llama-3.2-90b-vision-instruct",
370
+ "meta/llama-3.3-70b-instruct",
371
+ "meta/llama-4-maverick-17b-128e-instruct-fp8",
372
+ "meta/llama-4-scout-17b-16e-instruct",
373
+ "meta/meta-llama-3-70b-instruct",
374
+ "meta/meta-llama-3-8b-instruct",
375
+ "meta/meta-llama-3.1-405b-instruct",
376
+ "meta/meta-llama-3.1-70b-instruct",
377
+ "meta/meta-llama-3.1-8b-instruct",
378
+ "microsoft/mai-ds-r1",
379
+ "microsoft/phi-3-medium-128k-instruct",
380
+ "microsoft/phi-3-medium-4k-instruct",
381
+ "microsoft/phi-3-mini-128k-instruct",
382
+ "microsoft/phi-3-mini-4k-instruct",
383
+ "microsoft/phi-3-small-128k-instruct",
384
+ "microsoft/phi-3-small-8k-instruct",
385
+ "microsoft/phi-3.5-mini-instruct",
386
+ "microsoft/phi-3.5-moe-instruct",
387
+ "microsoft/phi-3.5-vision-instruct",
388
+ "microsoft/phi-4",
389
+ "microsoft/phi-4-mini-instruct",
390
+ "microsoft/phi-4-mini-reasoning",
391
+ "microsoft/phi-4-multimodal-instruct",
392
+ "microsoft/phi-4-reasoning",
393
+ "mistral-ai/codestral-2501",
394
+ "mistral-ai/ministral-3b",
395
+ "mistral-ai/mistral-large-2411",
396
+ "mistral-ai/mistral-medium-2505",
397
+ "mistral-ai/mistral-nemo",
398
+ "mistral-ai/mistral-small-2503",
399
+ "openai/gpt-4.1",
400
+ "openai/gpt-4.1-mini",
401
+ "openai/gpt-4.1-nano",
402
+ "openai/gpt-4o",
403
+ "openai/gpt-4o-mini",
404
+ "openai/o1",
405
+ "openai/o1-mini",
406
+ "openai/o1-preview",
407
+ "openai/o3",
408
+ "openai/o3-mini",
409
+ "openai/o4-mini",
410
+ "xai/grok-3",
411
+ "xai/grok-3-mini"
412
+ ],
413
+ docUrl: "https://docs.github.com/en/github-models"
414
+ },
415
+ togetherai: {
416
+ url: "https://api.together.xyz/v1/chat/completions",
417
+ apiKeyEnvVar: "TOGETHER_API_KEY",
418
+ apiKeyHeader: "Authorization",
419
+ name: "Together AI",
420
+ models: [
421
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
422
+ "deepseek-ai/DeepSeek-R1",
423
+ "deepseek-ai/DeepSeek-V3",
424
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo",
425
+ "moonshotai/Kimi-K2-Instruct",
426
+ "openai/gpt-oss-120b"
427
+ ],
428
+ docUrl: "https://docs.together.ai/docs/serverless-models"
429
+ },
430
+ baseten: {
431
+ url: "https://inference.baseten.co/v1/chat/completions",
432
+ apiKeyEnvVar: "BASETEN_API_KEY",
433
+ apiKeyHeader: "Authorization",
434
+ name: "Baseten",
435
+ models: ["Qwen3/Qwen3-Coder-480B-A35B-Instruct", "moonshotai/Kimi-K2-Instruct-0905"],
436
+ docUrl: "https://docs.baseten.co/development/model-apis/overview"
437
+ },
438
+ huggingface: {
439
+ url: "https://router.huggingface.co/v1/chat/completions",
440
+ apiKeyEnvVar: "HF_TOKEN",
441
+ apiKeyHeader: "Authorization",
442
+ name: "Hugging Face",
443
+ models: [
444
+ "Qwen/Qwen3-235B-A22B-Thinking-2507",
445
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct",
446
+ "Qwen/Qwen3-Next-80B-A3B-Instruct",
447
+ "Qwen/Qwen3-Next-80B-A3B-Thinking",
448
+ "deepseek-ai/DeepSeek-R1-0528",
449
+ "deepseek-ai/Deepseek-V3-0324",
450
+ "moonshotai/Kimi-K2-Instruct",
451
+ "moonshotai/Kimi-K2-Instruct-0905",
452
+ "zai-org/GLM-4.5",
453
+ "zai-org/GLM-4.5-Air"
454
+ ],
455
+ docUrl: "https://huggingface.co/docs/inference-providers"
456
+ },
457
+ opencode: {
458
+ url: "https://opencode.ai/zen/v1/chat/completions",
459
+ apiKeyEnvVar: "OPENCODE_API_KEY",
460
+ apiKeyHeader: "Authorization",
461
+ name: "opencode zen",
462
+ models: [
463
+ "claude-3-5-haiku",
464
+ "claude-opus-4-1",
465
+ "claude-sonnet-4",
466
+ "claude-sonnet-4-5",
467
+ "code-supernova",
468
+ "gpt-5",
469
+ "gpt-5-codex",
470
+ "grok-code",
471
+ "kimi-k2",
472
+ "qwen3-coder",
473
+ "qwen3-max"
474
+ ],
475
+ docUrl: "https://opencode.ai/docs"
476
+ },
477
+ fastrouter: {
478
+ url: "https://go.fastrouter.ai/api/v1/chat/completions",
479
+ apiKeyEnvVar: "FASTROUTER_API_KEY",
480
+ apiKeyHeader: "Authorization",
481
+ name: "FastRouter",
482
+ models: [
483
+ "anthropic/claude-opus-4.1",
484
+ "anthropic/claude-sonnet-4",
485
+ "deepseek-ai/deepseek-r1-distill-llama-70b",
486
+ "google/gemini-2.5-flash",
487
+ "google/gemini-2.5-pro",
488
+ "moonshotai/kimi-k2",
489
+ "openai/gpt-4.1",
490
+ "openai/gpt-5",
491
+ "openai/gpt-5-mini",
492
+ "openai/gpt-5-nano",
493
+ "openai/gpt-oss-120b",
494
+ "openai/gpt-oss-20b",
495
+ "qwen/qwen3-coder",
496
+ "x-ai/grok-4"
497
+ ],
498
+ docUrl: "https://fastrouter.ai/models"
499
+ },
500
+ google: {
501
+ url: "https://generativelanguage.googleapis.com/v1beta/chat/completions",
502
+ apiKeyEnvVar: "GOOGLE_GENERATIVE_AI_API_KEY",
503
+ apiKeyHeader: "Authorization",
504
+ name: "Google",
505
+ models: [
506
+ "gemini-1.5-flash",
507
+ "gemini-1.5-flash-8b",
508
+ "gemini-1.5-pro",
509
+ "gemini-2.0-flash",
510
+ "gemini-2.0-flash-lite",
511
+ "gemini-2.5-flash",
512
+ "gemini-2.5-flash-lite",
513
+ "gemini-2.5-flash-lite-preview-06-17",
514
+ "gemini-2.5-flash-lite-preview-09-2025",
515
+ "gemini-2.5-flash-preview-04-17",
516
+ "gemini-2.5-flash-preview-05-20",
517
+ "gemini-2.5-flash-preview-09-2025",
518
+ "gemini-2.5-pro",
519
+ "gemini-2.5-pro-preview-05-06",
520
+ "gemini-2.5-pro-preview-06-05",
521
+ "gemini-flash-latest",
522
+ "gemini-flash-lite-latest",
523
+ "gemini-live-2.5-flash-preview-native-audio"
524
+ ],
525
+ docUrl: "https://ai.google.dev/gemini-api/docs/pricing"
526
+ },
527
+ inception: {
528
+ url: "https://api.inceptionlabs.ai/v1/chat/completions",
529
+ apiKeyEnvVar: "INCEPTION_API_KEY",
530
+ apiKeyHeader: "Authorization",
531
+ name: "Inception",
532
+ models: ["mercury", "mercury-coder"],
533
+ docUrl: "https://platform.inceptionlabs.ai/docs"
534
+ },
535
+ wandb: {
536
+ url: "https://api.inference.wandb.ai/v1/chat/completions",
537
+ apiKeyEnvVar: "WANDB_API_KEY",
538
+ apiKeyHeader: "Authorization",
539
+ name: "Weights & Biases",
540
+ models: [
541
+ "Qwen/Qwen3-235B-A22B-Instruct-2507",
542
+ "Qwen/Qwen3-235B-A22B-Thinking-2507",
543
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct",
544
+ "deepseek-ai/DeepSeek-R1-0528",
545
+ "deepseek-ai/DeepSeek-V3-0324",
546
+ "meta-llama/Llama-3.1-8B-Instruct",
547
+ "meta-llama/Llama-3.3-70B-Instruct",
548
+ "meta-llama/Llama-4-Scout-17B-16E-Instruct",
549
+ "microsoft/Phi-4-mini-instruct",
550
+ "moonshotai/Kimi-K2-Instruct"
551
+ ],
552
+ docUrl: "https://weave-docs.wandb.ai/guides/integrations/inference/"
553
+ },
554
+ openai: {
555
+ url: "https://api.openai.com/v1/chat/completions",
556
+ apiKeyEnvVar: "OPENAI_API_KEY",
557
+ apiKeyHeader: "Authorization",
558
+ name: "OpenAI",
559
+ models: [
560
+ "codex-mini-latest",
561
+ "gpt-3.5-turbo",
562
+ "gpt-4",
563
+ "gpt-4-turbo",
564
+ "gpt-4.1",
565
+ "gpt-4.1-mini",
566
+ "gpt-4.1-nano",
567
+ "gpt-4o",
568
+ "gpt-4o-2024-05-13",
569
+ "gpt-4o-2024-08-06",
570
+ "gpt-4o-2024-11-20",
571
+ "gpt-4o-mini",
572
+ "gpt-5",
573
+ "gpt-5-chat-latest",
574
+ "gpt-5-codex",
575
+ "gpt-5-mini",
576
+ "gpt-5-nano",
577
+ "o1",
578
+ "o1-mini",
579
+ "o1-preview",
580
+ "o1-pro",
581
+ "o3",
582
+ "o3-deep-research",
583
+ "o3-mini",
584
+ "o3-pro",
585
+ "o4-mini",
586
+ "o4-mini-deep-research"
587
+ ],
588
+ docUrl: "https://platform.openai.com/docs/models"
589
+ },
590
+ "zhipuai-coding-plan": {
591
+ url: "https://open.bigmodel.cn/api/coding/paas/v4/chat/completions",
592
+ apiKeyEnvVar: "ZHIPU_API_KEY",
593
+ apiKeyHeader: "Authorization",
594
+ name: "Zhipu AI Coding Plan",
595
+ models: ["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v", "glm-4.6"],
596
+ docUrl: "https://docs.bigmodel.cn/cn/coding-plan/overview"
597
+ },
598
+ perplexity: {
599
+ url: "https://api.perplexity.ai/chat/completions",
600
+ apiKeyEnvVar: "PERPLEXITY_API_KEY",
601
+ apiKeyHeader: "Authorization",
602
+ name: "Perplexity",
603
+ models: ["sonar", "sonar-pro", "sonar-reasoning", "sonar-reasoning-pro"],
604
+ docUrl: "https://docs.perplexity.ai"
605
+ },
606
+ openrouter: {
607
+ url: "https://openrouter.ai/api/v1/chat/completions",
608
+ apiKeyEnvVar: "OPENROUTER_API_KEY",
609
+ apiKeyHeader: "Authorization",
610
+ name: "OpenRouter",
611
+ models: [
612
+ "anthropic/claude-3.5-haiku",
613
+ "anthropic/claude-3.7-sonnet",
614
+ "anthropic/claude-opus-4",
615
+ "anthropic/claude-opus-4.1",
616
+ "anthropic/claude-sonnet-4",
617
+ "anthropic/claude-sonnet-4.5",
618
+ "cognitivecomputations/dolphin3.0-mistral-24b",
619
+ "cognitivecomputations/dolphin3.0-r1-mistral-24b",
620
+ "deepseek/deepseek-chat-v3-0324",
621
+ "deepseek/deepseek-chat-v3.1",
622
+ "deepseek/deepseek-r1-0528-qwen3-8b:free",
623
+ "deepseek/deepseek-r1-0528:free",
624
+ "deepseek/deepseek-r1-distill-llama-70b",
625
+ "deepseek/deepseek-r1-distill-qwen-14b",
626
+ "deepseek/deepseek-r1:free",
627
+ "deepseek/deepseek-v3-base:free",
628
+ "deepseek/deepseek-v3.1-terminus",
629
+ "featherless/qwerky-72b",
630
+ "google/gemini-2.0-flash-001",
631
+ "google/gemini-2.0-flash-exp:free",
632
+ "google/gemini-2.5-flash",
633
+ "google/gemini-2.5-pro",
634
+ "google/gemini-2.5-pro-preview-05-06",
635
+ "google/gemini-2.5-pro-preview-06-05",
636
+ "google/gemma-2-9b-it:free",
637
+ "google/gemma-3-12b-it",
638
+ "google/gemma-3-27b-it",
639
+ "google/gemma-3n-e4b-it",
640
+ "google/gemma-3n-e4b-it:free",
641
+ "meta-llama/llama-3.2-11b-vision-instruct",
642
+ "meta-llama/llama-3.3-70b-instruct:free",
643
+ "meta-llama/llama-4-scout:free",
644
+ "microsoft/mai-ds-r1:free",
645
+ "mistralai/codestral-2508",
646
+ "mistralai/devstral-medium-2507",
647
+ "mistralai/devstral-small-2505",
648
+ "mistralai/devstral-small-2505:free",
649
+ "mistralai/devstral-small-2507",
650
+ "mistralai/mistral-7b-instruct:free",
651
+ "mistralai/mistral-medium-3",
652
+ "mistralai/mistral-medium-3.1",
653
+ "mistralai/mistral-nemo:free",
654
+ "mistralai/mistral-small-3.1-24b-instruct",
655
+ "mistralai/mistral-small-3.2-24b-instruct",
656
+ "mistralai/mistral-small-3.2-24b-instruct:free",
657
+ "moonshotai/kimi-dev-72b:free",
658
+ "moonshotai/kimi-k2",
659
+ "moonshotai/kimi-k2-0905",
660
+ "moonshotai/kimi-k2:free",
661
+ "nousresearch/deephermes-3-llama-3-8b-preview",
662
+ "nousresearch/hermes-4-405b",
663
+ "nousresearch/hermes-4-70b",
664
+ "openai/gpt-4.1",
665
+ "openai/gpt-4.1-mini",
666
+ "openai/gpt-4o-mini",
667
+ "openai/gpt-5",
668
+ "openai/gpt-5-chat",
669
+ "openai/gpt-5-codex",
670
+ "openai/gpt-5-mini",
671
+ "openai/gpt-5-nano",
672
+ "openai/gpt-oss-120b",
673
+ "openai/gpt-oss-20b",
674
+ "openai/o4-mini",
675
+ "openrouter/cypher-alpha:free",
676
+ "openrouter/horizon-alpha",
677
+ "openrouter/horizon-beta",
678
+ "openrouter/sonoma-dusk-alpha",
679
+ "openrouter/sonoma-sky-alpha",
680
+ "qwen/qwen-2.5-coder-32b-instruct",
681
+ "qwen/qwen2.5-vl-32b-instruct:free",
682
+ "qwen/qwen2.5-vl-72b-instruct",
683
+ "qwen/qwen2.5-vl-72b-instruct:free",
684
+ "qwen/qwen3-14b:free",
685
+ "qwen/qwen3-235b-a22b-07-25",
686
+ "qwen/qwen3-235b-a22b-07-25:free",
687
+ "qwen/qwen3-235b-a22b-thinking-2507",
688
+ "qwen/qwen3-235b-a22b:free",
689
+ "qwen/qwen3-30b-a3b-instruct-2507",
690
+ "qwen/qwen3-30b-a3b:free",
691
+ "qwen/qwen3-32b:free",
692
+ "qwen/qwen3-8b:free",
693
+ "qwen/qwen3-coder",
694
+ "qwen/qwen3-coder:free",
695
+ "qwen/qwen3-max",
696
+ "qwen/qwen3-next-80b-a3b-instruct",
697
+ "qwen/qwq-32b:free",
698
+ "rekaai/reka-flash-3",
699
+ "sarvamai/sarvam-m:free",
700
+ "thudm/glm-z1-32b:free",
701
+ "tngtech/deepseek-r1t2-chimera:free",
702
+ "x-ai/grok-3",
703
+ "x-ai/grok-3-beta",
704
+ "x-ai/grok-3-mini",
705
+ "x-ai/grok-3-mini-beta",
706
+ "x-ai/grok-4",
707
+ "x-ai/grok-4-fast",
708
+ "x-ai/grok-4-fast:free",
709
+ "x-ai/grok-code-fast-1",
710
+ "z-ai/glm-4.5",
711
+ "z-ai/glm-4.5-air",
712
+ "z-ai/glm-4.5-air:free",
713
+ "z-ai/glm-4.5v"
714
+ ],
715
+ docUrl: "https://openrouter.ai/models"
716
+ },
717
+ synthetic: {
718
+ url: "https://api.synthetic.new/v1/chat/completions",
719
+ apiKeyEnvVar: "SYNTHETIC_API_KEY",
720
+ apiKeyHeader: "Authorization",
721
+ name: "Synthetic",
722
+ models: [
723
+ "hf:Qwen/Qwen2.5-Coder-32B-Instruct",
724
+ "hf:Qwen/Qwen3-235B-A22B-Instruct-2507",
725
+ "hf:Qwen/Qwen3-235B-A22B-Thinking-2507",
726
+ "hf:Qwen/Qwen3-Coder-480B-A35B-Instruct",
727
+ "hf:deepseek-ai/DeepSeek-R1",
728
+ "hf:deepseek-ai/DeepSeek-R1-0528",
729
+ "hf:deepseek-ai/DeepSeek-V3",
730
+ "hf:deepseek-ai/DeepSeek-V3-0324",
731
+ "hf:deepseek-ai/DeepSeek-V3.1",
732
+ "hf:deepseek-ai/DeepSeek-V3.1-Terminus",
733
+ "hf:meta-llama/Llama-3.1-405B-Instruct",
734
+ "hf:meta-llama/Llama-3.1-70B-Instruct",
735
+ "hf:meta-llama/Llama-3.1-8B-Instruct",
736
+ "hf:meta-llama/Llama-3.3-70B-Instruct",
737
+ "hf:meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
738
+ "hf:meta-llama/Llama-4-Scout-17B-16E-Instruct",
739
+ "hf:moonshotai/Kimi-K2-Instruct",
740
+ "hf:moonshotai/Kimi-K2-Instruct-0905",
741
+ "hf:openai/gpt-oss-120b",
742
+ "hf:zai-org/GLM-4.5"
743
+ ],
744
+ docUrl: "https://synthetic.new/pricing"
745
+ },
746
+ deepinfra: {
747
+ url: "https://api.deepinfra.com/v1/openai/chat/completions",
748
+ apiKeyEnvVar: "DEEPINFRA_API_KEY",
749
+ apiKeyHeader: "Authorization",
750
+ name: "Deep Infra",
751
+ models: [
752
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct",
753
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo",
754
+ "moonshotai/Kimi-K2-Instruct",
755
+ "zai-org/GLM-4.5"
756
+ ],
757
+ docUrl: "https://deepinfra.com/models"
758
+ },
759
+ zhipuai: {
760
+ url: "https://open.bigmodel.cn/api/paas/v4/chat/completions",
761
+ apiKeyEnvVar: "ZHIPU_API_KEY",
762
+ apiKeyHeader: "Authorization",
763
+ name: "Zhipu AI",
764
+ models: ["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v", "glm-4.6"],
765
+ docUrl: "https://docs.z.ai/guides/overview/pricing"
766
+ },
767
+ submodel: {
768
+ url: "https://llm.submodel.ai/v1/chat/completions",
769
+ apiKeyEnvVar: "SUBMODEL_INSTAGEN_ACCESS_KEY",
770
+ apiKeyHeader: "Authorization",
771
+ name: "submodel",
772
+ models: [
773
+ "Qwen/Qwen3-235B-A22B-Instruct-2507",
774
+ "Qwen/Qwen3-235B-A22B-Thinking-2507",
775
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
776
+ "deepseek-ai/DeepSeek-R1-0528",
777
+ "deepseek-ai/DeepSeek-V3-0324",
778
+ "deepseek-ai/DeepSeek-V3.1",
779
+ "openai/gpt-oss-120b",
780
+ "zai-org/GLM-4.5-Air",
781
+ "zai-org/GLM-4.5-FP8"
782
+ ],
783
+ docUrl: "https://submodel.gitbook.io"
784
+ },
785
+ zai: {
786
+ url: "https://api.z.ai/api/paas/v4/chat/completions",
787
+ apiKeyEnvVar: "ZHIPU_API_KEY",
788
+ apiKeyHeader: "Authorization",
789
+ name: "Z.AI",
790
+ models: ["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v", "glm-4.6"],
791
+ docUrl: "https://docs.z.ai/guides/overview/pricing"
792
+ },
793
+ inference: {
794
+ url: "https://inference.net/v1/chat/completions",
795
+ apiKeyEnvVar: "INFERENCE_API_KEY",
796
+ apiKeyHeader: "Authorization",
797
+ name: "Inference",
798
+ models: [
799
+ "google/gemma-3",
800
+ "meta/llama-3.1-8b-instruct",
801
+ "meta/llama-3.2-11b-vision-instruct",
802
+ "meta/llama-3.2-1b-instruct",
803
+ "meta/llama-3.2-3b-instruct",
804
+ "mistral/mistral-nemo-12b-instruct",
805
+ "osmosis/osmosis-structure-0.6b",
806
+ "qwen/qwen-2.5-7b-vision-instruct",
807
+ "qwen/qwen3-embedding-4b"
808
+ ],
809
+ docUrl: "https://inference.net/models"
810
+ },
811
+ requesty: {
812
+ url: "https://router.requesty.ai/v1/chat/completions",
813
+ apiKeyEnvVar: "REQUESTY_API_KEY",
814
+ apiKeyHeader: "Authorization",
815
+ name: "Requesty",
816
+ models: [
817
+ "anthropic/claude-3-7-sonnet",
818
+ "anthropic/claude-4-sonnet-20250522",
819
+ "anthropic/claude-opus-4",
820
+ "anthropic/claude-opus-4-1-20250805",
821
+ "google/gemini-2.5-flash",
822
+ "google/gemini-2.5-pro",
823
+ "openai/gpt-4.1",
824
+ "openai/gpt-4.1-mini",
825
+ "openai/gpt-4o-mini",
826
+ "openai/gpt-5",
827
+ "openai/gpt-5-mini",
828
+ "openai/gpt-5-nano",
829
+ "openai/o4-mini"
830
+ ],
831
+ docUrl: "https://requesty.ai/solution/llm-routing/models"
832
+ },
833
+ morph: {
834
+ url: "https://api.morphllm.com/v1/chat/completions",
835
+ apiKeyEnvVar: "MORPH_API_KEY",
836
+ apiKeyHeader: "Authorization",
837
+ name: "Morph",
838
+ models: ["auto", "morph-v3-fast", "morph-v3-large"],
839
+ docUrl: "https://docs.morphllm.com/api-reference/introduction"
840
+ },
841
+ lmstudio: {
842
+ url: "http://127.0.0.1:1234/v1/chat/completions",
843
+ apiKeyEnvVar: "LMSTUDIO_API_KEY",
844
+ apiKeyHeader: "Authorization",
845
+ name: "LMStudio",
846
+ models: ["openai/gpt-oss-20b", "qwen/qwen3-30b-a3b-2507", "qwen/qwen3-coder-30b"],
847
+ docUrl: "https://lmstudio.ai/models"
848
+ },
849
+ anthropic: {
850
+ url: "https://api.anthropic.com/v1/chat/completions",
851
+ apiKeyEnvVar: "ANTHROPIC_API_KEY",
852
+ apiKeyHeader: "x-api-key",
853
+ name: "Anthropic",
854
+ models: [
855
+ "claude-3-5-haiku-20241022",
856
+ "claude-3-5-sonnet-20240620",
857
+ "claude-3-5-sonnet-20241022",
858
+ "claude-3-7-sonnet-20250219",
859
+ "claude-3-haiku-20240307",
860
+ "claude-3-opus-20240229",
861
+ "claude-3-sonnet-20240229",
862
+ "claude-opus-4-1-20250805",
863
+ "claude-opus-4-20250514",
864
+ "claude-sonnet-4-20250514",
865
+ "claude-sonnet-4-5-20250929"
866
+ ],
867
+ docUrl: "https://docs.anthropic.com/en/docs/about-claude/models"
868
+ },
869
+ "fireworks-ai": {
870
+ url: "https://api.fireworks.ai/inference/v1/chat/completions",
871
+ apiKeyEnvVar: "FIREWORKS_API_KEY",
872
+ apiKeyHeader: "Authorization",
873
+ name: "Fireworks AI",
874
+ models: [
875
+ "accounts/fireworks/models/deepseek-r1-0528",
876
+ "accounts/fireworks/models/deepseek-v3-0324",
877
+ "accounts/fireworks/models/deepseek-v3p1",
878
+ "accounts/fireworks/models/glm-4p5",
879
+ "accounts/fireworks/models/glm-4p5-air",
880
+ "accounts/fireworks/models/gpt-oss-120b",
881
+ "accounts/fireworks/models/gpt-oss-20b",
882
+ "accounts/fireworks/models/kimi-k2-instruct",
883
+ "accounts/fireworks/models/qwen3-235b-a22b",
884
+ "accounts/fireworks/models/qwen3-coder-480b-a35b-instruct"
885
+ ],
886
+ docUrl: "https://fireworks.ai/docs/"
887
+ },
888
+ modelscope: {
889
+ url: "https://api-inference.modelscope.cn/v1/chat/completions",
890
+ apiKeyEnvVar: "MODELSCOPE_API_KEY",
891
+ apiKeyHeader: "Authorization",
892
+ name: "ModelScope",
893
+ models: [
894
+ "Qwen/Qwen3-235B-A22B-Instruct-2507",
895
+ "Qwen/Qwen3-235B-A22B-Thinking-2507",
896
+ "Qwen/Qwen3-30B-A3B-Instruct-2507",
897
+ "Qwen/Qwen3-30B-A3B-Thinking-2507",
898
+ "Qwen/Qwen3-Coder-30B-A3B-Instruct",
899
+ "Qwen/Qwen3-Coder-480B-A35B-Instruct",
900
+ "ZhipuAI/GLM-4.5"
901
+ ],
902
+ docUrl: "https://modelscope.cn/docs/model-service/API-Inference/intro"
903
+ },
904
+ llama: {
905
+ url: "https://api.llama.com/compat/v1/chat/completions",
906
+ apiKeyEnvVar: "LLAMA_API_KEY",
907
+ apiKeyHeader: "Authorization",
908
+ name: "Llama",
909
+ models: [
910
+ "cerebras-llama-4-maverick-17b-128e-instruct",
911
+ "cerebras-llama-4-scout-17b-16e-instruct",
912
+ "groq-llama-4-maverick-17b-128e-instruct",
913
+ "llama-3.3-70b-instruct",
914
+ "llama-3.3-8b-instruct",
915
+ "llama-4-maverick-17b-128e-instruct-fp8",
916
+ "llama-4-scout-17b-16e-instruct-fp8"
917
+ ],
918
+ docUrl: "https://llama.developer.meta.com/docs/models"
919
+ },
920
+ cerebras: {
921
+ url: "https://api.cerebras.ai/v1/chat/completions",
922
+ apiKeyEnvVar: "CEREBRAS_API_KEY",
923
+ apiKeyHeader: "Authorization",
924
+ name: "Cerebras",
925
+ models: ["gpt-oss-120b", "qwen-3-235b-a22b-instruct-2507", "qwen-3-coder-480b"],
926
+ docUrl: "https://inference-docs.cerebras.ai/models/overview"
927
+ }
928
+ };
929
+ function getProviderConfig(providerId) {
930
+ return PROVIDER_REGISTRY[providerId];
931
+ }
932
+ function parseModelString(modelString) {
933
+ const firstSlashIndex = modelString.indexOf("/");
934
+ if (firstSlashIndex !== -1) {
935
+ const provider = modelString.substring(0, firstSlashIndex);
936
+ const modelId = modelString.substring(firstSlashIndex + 1);
937
+ if (provider && modelId) {
938
+ return {
939
+ provider,
940
+ modelId
941
+ };
942
+ }
943
+ }
944
+ return {
945
+ provider: null,
946
+ modelId: modelString
947
+ };
948
+ }
949
+
950
+ // src/llm/model/openai-compatible.ts
951
+ function resolveApiKey({ provider, apiKey }) {
952
+ if (apiKey) return apiKey;
953
+ if (provider) {
954
+ const config = getProviderConfig(provider);
955
+ if (config?.apiKeyEnvVar) {
956
+ return process.env[config.apiKeyEnvVar];
957
+ }
958
+ }
959
+ return void 0;
960
+ }
961
+ function buildHeaders(apiKey, apiKeyHeader, customHeaders, provider) {
962
+ const headers = {
963
+ "Content-Type": "application/json",
964
+ ...customHeaders
965
+ };
966
+ if (apiKey) {
967
+ if (apiKeyHeader === "x-api-key") {
968
+ headers["x-api-key"] = apiKey;
969
+ } else {
970
+ headers["Authorization"] = `Bearer ${apiKey}`;
971
+ }
972
+ }
973
+ if (provider === "anthropic") {
974
+ headers["anthropic-version"] = "2023-06-01";
975
+ }
976
+ return headers;
977
+ }
978
+ var OpenAICompatibleModel = class {
979
+ specificationVersion = "v2";
980
+ defaultObjectGenerationMode = "json";
981
+ supportsStructuredOutputs = true;
982
+ supportsImageUrls = true;
983
+ supportedUrls = {};
984
+ modelId;
985
+ provider;
986
+ url;
987
+ headers;
988
+ apiKey;
989
+ constructor(config) {
990
+ let parsedConfig;
991
+ if (typeof config === "string") {
992
+ let isUrl = false;
993
+ try {
994
+ new URL(config);
995
+ isUrl = true;
996
+ } catch {
997
+ }
998
+ if (isUrl) {
999
+ parsedConfig = {
1000
+ id: "unknown",
1001
+ url: config
1002
+ };
1003
+ this.provider = "openai-compatible";
1004
+ } else {
1005
+ const firstSlashIndex = config.indexOf("/");
1006
+ if (firstSlashIndex !== -1) {
1007
+ const provider = config.substring(0, firstSlashIndex);
1008
+ const modelId = config.substring(firstSlashIndex + 1);
1009
+ const providerConfig2 = getProviderConfig(provider);
1010
+ if (!providerConfig2) {
1011
+ throw new Error(`Unknown provider: ${provider}. Use a custom URL instead.`);
1012
+ }
1013
+ parsedConfig = {
1014
+ id: modelId,
1015
+ url: providerConfig2.url,
1016
+ apiKey: resolveApiKey({ provider })
1017
+ };
1018
+ this.provider = provider;
1019
+ } else {
1020
+ throw new Error(`Invalid model string: "${config}". Use "provider/model" format or a direct URL.`);
1021
+ }
1022
+ }
1023
+ } else {
1024
+ parsedConfig = config;
1025
+ const parsed = parseModelString(config.id);
1026
+ if (!config.url && parsed.provider) {
1027
+ const providerConfig2 = getProviderConfig(parsed.provider);
1028
+ if (!providerConfig2) {
1029
+ throw new Error(`Unknown provider: ${parsed.provider}. Please provide a URL.`);
1030
+ }
1031
+ parsedConfig.url = providerConfig2.url;
1032
+ parsedConfig.id = parsed.modelId;
1033
+ this.provider = parsed.provider;
1034
+ } else {
1035
+ this.provider = parsed.provider || "openai-compatible";
1036
+ }
1037
+ if (!parsedConfig.apiKey) {
1038
+ parsedConfig.apiKey = resolveApiKey({ provider: parsed.provider || void 0 });
1039
+ }
1040
+ }
1041
+ if (!parsedConfig.url) {
1042
+ throw new Error("URL is required for OpenAI-compatible model");
1043
+ }
1044
+ const providerConfig = this.provider !== "openai-compatible" ? getProviderConfig(this.provider) : void 0;
1045
+ this.modelId = parsedConfig.id;
1046
+ this.url = parsedConfig.url;
1047
+ this.apiKey = parsedConfig.apiKey;
1048
+ this.headers = buildHeaders(parsedConfig.apiKey, providerConfig?.apiKeyHeader, parsedConfig.headers, this.provider);
1049
+ }
1050
+ convertMessagesToOpenAI(messages) {
1051
+ return messages.map((msg) => {
1052
+ if (msg.role === "system") {
1053
+ return {
1054
+ role: "system",
1055
+ content: msg.content
1056
+ };
1057
+ }
1058
+ if (msg.role === "user") {
1059
+ const contentParts = msg.content.map((part) => {
1060
+ if (part.type === "text") {
1061
+ return { type: "text", text: part.text };
1062
+ }
1063
+ if (part.type === "file") {
1064
+ return {
1065
+ type: "image_url",
1066
+ image_url: { url: part.data }
1067
+ };
1068
+ }
1069
+ return null;
1070
+ }).filter(Boolean);
1071
+ if (contentParts.every((p) => p?.type === "text")) {
1072
+ return {
1073
+ role: "user",
1074
+ content: contentParts.map((p) => p?.text || "").join("")
1075
+ };
1076
+ }
1077
+ return {
1078
+ role: "user",
1079
+ content: contentParts
1080
+ };
1081
+ }
1082
+ if (msg.role === "assistant") {
1083
+ const textContent = msg.content.filter((part) => part.type === "text").map((part) => part.text).join("");
1084
+ const toolCalls = msg.content.filter((part) => part.type === "tool-call").map((part) => ({
1085
+ id: part.toolCallId,
1086
+ type: "function",
1087
+ function: {
1088
+ name: part.toolName,
1089
+ arguments: JSON.stringify(part.input || {})
1090
+ }
1091
+ }));
1092
+ return {
1093
+ role: "assistant",
1094
+ content: textContent || null,
1095
+ ...toolCalls.length > 0 && { tool_calls: toolCalls }
1096
+ };
1097
+ }
1098
+ if (msg.role === "tool") {
1099
+ return msg.content.map((toolResponse) => ({
1100
+ role: "tool",
1101
+ tool_call_id: toolResponse.toolCallId,
1102
+ content: JSON.stringify(toolResponse.output)
1103
+ }));
1104
+ }
1105
+ return msg;
1106
+ }).flat();
1107
+ }
1108
+ convertToolsToOpenAI(tools) {
1109
+ if (!tools || Object.keys(tools).length === 0) return void 0;
1110
+ return Object.entries(tools).map(([name, tool]) => {
1111
+ if (tool.type === "function") {
1112
+ return {
1113
+ type: "function",
1114
+ function: {
1115
+ name: tool.name,
1116
+ description: tool.description,
1117
+ parameters: tool.inputSchema || {}
1118
+ }
1119
+ };
1120
+ }
1121
+ return {
1122
+ type: "function",
1123
+ function: {
1124
+ name,
1125
+ description: `Provider tool: ${name}`,
1126
+ parameters: {}
1127
+ }
1128
+ };
1129
+ });
1130
+ }
1131
+ mapFinishReason(reason) {
1132
+ switch (reason) {
1133
+ case "stop":
1134
+ return "stop";
1135
+ case "length":
1136
+ case "max_tokens":
1137
+ return "length";
1138
+ case "tool_calls":
1139
+ case "function_call":
1140
+ return "tool-calls";
1141
+ case "content_filter":
1142
+ return "content-filter";
1143
+ default:
1144
+ return "unknown";
1145
+ }
1146
+ }
1147
+ validateApiKey() {
1148
+ if (!this.apiKey && this.provider !== "openai-compatible") {
1149
+ const providerConfig = getProviderConfig(this.provider);
1150
+ if (providerConfig?.apiKeyEnvVar) {
1151
+ throw new Error(
1152
+ `API key not found for provider "${this.provider}". Please set the ${providerConfig.apiKeyEnvVar} environment variable.`
1153
+ );
1154
+ } else {
1155
+ throw new Error(
1156
+ `API key not found for provider "${this.provider}". Please provide an API key in the configuration.`
1157
+ );
1158
+ }
1159
+ }
1160
+ }
1161
+ async doGenerate() {
1162
+ throw new Error(
1163
+ "doGenerate is not supported by OpenAICompatibleModel. Mastra only uses streaming (doStream) for all LLM calls."
1164
+ );
1165
+ }
1166
+ async doStream(options) {
1167
+ this.validateApiKey();
1168
+ const { prompt, tools, toolChoice, providerOptions } = options;
1169
+ const body = {
1170
+ messages: this.convertMessagesToOpenAI(prompt),
1171
+ model: this.modelId,
1172
+ stream: true,
1173
+ ...providerOptions
1174
+ };
1175
+ const openAITools = this.convertToolsToOpenAI(tools);
1176
+ if (openAITools) {
1177
+ body.tools = openAITools;
1178
+ if (toolChoice) {
1179
+ body.tool_choice = toolChoice.type === "none" ? "none" : toolChoice.type === "required" ? "required" : toolChoice.type === "auto" ? "auto" : toolChoice.type === "tool" ? { type: "function", function: { name: toolChoice.toolName } } : "auto";
1180
+ }
1181
+ }
1182
+ if (options.responseFormat?.type === "json") {
1183
+ body.response_format = {
1184
+ type: "json_schema",
1185
+ json_schema: {
1186
+ name: "response",
1187
+ strict: true,
1188
+ schema: options.responseFormat.schema
1189
+ }
1190
+ };
1191
+ }
1192
+ const fetchArgs = {
1193
+ method: "POST",
1194
+ headers: this.headers,
1195
+ body: JSON.stringify(body),
1196
+ signal: options.abortSignal
1197
+ };
1198
+ const response = await fetch(this.url, fetchArgs);
1199
+ if (!response.ok) {
1200
+ const error = await response.text();
1201
+ if (response.status === 401 || response.status === 403) {
1202
+ const providerConfig = getProviderConfig(this.provider);
1203
+ if (providerConfig?.apiKeyEnvVar) {
1204
+ throw new Error(
1205
+ `Authentication failed for provider "${this.provider}". Please ensure the ${providerConfig.apiKeyEnvVar} environment variable is set with a valid API key.`
1206
+ );
1207
+ }
1208
+ }
1209
+ throw new Error(`OpenAI-compatible API error: ${response.status} - ${error}`);
1210
+ }
1211
+ const reader = response.body?.getReader();
1212
+ if (!reader) {
1213
+ throw new Error("Response body is not readable");
1214
+ }
1215
+ const decoder = new TextDecoder();
1216
+ let buffer = "";
1217
+ let sentStart = false;
1218
+ const toolCallBuffers = /* @__PURE__ */ new Map();
1219
+ const mapFinishReason = this.mapFinishReason.bind(this);
1220
+ const modelId = this.modelId;
1221
+ let isActiveText = false;
1222
+ const stream = new ReadableStream({
1223
+ async start(controller) {
1224
+ try {
1225
+ controller.enqueue({
1226
+ type: "stream-start",
1227
+ warnings: []
1228
+ });
1229
+ while (true) {
1230
+ const { done, value } = await reader.read();
1231
+ if (done) {
1232
+ for (const [_, toolCall] of toolCallBuffers) {
1233
+ if (!toolCall.sent && toolCall.id && toolCall.name && toolCall.args) {
1234
+ controller.enqueue({
1235
+ type: "tool-call",
1236
+ toolCallId: toolCall.id,
1237
+ toolName: toolCall.name,
1238
+ input: toolCall.args || "{}"
1239
+ });
1240
+ }
1241
+ }
1242
+ controller.close();
1243
+ break;
1244
+ }
1245
+ buffer += decoder.decode(value, { stream: true });
1246
+ const lines = buffer.split("\n");
1247
+ buffer = lines.pop() || "";
1248
+ for (const line of lines) {
1249
+ if (line.trim() === "" || line.trim() === "data: [DONE]") {
1250
+ continue;
1251
+ }
1252
+ if (line.startsWith("data: ")) {
1253
+ try {
1254
+ const data = JSON.parse(line.slice(6));
1255
+ if (!sentStart && data.id) {
1256
+ controller.enqueue({
1257
+ type: "response-metadata",
1258
+ id: data.id,
1259
+ modelId: data.model || modelId,
1260
+ timestamp: new Date(data.created ? data.created * 1e3 : Date.now())
1261
+ });
1262
+ sentStart = true;
1263
+ }
1264
+ const choice = data.choices?.[0];
1265
+ if (!choice) continue;
1266
+ if (choice.delta?.content) {
1267
+ if (!isActiveText) {
1268
+ controller.enqueue({ type: "text-start", id: "text-1" });
1269
+ isActiveText = true;
1270
+ }
1271
+ controller.enqueue({
1272
+ type: "text-delta",
1273
+ id: "text-1",
1274
+ delta: choice.delta.content
1275
+ });
1276
+ } else if (isActiveText) {
1277
+ controller.enqueue({ type: "text-end", id: "text-1" });
1278
+ isActiveText = false;
1279
+ }
1280
+ if (choice.delta?.tool_calls) {
1281
+ for (const toolCall of choice.delta.tool_calls) {
1282
+ const index = toolCall.index;
1283
+ if (!toolCallBuffers.has(index)) {
1284
+ if (toolCall.id && toolCall.function?.name) {
1285
+ controller.enqueue({
1286
+ type: "tool-input-start",
1287
+ id: toolCall.id,
1288
+ toolName: toolCall.function.name
1289
+ });
1290
+ }
1291
+ toolCallBuffers.set(index, {
1292
+ id: toolCall.id || "",
1293
+ name: toolCall.function?.name || "",
1294
+ args: ""
1295
+ });
1296
+ }
1297
+ const buffer2 = toolCallBuffers.get(index);
1298
+ if (toolCall.id) {
1299
+ buffer2.id = toolCall.id;
1300
+ }
1301
+ if (toolCall.function?.name) {
1302
+ buffer2.name = toolCall.function.name;
1303
+ }
1304
+ if (toolCall.function?.arguments) {
1305
+ buffer2.args += toolCall.function.arguments;
1306
+ controller.enqueue({
1307
+ type: "tool-input-delta",
1308
+ id: buffer2.id,
1309
+ delta: toolCall.function.arguments
1310
+ });
1311
+ try {
1312
+ JSON.parse(buffer2.args);
1313
+ if (buffer2.id && buffer2.name) {
1314
+ controller.enqueue({
1315
+ type: "tool-input-end",
1316
+ id: buffer2.id
1317
+ });
1318
+ controller.enqueue({
1319
+ type: "tool-call",
1320
+ toolCallId: buffer2.id,
1321
+ toolName: buffer2.name,
1322
+ input: buffer2.args
1323
+ });
1324
+ toolCallBuffers.set(index, {
1325
+ id: buffer2.id,
1326
+ name: buffer2.name,
1327
+ args: buffer2.args,
1328
+ sent: true
1329
+ });
1330
+ }
1331
+ } catch {
1332
+ }
1333
+ }
1334
+ }
1335
+ }
1336
+ if (choice.finish_reason) {
1337
+ toolCallBuffers.clear();
1338
+ controller.enqueue({
1339
+ type: "finish",
1340
+ finishReason: mapFinishReason(choice.finish_reason),
1341
+ usage: data.usage ? {
1342
+ inputTokens: data.usage.prompt_tokens || 0,
1343
+ outputTokens: data.usage.completion_tokens || 0,
1344
+ totalTokens: data.usage.total_tokens || 0
1345
+ } : {
1346
+ inputTokens: 0,
1347
+ outputTokens: 0,
1348
+ totalTokens: 0
1349
+ }
1350
+ });
1351
+ }
1352
+ } catch (e) {
1353
+ console.error("Error parsing SSE data:", e);
1354
+ }
1355
+ }
1356
+ }
1357
+ }
1358
+ } catch (error) {
1359
+ controller.error(error);
1360
+ }
1361
+ }
1362
+ });
1363
+ return {
1364
+ stream,
1365
+ request: { body: JSON.stringify(body) },
1366
+ response: { headers: Object.fromEntries(response.headers.entries()) },
1367
+ warnings: []
1368
+ };
1369
+ }
1370
+ };
1371
+
1372
+ export { OpenAICompatibleModel, PROVIDER_REGISTRY, getProviderConfig, parseModelString };
1373
+ //# sourceMappingURL=chunk-5M6ZTQJN.js.map
1374
+ //# sourceMappingURL=chunk-5M6ZTQJN.js.map