@averyyy/pi-ai 0.80.3-piclient.1

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 (650) hide show
  1. package/README.md +1564 -0
  2. package/dist/api/anthropic-messages.d.ts +71 -0
  3. package/dist/api/anthropic-messages.d.ts.map +1 -0
  4. package/dist/api/anthropic-messages.js +972 -0
  5. package/dist/api/anthropic-messages.js.map +1 -0
  6. package/dist/api/anthropic-messages.lazy.d.ts +3 -0
  7. package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
  8. package/dist/api/anthropic-messages.lazy.js +3 -0
  9. package/dist/api/anthropic-messages.lazy.js.map +1 -0
  10. package/dist/api/azure-openai-responses.d.ts +15 -0
  11. package/dist/api/azure-openai-responses.d.ts.map +1 -0
  12. package/dist/api/azure-openai-responses.js +219 -0
  13. package/dist/api/azure-openai-responses.js.map +1 -0
  14. package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
  15. package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
  16. package/dist/api/azure-openai-responses.lazy.js +3 -0
  17. package/dist/api/azure-openai-responses.lazy.js.map +1 -0
  18. package/dist/api/bedrock-converse-stream.d.ts +38 -0
  19. package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
  20. package/dist/api/bedrock-converse-stream.js +872 -0
  21. package/dist/api/bedrock-converse-stream.js.map +1 -0
  22. package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
  23. package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
  24. package/dist/api/bedrock-converse-stream.lazy.js +30 -0
  25. package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
  26. package/dist/api/cloudflare.d.ts +9 -0
  27. package/dist/api/cloudflare.d.ts.map +1 -0
  28. package/dist/api/cloudflare.js +9 -0
  29. package/dist/api/cloudflare.js.map +1 -0
  30. package/dist/api/github-copilot-headers.d.ts +8 -0
  31. package/dist/api/github-copilot-headers.d.ts.map +1 -0
  32. package/dist/api/github-copilot-headers.js +29 -0
  33. package/dist/api/github-copilot-headers.js.map +1 -0
  34. package/dist/api/google-generative-ai.d.ts +13 -0
  35. package/dist/api/google-generative-ai.d.ts.map +1 -0
  36. package/dist/api/google-generative-ai.js +407 -0
  37. package/dist/api/google-generative-ai.js.map +1 -0
  38. package/dist/api/google-generative-ai.lazy.d.ts +3 -0
  39. package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
  40. package/dist/api/google-generative-ai.lazy.js +3 -0
  41. package/dist/api/google-generative-ai.lazy.js.map +1 -0
  42. package/dist/api/google-shared.d.ts +70 -0
  43. package/dist/api/google-shared.d.ts.map +1 -0
  44. package/dist/api/google-shared.js +329 -0
  45. package/dist/api/google-shared.js.map +1 -0
  46. package/dist/api/google-vertex.d.ts +15 -0
  47. package/dist/api/google-vertex.d.ts.map +1 -0
  48. package/dist/api/google-vertex.js +456 -0
  49. package/dist/api/google-vertex.js.map +1 -0
  50. package/dist/api/google-vertex.lazy.d.ts +3 -0
  51. package/dist/api/google-vertex.lazy.d.ts.map +1 -0
  52. package/dist/api/google-vertex.lazy.js +3 -0
  53. package/dist/api/google-vertex.lazy.js.map +1 -0
  54. package/dist/api/lazy.d.ts +15 -0
  55. package/dist/api/lazy.d.ts.map +1 -0
  56. package/dist/api/lazy.js +59 -0
  57. package/dist/api/lazy.js.map +1 -0
  58. package/dist/api/mistral-conversations.d.ts +25 -0
  59. package/dist/api/mistral-conversations.d.ts.map +1 -0
  60. package/dist/api/mistral-conversations.js +555 -0
  61. package/dist/api/mistral-conversations.js.map +1 -0
  62. package/dist/api/mistral-conversations.lazy.d.ts +3 -0
  63. package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
  64. package/dist/api/mistral-conversations.lazy.js +3 -0
  65. package/dist/api/mistral-conversations.lazy.js.map +1 -0
  66. package/dist/api/openai-codex-responses.d.ts +30 -0
  67. package/dist/api/openai-codex-responses.d.ts.map +1 -0
  68. package/dist/api/openai-codex-responses.js +1215 -0
  69. package/dist/api/openai-codex-responses.js.map +1 -0
  70. package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
  71. package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
  72. package/dist/api/openai-codex-responses.lazy.js +3 -0
  73. package/dist/api/openai-codex-responses.lazy.js.map +1 -0
  74. package/dist/api/openai-completions.d.ts +19 -0
  75. package/dist/api/openai-completions.d.ts.map +1 -0
  76. package/dist/api/openai-completions.js +1058 -0
  77. package/dist/api/openai-completions.js.map +1 -0
  78. package/dist/api/openai-completions.lazy.d.ts +3 -0
  79. package/dist/api/openai-completions.lazy.d.ts.map +1 -0
  80. package/dist/api/openai-completions.lazy.js +3 -0
  81. package/dist/api/openai-completions.lazy.js.map +1 -0
  82. package/dist/api/openai-prompt-cache.d.ts +3 -0
  83. package/dist/api/openai-prompt-cache.d.ts.map +1 -0
  84. package/dist/api/openai-prompt-cache.js +10 -0
  85. package/dist/api/openai-prompt-cache.js.map +1 -0
  86. package/dist/api/openai-responses-shared.d.ts +18 -0
  87. package/dist/api/openai-responses-shared.d.ts.map +1 -0
  88. package/dist/api/openai-responses-shared.js +482 -0
  89. package/dist/api/openai-responses-shared.js.map +1 -0
  90. package/dist/api/openai-responses.d.ts +13 -0
  91. package/dist/api/openai-responses.d.ts.map +1 -0
  92. package/dist/api/openai-responses.js +226 -0
  93. package/dist/api/openai-responses.js.map +1 -0
  94. package/dist/api/openai-responses.lazy.d.ts +3 -0
  95. package/dist/api/openai-responses.lazy.d.ts.map +1 -0
  96. package/dist/api/openai-responses.lazy.js +3 -0
  97. package/dist/api/openai-responses.lazy.js.map +1 -0
  98. package/dist/api/openrouter-images.d.ts +3 -0
  99. package/dist/api/openrouter-images.d.ts.map +1 -0
  100. package/dist/api/openrouter-images.js +126 -0
  101. package/dist/api/openrouter-images.js.map +1 -0
  102. package/dist/api/openrouter-images.lazy.d.ts +3 -0
  103. package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
  104. package/dist/api/openrouter-images.lazy.js +4 -0
  105. package/dist/api/openrouter-images.lazy.js.map +1 -0
  106. package/dist/api/simple-options.d.ts +9 -0
  107. package/dist/api/simple-options.d.ts.map +1 -0
  108. package/dist/api/simple-options.js +52 -0
  109. package/dist/api/simple-options.js.map +1 -0
  110. package/dist/api/transform-messages.d.ts +8 -0
  111. package/dist/api/transform-messages.d.ts.map +1 -0
  112. package/dist/api/transform-messages.js +184 -0
  113. package/dist/api/transform-messages.js.map +1 -0
  114. package/dist/api-registry.d.ts +20 -0
  115. package/dist/api-registry.d.ts.map +1 -0
  116. package/dist/api-registry.js +44 -0
  117. package/dist/api-registry.js.map +1 -0
  118. package/dist/auth/context.d.ts +7 -0
  119. package/dist/auth/context.d.ts.map +1 -0
  120. package/dist/auth/context.js +42 -0
  121. package/dist/auth/context.js.map +1 -0
  122. package/dist/auth/credential-store.d.ts +16 -0
  123. package/dist/auth/credential-store.d.ts.map +1 -0
  124. package/dist/auth/credential-store.js +37 -0
  125. package/dist/auth/credential-store.js.map +1 -0
  126. package/dist/auth/helpers.d.ts +20 -0
  127. package/dist/auth/helpers.d.ts.map +1 -0
  128. package/dist/auth/helpers.js +46 -0
  129. package/dist/auth/helpers.js.map +1 -0
  130. package/dist/auth/resolve.d.ts +26 -0
  131. package/dist/auth/resolve.d.ts.map +1 -0
  132. package/dist/auth/resolve.js +101 -0
  133. package/dist/auth/resolve.js.map +1 -0
  134. package/dist/auth/types.d.ts +180 -0
  135. package/dist/auth/types.d.ts.map +1 -0
  136. package/dist/auth/types.js +2 -0
  137. package/dist/auth/types.js.map +1 -0
  138. package/dist/bedrock-provider.d.ts +5 -0
  139. package/dist/bedrock-provider.d.ts.map +1 -0
  140. package/dist/bedrock-provider.js +6 -0
  141. package/dist/bedrock-provider.js.map +1 -0
  142. package/dist/cli.d.ts +3 -0
  143. package/dist/cli.d.ts.map +1 -0
  144. package/dist/cli.js +130 -0
  145. package/dist/cli.js.map +1 -0
  146. package/dist/compat.d.ts +65 -0
  147. package/dist/compat.d.ts.map +1 -0
  148. package/dist/compat.js +182 -0
  149. package/dist/compat.js.map +1 -0
  150. package/dist/env-api-keys.d.ts +18 -0
  151. package/dist/env-api-keys.d.ts.map +1 -0
  152. package/dist/env-api-keys.js +145 -0
  153. package/dist/env-api-keys.js.map +1 -0
  154. package/dist/image-models.d.ts +10 -0
  155. package/dist/image-models.d.ts.map +1 -0
  156. package/dist/image-models.generated.d.ts +530 -0
  157. package/dist/image-models.generated.d.ts.map +1 -0
  158. package/dist/image-models.generated.js +532 -0
  159. package/dist/image-models.generated.js.map +1 -0
  160. package/dist/image-models.js +23 -0
  161. package/dist/image-models.js.map +1 -0
  162. package/dist/images-api-registry.d.ts +14 -0
  163. package/dist/images-api-registry.d.ts.map +1 -0
  164. package/dist/images-api-registry.js +22 -0
  165. package/dist/images-api-registry.js.map +1 -0
  166. package/dist/images-models.d.ts +93 -0
  167. package/dist/images-models.d.ts.map +1 -0
  168. package/dist/images-models.js +141 -0
  169. package/dist/images-models.js.map +1 -0
  170. package/dist/images.d.ts +4 -0
  171. package/dist/images.d.ts.map +1 -0
  172. package/dist/images.js +14 -0
  173. package/dist/images.js.map +1 -0
  174. package/dist/index.d.ts +31 -0
  175. package/dist/index.d.ts.map +1 -0
  176. package/dist/index.js +19 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/legacy-api-aliases.d.ts +42 -0
  179. package/dist/legacy-api-aliases.d.ts.map +1 -0
  180. package/dist/legacy-api-aliases.js +49 -0
  181. package/dist/legacy-api-aliases.js.map +1 -0
  182. package/dist/models.d.ts +142 -0
  183. package/dist/models.d.ts.map +1 -0
  184. package/dist/models.generated.d.ts +20965 -0
  185. package/dist/models.generated.d.ts.map +1 -0
  186. package/dist/models.generated.js +75 -0
  187. package/dist/models.generated.js.map +1 -0
  188. package/dist/models.js +238 -0
  189. package/dist/models.js.map +1 -0
  190. package/dist/oauth.d.ts +2 -0
  191. package/dist/oauth.d.ts.map +1 -0
  192. package/dist/oauth.js +2 -0
  193. package/dist/oauth.js.map +1 -0
  194. package/dist/providers/all.d.ts +21 -0
  195. package/dist/providers/all.d.ts.map +1 -0
  196. package/dist/providers/all.js +114 -0
  197. package/dist/providers/all.js.map +1 -0
  198. package/dist/providers/amazon-bedrock.d.ts +3 -0
  199. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  200. package/dist/providers/amazon-bedrock.js +39 -0
  201. package/dist/providers/amazon-bedrock.js.map +1 -0
  202. package/dist/providers/amazon-bedrock.models.d.ts +1837 -0
  203. package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
  204. package/dist/providers/amazon-bedrock.models.js +1794 -0
  205. package/dist/providers/amazon-bedrock.models.js.map +1 -0
  206. package/dist/providers/ant-ling.d.ts +3 -0
  207. package/dist/providers/ant-ling.d.ts.map +1 -0
  208. package/dist/providers/ant-ling.js +15 -0
  209. package/dist/providers/ant-ling.js.map +1 -0
  210. package/dist/providers/ant-ling.models.d.ts +86 -0
  211. package/dist/providers/ant-ling.models.d.ts.map +1 -0
  212. package/dist/providers/ant-ling.models.js +60 -0
  213. package/dist/providers/ant-ling.models.js.map +1 -0
  214. package/dist/providers/anthropic.d.ts +3 -0
  215. package/dist/providers/anthropic.d.ts.map +1 -0
  216. package/dist/providers/anthropic.js +20 -0
  217. package/dist/providers/anthropic.js.map +1 -0
  218. package/dist/providers/anthropic.models.d.ts +444 -0
  219. package/dist/providers/anthropic.models.d.ts.map +1 -0
  220. package/dist/providers/anthropic.models.js +423 -0
  221. package/dist/providers/anthropic.models.js.map +1 -0
  222. package/dist/providers/azure-openai-responses.d.ts +3 -0
  223. package/dist/providers/azure-openai-responses.d.ts.map +1 -0
  224. package/dist/providers/azure-openai-responses.js +14 -0
  225. package/dist/providers/azure-openai-responses.js.map +1 -0
  226. package/dist/providers/azure-openai-responses.models.d.ts +804 -0
  227. package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
  228. package/dist/providers/azure-openai-responses.models.js +743 -0
  229. package/dist/providers/azure-openai-responses.models.js.map +1 -0
  230. package/dist/providers/cerebras.d.ts +3 -0
  231. package/dist/providers/cerebras.d.ts.map +1 -0
  232. package/dist/providers/cerebras.js +15 -0
  233. package/dist/providers/cerebras.js.map +1 -0
  234. package/dist/providers/cerebras.models.d.ts +45 -0
  235. package/dist/providers/cerebras.models.d.ts.map +1 -0
  236. package/dist/providers/cerebras.models.js +41 -0
  237. package/dist/providers/cerebras.models.js.map +1 -0
  238. package/dist/providers/cloudflare-ai-gateway.d.ts +3 -0
  239. package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
  240. package/dist/providers/cloudflare-ai-gateway.js +20 -0
  241. package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
  242. package/dist/providers/cloudflare-ai-gateway.models.d.ts +765 -0
  243. package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
  244. package/dist/providers/cloudflare-ai-gateway.models.js +666 -0
  245. package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
  246. package/dist/providers/cloudflare-auth.d.ts +4 -0
  247. package/dist/providers/cloudflare-auth.d.ts.map +1 -0
  248. package/dist/providers/cloudflare-auth.js +85 -0
  249. package/dist/providers/cloudflare-auth.js.map +1 -0
  250. package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
  251. package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
  252. package/dist/providers/cloudflare-workers-ai.js +14 -0
  253. package/dist/providers/cloudflare-workers-ai.js.map +1 -0
  254. package/dist/providers/cloudflare-workers-ai.models.d.ts +302 -0
  255. package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
  256. package/dist/providers/cloudflare-workers-ai.models.js +239 -0
  257. package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
  258. package/dist/providers/cloudflare.d.ts +13 -0
  259. package/dist/providers/cloudflare.d.ts.map +1 -0
  260. package/dist/providers/cloudflare.js +26 -0
  261. package/dist/providers/cloudflare.js.map +1 -0
  262. package/dist/providers/deepseek.d.ts +3 -0
  263. package/dist/providers/deepseek.d.ts.map +1 -0
  264. package/dist/providers/deepseek.js +15 -0
  265. package/dist/providers/deepseek.js.map +1 -0
  266. package/dist/providers/deepseek.models.d.ts +63 -0
  267. package/dist/providers/deepseek.models.d.ts.map +1 -0
  268. package/dist/providers/deepseek.models.js +43 -0
  269. package/dist/providers/deepseek.models.js.map +1 -0
  270. package/dist/providers/faux.d.ts +97 -0
  271. package/dist/providers/faux.d.ts.map +1 -0
  272. package/dist/providers/faux.js +395 -0
  273. package/dist/providers/faux.js.map +1 -0
  274. package/dist/providers/fireworks.d.ts +3 -0
  275. package/dist/providers/fireworks.d.ts.map +1 -0
  276. package/dist/providers/fireworks.js +19 -0
  277. package/dist/providers/fireworks.js.map +1 -0
  278. package/dist/providers/fireworks.models.d.ts +376 -0
  279. package/dist/providers/fireworks.models.d.ts.map +1 -0
  280. package/dist/providers/fireworks.models.js +294 -0
  281. package/dist/providers/fireworks.models.js.map +1 -0
  282. package/dist/providers/github-copilot-headers.d.ts +8 -0
  283. package/dist/providers/github-copilot-headers.d.ts.map +1 -0
  284. package/dist/providers/github-copilot-headers.js +29 -0
  285. package/dist/providers/github-copilot-headers.js.map +1 -0
  286. package/dist/providers/github-copilot.d.ts +3 -0
  287. package/dist/providers/github-copilot.d.ts.map +1 -0
  288. package/dist/providers/github-copilot.js +25 -0
  289. package/dist/providers/github-copilot.js.map +1 -0
  290. package/dist/providers/github-copilot.models.d.ts +616 -0
  291. package/dist/providers/github-copilot.models.d.ts.map +1 -0
  292. package/dist/providers/github-copilot.models.js +426 -0
  293. package/dist/providers/github-copilot.models.js.map +1 -0
  294. package/dist/providers/google-shared.d.ts +70 -0
  295. package/dist/providers/google-shared.d.ts.map +1 -0
  296. package/dist/providers/google-shared.js +329 -0
  297. package/dist/providers/google-shared.js.map +1 -0
  298. package/dist/providers/google-vertex.d.ts +3 -0
  299. package/dist/providers/google-vertex.d.ts.map +1 -0
  300. package/dist/providers/google-vertex.js +35 -0
  301. package/dist/providers/google-vertex.js.map +1 -0
  302. package/dist/providers/google-vertex.models.d.ts +202 -0
  303. package/dist/providers/google-vertex.models.d.ts.map +1 -0
  304. package/dist/providers/google-vertex.models.js +182 -0
  305. package/dist/providers/google-vertex.models.js.map +1 -0
  306. package/dist/providers/google.d.ts +3 -0
  307. package/dist/providers/google.d.ts.map +1 -0
  308. package/dist/providers/google.js +15 -0
  309. package/dist/providers/google.js.map +1 -0
  310. package/dist/providers/google.models.d.ts +328 -0
  311. package/dist/providers/google.models.d.ts.map +1 -0
  312. package/dist/providers/google.models.js +288 -0
  313. package/dist/providers/google.models.js.map +1 -0
  314. package/dist/providers/groq.d.ts +3 -0
  315. package/dist/providers/groq.d.ts.map +1 -0
  316. package/dist/providers/groq.js +15 -0
  317. package/dist/providers/groq.js.map +1 -0
  318. package/dist/providers/groq.models.d.ts +128 -0
  319. package/dist/providers/groq.models.d.ts.map +1 -0
  320. package/dist/providers/groq.models.js +125 -0
  321. package/dist/providers/groq.models.js.map +1 -0
  322. package/dist/providers/huggingface.d.ts +3 -0
  323. package/dist/providers/huggingface.d.ts.map +1 -0
  324. package/dist/providers/huggingface.js +15 -0
  325. package/dist/providers/huggingface.js.map +1 -0
  326. package/dist/providers/huggingface.models.d.ts +963 -0
  327. package/dist/providers/huggingface.models.d.ts.map +1 -0
  328. package/dist/providers/huggingface.models.js +869 -0
  329. package/dist/providers/huggingface.models.js.map +1 -0
  330. package/dist/providers/images/openrouter.d.ts +3 -0
  331. package/dist/providers/images/openrouter.d.ts.map +1 -0
  332. package/dist/providers/images/openrouter.js +128 -0
  333. package/dist/providers/images/openrouter.js.map +1 -0
  334. package/dist/providers/images/register-builtins.d.ts +4 -0
  335. package/dist/providers/images/register-builtins.d.ts.map +1 -0
  336. package/dist/providers/images/register-builtins.js +34 -0
  337. package/dist/providers/images/register-builtins.js.map +1 -0
  338. package/dist/providers/kimi-coding.d.ts +3 -0
  339. package/dist/providers/kimi-coding.d.ts.map +1 -0
  340. package/dist/providers/kimi-coding.js +15 -0
  341. package/dist/providers/kimi-coding.js.map +1 -0
  342. package/dist/providers/kimi-coding.models.d.ts +63 -0
  343. package/dist/providers/kimi-coding.models.d.ts.map +1 -0
  344. package/dist/providers/kimi-coding.models.js +59 -0
  345. package/dist/providers/kimi-coding.models.js.map +1 -0
  346. package/dist/providers/minimax-cn.d.ts +3 -0
  347. package/dist/providers/minimax-cn.d.ts.map +1 -0
  348. package/dist/providers/minimax-cn.js +15 -0
  349. package/dist/providers/minimax-cn.js.map +1 -0
  350. package/dist/providers/minimax-cn.models.d.ts +54 -0
  351. package/dist/providers/minimax-cn.models.d.ts.map +1 -0
  352. package/dist/providers/minimax-cn.models.js +56 -0
  353. package/dist/providers/minimax-cn.models.js.map +1 -0
  354. package/dist/providers/minimax.d.ts +3 -0
  355. package/dist/providers/minimax.d.ts.map +1 -0
  356. package/dist/providers/minimax.js +15 -0
  357. package/dist/providers/minimax.js.map +1 -0
  358. package/dist/providers/minimax.models.d.ts +54 -0
  359. package/dist/providers/minimax.models.d.ts.map +1 -0
  360. package/dist/providers/minimax.models.js +56 -0
  361. package/dist/providers/minimax.models.js.map +1 -0
  362. package/dist/providers/mistral.d.ts +3 -0
  363. package/dist/providers/mistral.d.ts.map +1 -0
  364. package/dist/providers/mistral.js +15 -0
  365. package/dist/providers/mistral.js.map +1 -0
  366. package/dist/providers/mistral.models.d.ts +513 -0
  367. package/dist/providers/mistral.models.d.ts.map +1 -0
  368. package/dist/providers/mistral.models.js +515 -0
  369. package/dist/providers/mistral.models.js.map +1 -0
  370. package/dist/providers/moonshotai-cn.d.ts +3 -0
  371. package/dist/providers/moonshotai-cn.d.ts.map +1 -0
  372. package/dist/providers/moonshotai-cn.js +15 -0
  373. package/dist/providers/moonshotai-cn.js.map +1 -0
  374. package/dist/providers/moonshotai-cn.models.d.ts +234 -0
  375. package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
  376. package/dist/providers/moonshotai-cn.models.js +169 -0
  377. package/dist/providers/moonshotai-cn.models.js.map +1 -0
  378. package/dist/providers/moonshotai.d.ts +3 -0
  379. package/dist/providers/moonshotai.d.ts.map +1 -0
  380. package/dist/providers/moonshotai.js +15 -0
  381. package/dist/providers/moonshotai.js.map +1 -0
  382. package/dist/providers/moonshotai.models.d.ts +234 -0
  383. package/dist/providers/moonshotai.models.d.ts.map +1 -0
  384. package/dist/providers/moonshotai.models.js +169 -0
  385. package/dist/providers/moonshotai.models.js.map +1 -0
  386. package/dist/providers/nvidia.d.ts +3 -0
  387. package/dist/providers/nvidia.d.ts.map +1 -0
  388. package/dist/providers/nvidia.js +15 -0
  389. package/dist/providers/nvidia.js.map +1 -0
  390. package/dist/providers/nvidia.models.d.ts +563 -0
  391. package/dist/providers/nvidia.models.d.ts.map +1 -0
  392. package/dist/providers/nvidia.models.js +385 -0
  393. package/dist/providers/nvidia.models.js.map +1 -0
  394. package/dist/providers/openai-codex-responses.d.ts +30 -0
  395. package/dist/providers/openai-codex-responses.d.ts.map +1 -0
  396. package/dist/providers/openai-codex-responses.js +1173 -0
  397. package/dist/providers/openai-codex-responses.js.map +1 -0
  398. package/dist/providers/openai-codex.d.ts +3 -0
  399. package/dist/providers/openai-codex.d.ts.map +1 -0
  400. package/dist/providers/openai-codex.js +18 -0
  401. package/dist/providers/openai-codex.js.map +1 -0
  402. package/dist/providers/openai-codex.models.d.ts +87 -0
  403. package/dist/providers/openai-codex.models.d.ts.map +1 -0
  404. package/dist/providers/openai-codex.models.js +77 -0
  405. package/dist/providers/openai-codex.models.js.map +1 -0
  406. package/dist/providers/openai-completions.d.ts +19 -0
  407. package/dist/providers/openai-completions.d.ts.map +1 -0
  408. package/dist/providers/openai-completions.js +977 -0
  409. package/dist/providers/openai-completions.js.map +1 -0
  410. package/dist/providers/openai-prompt-cache.d.ts +3 -0
  411. package/dist/providers/openai-prompt-cache.d.ts.map +1 -0
  412. package/dist/providers/openai-prompt-cache.js +10 -0
  413. package/dist/providers/openai-prompt-cache.js.map +1 -0
  414. package/dist/providers/openai-responses-shared.d.ts +18 -0
  415. package/dist/providers/openai-responses-shared.d.ts.map +1 -0
  416. package/dist/providers/openai-responses-shared.js +496 -0
  417. package/dist/providers/openai-responses-shared.js.map +1 -0
  418. package/dist/providers/openai-responses.d.ts +13 -0
  419. package/dist/providers/openai-responses.d.ts.map +1 -0
  420. package/dist/providers/openai-responses.js +234 -0
  421. package/dist/providers/openai-responses.js.map +1 -0
  422. package/dist/providers/openai.d.ts +3 -0
  423. package/dist/providers/openai.d.ts.map +1 -0
  424. package/dist/providers/openai.js +15 -0
  425. package/dist/providers/openai.js.map +1 -0
  426. package/dist/providers/openai.models.d.ts +805 -0
  427. package/dist/providers/openai.models.d.ts.map +1 -0
  428. package/dist/providers/openai.models.js +743 -0
  429. package/dist/providers/openai.models.js.map +1 -0
  430. package/dist/providers/opencode-go.d.ts +3 -0
  431. package/dist/providers/opencode-go.d.ts.map +1 -0
  432. package/dist/providers/opencode-go.js +18 -0
  433. package/dist/providers/opencode-go.js.map +1 -0
  434. package/dist/providers/opencode-go.models.d.ts +309 -0
  435. package/dist/providers/opencode-go.models.d.ts.map +1 -0
  436. package/dist/providers/opencode-go.models.js +240 -0
  437. package/dist/providers/opencode-go.models.js.map +1 -0
  438. package/dist/providers/opencode.d.ts +3 -0
  439. package/dist/providers/opencode.d.ts.map +1 -0
  440. package/dist/providers/opencode.js +22 -0
  441. package/dist/providers/opencode.js.map +1 -0
  442. package/dist/providers/opencode.models.d.ts +976 -0
  443. package/dist/providers/opencode.models.d.ts.map +1 -0
  444. package/dist/providers/opencode.models.js +815 -0
  445. package/dist/providers/opencode.models.js.map +1 -0
  446. package/dist/providers/openrouter-images.d.ts +3 -0
  447. package/dist/providers/openrouter-images.d.ts.map +1 -0
  448. package/dist/providers/openrouter-images.js +14 -0
  449. package/dist/providers/openrouter-images.js.map +1 -0
  450. package/dist/providers/openrouter.d.ts +3 -0
  451. package/dist/providers/openrouter.d.ts.map +1 -0
  452. package/dist/providers/openrouter.js +15 -0
  453. package/dist/providers/openrouter.js.map +1 -0
  454. package/dist/providers/openrouter.models.d.ts +5402 -0
  455. package/dist/providers/openrouter.models.d.ts.map +1 -0
  456. package/dist/providers/openrouter.models.js +4634 -0
  457. package/dist/providers/openrouter.models.js.map +1 -0
  458. package/dist/providers/register-builtins.d.ts +35 -0
  459. package/dist/providers/register-builtins.d.ts.map +1 -0
  460. package/dist/providers/register-builtins.js +254 -0
  461. package/dist/providers/register-builtins.js.map +1 -0
  462. package/dist/providers/simple-options.d.ts +8 -0
  463. package/dist/providers/simple-options.d.ts.map +1 -0
  464. package/dist/providers/simple-options.js +42 -0
  465. package/dist/providers/simple-options.js.map +1 -0
  466. package/dist/providers/together.d.ts +3 -0
  467. package/dist/providers/together.d.ts.map +1 -0
  468. package/dist/providers/together.js +15 -0
  469. package/dist/providers/together.js.map +1 -0
  470. package/dist/providers/together.models.d.ts +598 -0
  471. package/dist/providers/together.models.d.ts.map +1 -0
  472. package/dist/providers/together.models.js +380 -0
  473. package/dist/providers/together.models.js.map +1 -0
  474. package/dist/providers/transform-messages.d.ts +8 -0
  475. package/dist/providers/transform-messages.d.ts.map +1 -0
  476. package/dist/providers/transform-messages.js +184 -0
  477. package/dist/providers/transform-messages.js.map +1 -0
  478. package/dist/providers/vercel-ai-gateway.d.ts +3 -0
  479. package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
  480. package/dist/providers/vercel-ai-gateway.js +15 -0
  481. package/dist/providers/vercel-ai-gateway.js.map +1 -0
  482. package/dist/providers/vercel-ai-gateway.models.d.ts +3230 -0
  483. package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
  484. package/dist/providers/vercel-ai-gateway.models.js +3187 -0
  485. package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
  486. package/dist/providers/xai.d.ts +3 -0
  487. package/dist/providers/xai.d.ts.map +1 -0
  488. package/dist/providers/xai.js +15 -0
  489. package/dist/providers/xai.js.map +1 -0
  490. package/dist/providers/xai.models.d.ts +157 -0
  491. package/dist/providers/xai.models.d.ts.map +1 -0
  492. package/dist/providers/xai.models.js +131 -0
  493. package/dist/providers/xai.models.js.map +1 -0
  494. package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
  495. package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
  496. package/dist/providers/xiaomi-token-plan-ams.js +15 -0
  497. package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
  498. package/dist/providers/xiaomi-token-plan-ams.models.d.ts +108 -0
  499. package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
  500. package/dist/providers/xiaomi-token-plan-ams.models.js +95 -0
  501. package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
  502. package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
  503. package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
  504. package/dist/providers/xiaomi-token-plan-cn.js +15 -0
  505. package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
  506. package/dist/providers/xiaomi-token-plan-cn.models.d.ts +108 -0
  507. package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
  508. package/dist/providers/xiaomi-token-plan-cn.models.js +95 -0
  509. package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
  510. package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
  511. package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
  512. package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
  513. package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
  514. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +108 -0
  515. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
  516. package/dist/providers/xiaomi-token-plan-sgp.models.js +95 -0
  517. package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
  518. package/dist/providers/xiaomi.d.ts +3 -0
  519. package/dist/providers/xiaomi.d.ts.map +1 -0
  520. package/dist/providers/xiaomi.js +15 -0
  521. package/dist/providers/xiaomi.js.map +1 -0
  522. package/dist/providers/xiaomi.models.d.ts +129 -0
  523. package/dist/providers/xiaomi.models.d.ts.map +1 -0
  524. package/dist/providers/xiaomi.models.js +113 -0
  525. package/dist/providers/xiaomi.models.js.map +1 -0
  526. package/dist/providers/zai-coding-cn.d.ts +3 -0
  527. package/dist/providers/zai-coding-cn.d.ts.map +1 -0
  528. package/dist/providers/zai-coding-cn.js +15 -0
  529. package/dist/providers/zai-coding-cn.js.map +1 -0
  530. package/dist/providers/zai-coding-cn.models.d.ts +153 -0
  531. package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
  532. package/dist/providers/zai-coding-cn.models.js +114 -0
  533. package/dist/providers/zai-coding-cn.models.js.map +1 -0
  534. package/dist/providers/zai.d.ts +3 -0
  535. package/dist/providers/zai.d.ts.map +1 -0
  536. package/dist/providers/zai.js +15 -0
  537. package/dist/providers/zai.js.map +1 -0
  538. package/dist/providers/zai.models.d.ts +153 -0
  539. package/dist/providers/zai.models.d.ts.map +1 -0
  540. package/dist/providers/zai.models.js +114 -0
  541. package/dist/providers/zai.models.js.map +1 -0
  542. package/dist/session-resources.d.ts +4 -0
  543. package/dist/session-resources.d.ts.map +1 -0
  544. package/dist/session-resources.js +22 -0
  545. package/dist/session-resources.js.map +1 -0
  546. package/dist/stream.d.ts +8 -0
  547. package/dist/stream.d.ts.map +1 -0
  548. package/dist/stream.js +39 -0
  549. package/dist/stream.js.map +1 -0
  550. package/dist/types.d.ts +597 -0
  551. package/dist/types.d.ts.map +1 -0
  552. package/dist/types.js +2 -0
  553. package/dist/types.js.map +1 -0
  554. package/dist/utils/abort-signals.d.ts +6 -0
  555. package/dist/utils/abort-signals.d.ts.map +1 -0
  556. package/dist/utils/abort-signals.js +34 -0
  557. package/dist/utils/abort-signals.js.map +1 -0
  558. package/dist/utils/diagnostics.d.ts +19 -0
  559. package/dist/utils/diagnostics.d.ts.map +1 -0
  560. package/dist/utils/diagnostics.js +25 -0
  561. package/dist/utils/diagnostics.js.map +1 -0
  562. package/dist/utils/error-body.d.ts +25 -0
  563. package/dist/utils/error-body.d.ts.map +1 -0
  564. package/dist/utils/error-body.js +109 -0
  565. package/dist/utils/error-body.js.map +1 -0
  566. package/dist/utils/estimate.d.ts +17 -0
  567. package/dist/utils/estimate.d.ts.map +1 -0
  568. package/dist/utils/estimate.js +95 -0
  569. package/dist/utils/estimate.js.map +1 -0
  570. package/dist/utils/event-stream.d.ts +21 -0
  571. package/dist/utils/event-stream.d.ts.map +1 -0
  572. package/dist/utils/event-stream.js +81 -0
  573. package/dist/utils/event-stream.js.map +1 -0
  574. package/dist/utils/hash.d.ts +3 -0
  575. package/dist/utils/hash.d.ts.map +1 -0
  576. package/dist/utils/hash.js +14 -0
  577. package/dist/utils/hash.js.map +1 -0
  578. package/dist/utils/headers.d.ts +4 -0
  579. package/dist/utils/headers.d.ts.map +1 -0
  580. package/dist/utils/headers.js +18 -0
  581. package/dist/utils/headers.js.map +1 -0
  582. package/dist/utils/json-parse.d.ts +16 -0
  583. package/dist/utils/json-parse.d.ts.map +1 -0
  584. package/dist/utils/json-parse.js +113 -0
  585. package/dist/utils/json-parse.js.map +1 -0
  586. package/dist/utils/node-http-proxy.d.ts +4 -0
  587. package/dist/utils/node-http-proxy.d.ts.map +1 -0
  588. package/dist/utils/node-http-proxy.js +92 -0
  589. package/dist/utils/node-http-proxy.js.map +1 -0
  590. package/dist/utils/oauth/anthropic.d.ts +27 -0
  591. package/dist/utils/oauth/anthropic.d.ts.map +1 -0
  592. package/dist/utils/oauth/anthropic.js +367 -0
  593. package/dist/utils/oauth/anthropic.js.map +1 -0
  594. package/dist/utils/oauth/device-code.d.ts +21 -0
  595. package/dist/utils/oauth/device-code.d.ts.map +1 -0
  596. package/dist/utils/oauth/device-code.js +56 -0
  597. package/dist/utils/oauth/device-code.js.map +1 -0
  598. package/dist/utils/oauth/github-copilot.d.ts +32 -0
  599. package/dist/utils/oauth/github-copilot.d.ts.map +1 -0
  600. package/dist/utils/oauth/github-copilot.js +370 -0
  601. package/dist/utils/oauth/github-copilot.js.map +1 -0
  602. package/dist/utils/oauth/index.d.ts +58 -0
  603. package/dist/utils/oauth/index.d.ts.map +1 -0
  604. package/dist/utils/oauth/index.js +122 -0
  605. package/dist/utils/oauth/index.js.map +1 -0
  606. package/dist/utils/oauth/load.d.ts +5 -0
  607. package/dist/utils/oauth/load.d.ts.map +1 -0
  608. package/dist/utils/oauth/load.js +22 -0
  609. package/dist/utils/oauth/load.js.map +1 -0
  610. package/dist/utils/oauth/oauth-page.d.ts +3 -0
  611. package/dist/utils/oauth/oauth-page.d.ts.map +1 -0
  612. package/dist/utils/oauth/oauth-page.js +105 -0
  613. package/dist/utils/oauth/oauth-page.js.map +1 -0
  614. package/dist/utils/oauth/openai-codex.d.ts +45 -0
  615. package/dist/utils/oauth/openai-codex.d.ts.map +1 -0
  616. package/dist/utils/oauth/openai-codex.js +537 -0
  617. package/dist/utils/oauth/openai-codex.js.map +1 -0
  618. package/dist/utils/oauth/pkce.d.ts +13 -0
  619. package/dist/utils/oauth/pkce.d.ts.map +1 -0
  620. package/dist/utils/oauth/pkce.js +31 -0
  621. package/dist/utils/oauth/pkce.js.map +1 -0
  622. package/dist/utils/oauth/types.d.ts +64 -0
  623. package/dist/utils/oauth/types.d.ts.map +1 -0
  624. package/dist/utils/oauth/types.js +2 -0
  625. package/dist/utils/oauth/types.js.map +1 -0
  626. package/dist/utils/overflow.d.ts +57 -0
  627. package/dist/utils/overflow.d.ts.map +1 -0
  628. package/dist/utils/overflow.js +155 -0
  629. package/dist/utils/overflow.js.map +1 -0
  630. package/dist/utils/provider-env.d.ts +7 -0
  631. package/dist/utils/provider-env.d.ts.map +1 -0
  632. package/dist/utils/provider-env.js +44 -0
  633. package/dist/utils/provider-env.js.map +1 -0
  634. package/dist/utils/retry.d.ts +12 -0
  635. package/dist/utils/retry.d.ts.map +1 -0
  636. package/dist/utils/retry.js +86 -0
  637. package/dist/utils/retry.js.map +1 -0
  638. package/dist/utils/sanitize-unicode.d.ts +22 -0
  639. package/dist/utils/sanitize-unicode.d.ts.map +1 -0
  640. package/dist/utils/sanitize-unicode.js +26 -0
  641. package/dist/utils/sanitize-unicode.js.map +1 -0
  642. package/dist/utils/typebox-helpers.d.ts +17 -0
  643. package/dist/utils/typebox-helpers.d.ts.map +1 -0
  644. package/dist/utils/typebox-helpers.js +21 -0
  645. package/dist/utils/typebox-helpers.js.map +1 -0
  646. package/dist/utils/validation.d.ts +18 -0
  647. package/dist/utils/validation.d.ts.map +1 -0
  648. package/dist/utils/validation.js +281 -0
  649. package/dist/utils/validation.js.map +1 -0
  650. package/package.json +92 -0
package/README.md ADDED
@@ -0,0 +1,1564 @@
1
+ # @earendil-works/pi-ai
2
+
3
+ Unified LLM API with provider collections, automatic auth resolution, token and cost tracking, and simple context persistence and hand-off to other models mid-session.
4
+
5
+ **Note**: This library only includes models that support tool calling (function calling), as this is essential for agentic workflows.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Supported Providers](#supported-providers)
10
+ - [Installation](#installation)
11
+ - [Quick Start](#quick-start)
12
+ - [Providers and Models](#providers-and-models)
13
+ - [Provider Factories](#provider-factories)
14
+ - [All Built-in Providers](#all-built-in-providers)
15
+ - [Querying Models](#querying-models)
16
+ - [Static Catalog Reads](#static-catalog-reads)
17
+ - [Dynamic Providers](#dynamic-providers)
18
+ - [Auth](#auth)
19
+ - [How Auth Resolves](#how-auth-resolves)
20
+ - [Credential Store](#credential-store)
21
+ - [Environment Variables](#environment-variables)
22
+ - [Tools](#tools)
23
+ - [Defining Tools](#defining-tools)
24
+ - [Handling Tool Calls](#handling-tool-calls)
25
+ - [Streaming Tool Calls with Partial JSON](#streaming-tool-calls-with-partial-json)
26
+ - [Validating Tool Arguments](#validating-tool-arguments)
27
+ - [Complete Event Reference](#complete-event-reference)
28
+ - [Image Input](#image-input)
29
+ - [Image Generation](#image-generation)
30
+ - [Thinking/Reasoning](#thinkingreasoning)
31
+ - [Unified Interface](#unified-interface-streamsimplecompletesimple)
32
+ - [Provider-Specific Options](#provider-specific-options-streamcomplete)
33
+ - [Streaming Thinking Content](#streaming-thinking-content)
34
+ - [Stop Reasons](#stop-reasons)
35
+ - [Error Handling](#error-handling)
36
+ - [Aborting Requests](#aborting-requests)
37
+ - [Continuing After Abort](#continuing-after-abort)
38
+ - [Debugging Provider Payloads](#debugging-provider-payloads)
39
+ - [Custom Providers](#custom-providers)
40
+ - [createProvider()](#createprovider)
41
+ - [Calling API Implementations Directly](#calling-api-implementations-directly)
42
+ - [OpenAI Compatibility Settings](#openai-compatibility-settings)
43
+ - [Faux Provider for Tests](#faux-provider-for-tests)
44
+ - [Cross-Provider Handoffs](#cross-provider-handoffs)
45
+ - [Context Serialization](#context-serialization)
46
+ - [Browser Usage](#browser-usage)
47
+ - [Bundling and Tree Shaking](#bundling-and-tree-shaking)
48
+ - [OAuth Providers](#oauth-providers)
49
+ - [Vertex AI](#vertex-ai)
50
+ - [CLI Login](#cli-login)
51
+ - [Programmatic OAuth](#programmatic-oauth)
52
+ - [Migrating from the Old Global API](#migrating-from-the-old-global-api)
53
+ - [Development](#development)
54
+ - [License](#license)
55
+
56
+ ## Supported Providers
57
+
58
+ - **OpenAI**
59
+ - **Ant Ling**
60
+ - **Azure OpenAI (Responses)**
61
+ - **OpenAI Codex** (ChatGPT Plus/Pro subscription, requires OAuth, see below)
62
+ - **DeepSeek**
63
+ - **NVIDIA NIM**
64
+ - **Anthropic**
65
+ - **Google**
66
+ - **Vertex AI** (Gemini via Vertex AI)
67
+ - **Mistral**
68
+ - **Groq**
69
+ - **Cerebras**
70
+ - **Cloudflare AI Gateway**
71
+ - **Cloudflare Workers AI**
72
+ - **xAI**
73
+ - **OpenRouter**
74
+ - **Vercel AI Gateway**
75
+ - **ZAI Coding Plan (Global)** (with separate China provider)
76
+ - **MiniMax** (with separate China provider)
77
+ - **Together AI**
78
+ - **Hugging Face**
79
+ - **Moonshot AI** (with separate China provider)
80
+ - **GitHub Copilot** (requires OAuth, see below)
81
+ - **Amazon Bedrock**
82
+ - **OpenCode Zen**
83
+ - **OpenCode Go**
84
+ - **Fireworks** (uses OpenAI- and Anthropic-compatible APIs)
85
+ - **Kimi For Coding** (Moonshot AI subscription endpoint, uses Anthropic-compatible API)
86
+ - **Xiaomi MiMo** (defaults to API billing endpoint, with separate Token Plan providers for `cn`/`ams`/`sgp` regions)
87
+ - **Any OpenAI-compatible API**: Ollama, vLLM, LM Studio, etc.
88
+
89
+ ## Installation
90
+
91
+ ```bash
92
+ npm install @earendil-works/pi-ai
93
+ ```
94
+
95
+ TypeBox exports are re-exported from `@earendil-works/pi-ai`: `Type`, `Static`, and `TSchema`.
96
+
97
+ ## Quick Start
98
+
99
+ You build a `Models` collection of providers and stream through it. The quickest start registers every built-in provider; apps that care about bundle size register individual providers instead (see [Provider Factories](#provider-factories) and [Bundling and Tree Shaking](#bundling-and-tree-shaking)).
100
+
101
+ ```typescript
102
+ import { Type, type Context, type Tool } from '@earendil-works/pi-ai';
103
+ import { builtinModels } from '@earendil-works/pi-ai/providers/all';
104
+
105
+ // A Models collection with every built-in provider registered
106
+ const models = builtinModels();
107
+
108
+ // Sync lookup against the collection
109
+ const model = models.getModel('openai', 'gpt-4o-mini')!;
110
+
111
+ // Define tools with TypeBox schemas for type safety and validation
112
+ const tools: Tool[] = [{
113
+ name: 'get_time',
114
+ description: 'Get the current time',
115
+ parameters: Type.Object({
116
+ timezone: Type.Optional(Type.String({ description: 'Optional timezone (e.g., America/New_York)' }))
117
+ })
118
+ }];
119
+
120
+ // Build a conversation context (easily serializable and transferable between models)
121
+ const context: Context = {
122
+ systemPrompt: 'You are a helpful assistant.',
123
+ messages: [{ role: 'user', content: 'What time is it?', timestamp: Date.now() }],
124
+ tools
125
+ };
126
+
127
+ // Option 1: Streaming with all event types.
128
+ // Auth resolves through the provider (OPENAI_API_KEY from the environment here).
129
+ const s = models.stream(model, context);
130
+
131
+ for await (const event of s) {
132
+ switch (event.type) {
133
+ case 'start':
134
+ console.log(`Starting with ${event.partial.model}`);
135
+ break;
136
+ case 'text_start':
137
+ console.log('\n[Text started]');
138
+ break;
139
+ case 'text_delta':
140
+ process.stdout.write(event.delta);
141
+ break;
142
+ case 'text_end':
143
+ console.log('\n[Text ended]');
144
+ break;
145
+ case 'thinking_start':
146
+ console.log('[Model is thinking...]');
147
+ break;
148
+ case 'thinking_delta':
149
+ process.stdout.write(event.delta);
150
+ break;
151
+ case 'thinking_end':
152
+ console.log('[Thinking complete]');
153
+ break;
154
+ case 'toolcall_start':
155
+ console.log(`\n[Tool call started: index ${event.contentIndex}]`);
156
+ break;
157
+ case 'toolcall_delta':
158
+ // Partial tool arguments are being streamed
159
+ const partialCall = event.partial.content[event.contentIndex];
160
+ if (partialCall.type === 'toolCall') {
161
+ console.log(`[Streaming args for ${partialCall.name}]`);
162
+ }
163
+ break;
164
+ case 'toolcall_end':
165
+ console.log(`\nTool called: ${event.toolCall.name}`);
166
+ console.log(`Arguments: ${JSON.stringify(event.toolCall.arguments)}`);
167
+ break;
168
+ case 'done':
169
+ console.log(`\nFinished: ${event.reason}`);
170
+ break;
171
+ case 'error':
172
+ console.error(`Error: ${event.error.errorMessage}`);
173
+ break;
174
+ }
175
+ }
176
+
177
+ // Get the final message after streaming, add it to the context
178
+ const finalMessage = await s.result();
179
+ context.messages.push(finalMessage);
180
+
181
+ // Handle tool calls if any
182
+ const toolCalls = finalMessage.content.filter(b => b.type === 'toolCall');
183
+ for (const call of toolCalls) {
184
+ const result = call.name === 'get_time'
185
+ ? new Date().toLocaleString('en-US', {
186
+ timeZone: call.arguments.timezone || 'UTC',
187
+ dateStyle: 'full',
188
+ timeStyle: 'long'
189
+ })
190
+ : 'Unknown tool';
191
+
192
+ // Add tool result to context (supports text and images)
193
+ context.messages.push({
194
+ role: 'toolResult',
195
+ toolCallId: call.id,
196
+ toolName: call.name,
197
+ content: [{ type: 'text', text: result }],
198
+ isError: false,
199
+ timestamp: Date.now()
200
+ });
201
+ }
202
+
203
+ // Continue if there were tool calls
204
+ if (toolCalls.length > 0) {
205
+ const continuation = await models.complete(model, context);
206
+ context.messages.push(continuation);
207
+ console.log('After tool execution:', continuation.content);
208
+ }
209
+
210
+ console.log(`Total tokens: ${finalMessage.usage.input} in, ${finalMessage.usage.output} out`);
211
+ console.log(`Cost: $${finalMessage.usage.cost.total.toFixed(4)}`);
212
+
213
+ // Option 2: Get complete response without streaming
214
+ const response = await models.complete(model, context);
215
+
216
+ for (const block of response.content) {
217
+ if (block.type === 'text') {
218
+ console.log(block.text);
219
+ } else if (block.type === 'toolCall') {
220
+ console.log(`Tool: ${block.name}(${JSON.stringify(block.arguments)})`);
221
+ }
222
+ }
223
+ ```
224
+
225
+ Snippets in the rest of this README assume a `models` collection set up like this (with the relevant providers registered).
226
+
227
+ ## Providers and Models
228
+
229
+ A **provider** is the runtime unit: it owns its model catalog, its auth (API key resolution, OAuth flows), and its stream behavior. A `Models` collection holds providers and routes every request to the provider that owns the model.
230
+
231
+ Providers internally share **API implementations** (the wire protocols): Anthropic models use `anthropic-messages`, OpenAI uses `openai-responses`, while xAI, Groq, Cerebras, OpenRouter, and most others share `openai-completions`. Mixed-API providers (GitHub Copilot, OpenCode Zen) dispatch per model.
232
+
233
+ ### Provider Factories
234
+
235
+ For apps that only need specific providers, there is one factory per built-in provider, each a subpath import that pulls only that provider's catalog:
236
+
237
+ ```typescript
238
+ import { anthropicProvider } from '@earendil-works/pi-ai/providers/anthropic';
239
+ import { openaiProvider } from '@earendil-works/pi-ai/providers/openai';
240
+ import { openrouterProvider } from '@earendil-works/pi-ai/providers/openrouter';
241
+ import { amazonBedrockProvider } from '@earendil-works/pi-ai/providers/amazon-bedrock';
242
+ // ...one module per provider in the Supported Providers list
243
+
244
+ const models = createModels();
245
+ models.setProvider(anthropicProvider());
246
+ models.setProvider(openrouterProvider());
247
+ ```
248
+
249
+ Provider factories import their model catalog and a lazy API wrapper. They do not import other providers. With bundler code splitting, SDK implementations (`@anthropic-ai/sdk`, `openai`, `@google/genai`, etc.) stay in lazy chunks loaded on the first request to a model of that API.
250
+
251
+ ### All Built-in Providers
252
+
253
+ For apps that want everything (as in Quick Start):
254
+
255
+ ```typescript
256
+ import { builtinModels } from '@earendil-works/pi-ai/providers/all';
257
+
258
+ const models = builtinModels(); // a Models collection with every built-in provider registered
259
+ ```
260
+
261
+ This imports all catalogs and every built-in provider factory. It is the heavy, explicit entrypoint. `builtinModels()` accepts the same options as `createModels()` (`credentials`, `authContext`); `builtinProviders()` returns the provider array if you want to register them on your own collection.
262
+
263
+ ### Querying Models
264
+
265
+ Reads are synchronous and return the last-known lists:
266
+
267
+ ```typescript
268
+ const providers = models.getProviders(); // registered Provider objects
269
+ const provider = models.getProvider('anthropic'); // one provider
270
+
271
+ const all = models.getModels(); // every model across providers
272
+ const anthropicModels = models.getModels('anthropic');
273
+ const model = models.getModel('anthropic', 'claude-sonnet-4-5');
274
+
275
+ for (const m of anthropicModels) {
276
+ console.log(`${m.id}: ${m.name}`);
277
+ console.log(` API: ${m.api}`);
278
+ console.log(` Context: ${m.contextWindow} tokens`);
279
+ console.log(` Vision: ${m.input.includes('image')}`);
280
+ console.log(` Reasoning: ${m.reasoning}`);
281
+ }
282
+ ```
283
+
284
+ Dynamically listed models are typed `Model<Api>`. Narrow with the `hasApi()` guard when you need API-specific option typing:
285
+
286
+ ```typescript
287
+ import { hasApi } from '@earendil-works/pi-ai';
288
+
289
+ const m = models.getModel('anthropic', 'claude-sonnet-4-5');
290
+ if (m && hasApi(m, 'anthropic-messages')) {
291
+ // m: Model<'anthropic-messages'> — stream options fully typed
292
+ models.stream(m, context, { thinkingEnabled: true, thinkingBudgetTokens: 2048 });
293
+ }
294
+ ```
295
+
296
+ ### Static Catalog Reads
297
+
298
+ For tooling that wants the generated built-in catalog with full literal typing (provider and model IDs auto-complete), independent of any collection:
299
+
300
+ ```typescript
301
+ import { getBuiltinModel, getBuiltinModels, getBuiltinProviders } from '@earendil-works/pi-ai/providers/all';
302
+
303
+ const model = getBuiltinModel('openai', 'gpt-4o-mini'); // typed Model<'openai-responses'>
304
+ const providers = getBuiltinProviders();
305
+ const anthropic = getBuiltinModels('anthropic');
306
+ ```
307
+
308
+ ### Dynamic Providers
309
+
310
+ Providers may have dynamic model lists (a llama.cpp server, a live OpenRouter listing). Reads stay sync; fetching is an explicit async verb:
311
+
312
+ ```typescript
313
+ // getModels() returns the last-known list (empty before the first refresh)
314
+ await models.refresh('llamacpp'); // fetch one provider's list; rejects on failure
315
+ await models.refresh(); // refresh all providers concurrently, best-effort
316
+ const fresh = models.getModel('llamacpp', 'qwen3-30b');
317
+ ```
318
+
319
+ Static built-in providers are no-ops for `refresh()`. See [createProvider()](#createprovider) for building a dynamic provider.
320
+
321
+ ## Auth
322
+
323
+ Every provider owns its auth: how API keys resolve (stored credentials, environment variables, ambient sources like AWS profiles or gcloud ADC) and, where supported, OAuth login/refresh flows.
324
+
325
+ ### How Auth Resolves
326
+
327
+ When you call `models.stream()`, the collection resolves auth through the owning provider and merges it into the request. Explicit per-request values always win:
328
+
329
+ ```typescript
330
+ // Resolved through the provider (env var, stored credential, OAuth token):
331
+ await models.complete(model, context);
332
+
333
+ // Explicit key wins over anything the provider would resolve:
334
+ await models.complete(model, context, { apiKey: 'sk-explicit' });
335
+ ```
336
+
337
+ You can inspect resolution without making a request — useful for status UIs:
338
+
339
+ ```typescript
340
+ const auth = await models.getAuth(model);
341
+ if (auth) {
342
+ console.log(`configured via ${auth.source}`); // e.g. "ANTHROPIC_API_KEY", "OAuth", "stored credential"
343
+ } else {
344
+ console.log('not configured');
345
+ }
346
+ ```
347
+
348
+ `getAuth()` resolves `undefined` for unconfigured providers and rejects with `ModelsError` when something is actually broken (`"oauth"`: token refresh failed, credential preserved for re-login; `"auth"`: key resolution or credential store failure). Request paths surface the same failures as stream errors.
349
+
350
+ ### Credential Store
351
+
352
+ Stored credentials (API keys entered interactively, OAuth tokens) live in a `CredentialStore` — one type-tagged credential per provider. pi-ai ships an in-memory default; apps inject persistent storage:
353
+
354
+ ```typescript
355
+ import { createModels, type CredentialStore } from '@earendil-works/pi-ai';
356
+
357
+ const models = createModels({ credentials: myFileBackedStore });
358
+ // builtinModels() takes the same options:
359
+ // const models = builtinModels({ credentials: myFileBackedStore });
360
+ ```
361
+
362
+ The contract is small: `read(providerId)`, `modify(providerId, fn)` (the only write path — a serialized read-modify-write), and `delete(providerId)`. OAuth token refresh runs inside `modify`, so concurrent requests and processes cannot double-refresh a rotated token. A stored credential *owns* its provider: environment variables are only consulted when nothing is stored, and a failed refresh never silently falls back to an env key.
363
+
364
+ API-key credentials use the same discriminator as pi's `auth.json` and can carry provider-scoped env/config values:
365
+
366
+ ```typescript
367
+ const credential = {
368
+ type: 'api_key',
369
+ key: '...',
370
+ env: {
371
+ CLOUDFLARE_ACCOUNT_ID: 'account-id',
372
+ CLOUDFLARE_GATEWAY_ID: 'gateway-id'
373
+ }
374
+ } as const;
375
+ ```
376
+
377
+ ### Environment Variables
378
+
379
+ Built-in providers resolve these env vars (Node.js; in browsers pass `apiKey` explicitly):
380
+
381
+ | Provider | Environment Variable(s) |
382
+ |----------|------------------------|
383
+ | OpenAI | `OPENAI_API_KEY` |
384
+ | Ant Ling | `ANT_LING_API_KEY` |
385
+ | Azure OpenAI | `AZURE_OPENAI_API_KEY` + `AZURE_OPENAI_BASE_URL` (e.g. `https://{resource}.ai.azure.com`) or `AZURE_OPENAI_RESOURCE_NAME`. Supports `*.openai.azure.com`, `*.cognitiveservices.azure.com` and `*.ai.azure.com`; root endpoints auto-normalize to `/openai/v1`. Optional: `AZURE_OPENAI_API_VERSION` (default `v1`), `AZURE_OPENAI_DEPLOYMENT_NAME_MAP`. |
386
+ | Anthropic | `ANTHROPIC_API_KEY` or `ANTHROPIC_OAUTH_TOKEN` |
387
+ | DeepSeek | `DEEPSEEK_API_KEY` |
388
+ | NVIDIA NIM | `NVIDIA_API_KEY` |
389
+ | Google | `GEMINI_API_KEY` |
390
+ | Vertex AI | `GOOGLE_CLOUD_API_KEY` or `GOOGLE_CLOUD_PROJECT` (or `GCLOUD_PROJECT`) + `GOOGLE_CLOUD_LOCATION` + ADC |
391
+ | Mistral | `MISTRAL_API_KEY` |
392
+ | Groq | `GROQ_API_KEY` |
393
+ | Cerebras | `CEREBRAS_API_KEY` |
394
+ | Cloudflare AI Gateway | `CLOUDFLARE_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_GATEWAY_ID` |
395
+ | Cloudflare Workers AI | `CLOUDFLARE_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` |
396
+ | xAI | `XAI_API_KEY` |
397
+ | Fireworks | `FIREWORKS_API_KEY` |
398
+ | Together AI | `TOGETHER_API_KEY` |
399
+ | OpenRouter | `OPENROUTER_API_KEY` |
400
+ | Vercel AI Gateway | `AI_GATEWAY_API_KEY` |
401
+ | ZAI Coding Plan (Global) | `ZAI_API_KEY` |
402
+ | ZAI Coding Plan (China) | `ZAI_CODING_CN_API_KEY` |
403
+ | MiniMax (Global) | `MINIMAX_API_KEY` |
404
+ | MiniMax (China) | `MINIMAX_CN_API_KEY` |
405
+ | Moonshot AI / Moonshot AI (China) | `MOONSHOT_API_KEY` |
406
+ | Hugging Face | `HF_TOKEN` |
407
+ | OpenCode Zen / OpenCode Go | `OPENCODE_API_KEY` |
408
+ | Kimi For Coding | `KIMI_API_KEY` |
409
+ | Xiaomi MiMo (API billing) | `XIAOMI_API_KEY` |
410
+ | Xiaomi MiMo Token Plan (China) | `XIAOMI_TOKEN_PLAN_CN_API_KEY` |
411
+ | Xiaomi MiMo Token Plan (Amsterdam) | `XIAOMI_TOKEN_PLAN_AMS_API_KEY` |
412
+ | Xiaomi MiMo Token Plan (Singapore) | `XIAOMI_TOKEN_PLAN_SGP_API_KEY` |
413
+ | GitHub Copilot | `COPILOT_GITHUB_TOKEN` |
414
+
415
+ Amazon Bedrock resolves ambient AWS credentials (`AWS_PROFILE`, access key pairs, `AWS_BEARER_TOKEN_BEDROCK`, ECS task roles, web identity tokens). Vertex AI resolves either an explicit key or gcloud Application Default Credentials plus project/location.
416
+
417
+ ## Tools
418
+
419
+ Tools enable LLMs to interact with external systems. This library uses TypeBox schemas for type-safe tool definitions with automatic validation using TypeBox's built-in validator and value conversion utilities. TypeBox schemas can be serialized and deserialized as plain JSON, making them ideal for distributed systems.
420
+
421
+ ### Defining Tools
422
+
423
+ ```typescript
424
+ import { Type, type Tool, StringEnum } from '@earendil-works/pi-ai';
425
+
426
+ // Define tool parameters with TypeBox
427
+ const weatherTool: Tool = {
428
+ name: 'get_weather',
429
+ description: 'Get current weather for a location',
430
+ parameters: Type.Object({
431
+ location: Type.String({ description: 'City name or coordinates' }),
432
+ units: StringEnum(['celsius', 'fahrenheit'], { default: 'celsius' })
433
+ })
434
+ };
435
+
436
+ // Note: For Google API compatibility, use StringEnum helper instead of Type.Enum
437
+ // Type.Enum generates anyOf/const patterns that Google doesn't support
438
+
439
+ const bookMeetingTool: Tool = {
440
+ name: 'book_meeting',
441
+ description: 'Schedule a meeting',
442
+ parameters: Type.Object({
443
+ title: Type.String({ minLength: 1 }),
444
+ startTime: Type.String({ format: 'date-time' }),
445
+ endTime: Type.String({ format: 'date-time' }),
446
+ attendees: Type.Array(Type.String({ format: 'email' }), { minItems: 1 })
447
+ })
448
+ };
449
+ ```
450
+
451
+ ### Handling Tool Calls
452
+
453
+ Tool results use content blocks and can include both text and images:
454
+
455
+ ```typescript
456
+ import { readFileSync } from 'fs';
457
+
458
+ const context: Context = {
459
+ messages: [{ role: 'user', content: 'What is the weather in London?', timestamp: Date.now() }],
460
+ tools: [weatherTool]
461
+ };
462
+
463
+ const response = await models.complete(model, context);
464
+
465
+ // Check for tool calls in the response
466
+ for (const block of response.content) {
467
+ if (block.type === 'toolCall') {
468
+ // Execute your tool with the arguments
469
+ // See "Validating Tool Arguments" section for validation
470
+ const result = await executeWeatherApi(block.arguments);
471
+
472
+ // Add tool result with text content
473
+ context.messages.push({
474
+ role: 'toolResult',
475
+ toolCallId: block.id,
476
+ toolName: block.name,
477
+ content: [{ type: 'text', text: JSON.stringify(result) }],
478
+ isError: false,
479
+ timestamp: Date.now()
480
+ });
481
+ }
482
+ }
483
+
484
+ // Tool results can also include images (for vision-capable models)
485
+ const imageBuffer = readFileSync('chart.png');
486
+ context.messages.push({
487
+ role: 'toolResult',
488
+ toolCallId: 'tool_xyz',
489
+ toolName: 'generate_chart',
490
+ content: [
491
+ { type: 'text', text: 'Generated chart showing temperature trends' },
492
+ { type: 'image', data: imageBuffer.toString('base64'), mimeType: 'image/png' }
493
+ ],
494
+ isError: false,
495
+ timestamp: Date.now()
496
+ });
497
+ ```
498
+
499
+ ### Streaming Tool Calls with Partial JSON
500
+
501
+ During streaming, tool call arguments are progressively parsed as they arrive. This enables real-time UI updates before the complete arguments are available:
502
+
503
+ ```typescript
504
+ const s = models.stream(model, context);
505
+
506
+ for await (const event of s) {
507
+ if (event.type === 'toolcall_delta') {
508
+ const toolCall = event.partial.content[event.contentIndex];
509
+
510
+ // toolCall.arguments contains partially parsed JSON during streaming
511
+ // This allows for progressive UI updates
512
+ if (toolCall.type === 'toolCall' && toolCall.arguments) {
513
+ // BE DEFENSIVE: arguments may be incomplete
514
+ // Example: Show file path being written even before content is complete
515
+ if (toolCall.name === 'write_file' && toolCall.arguments.path) {
516
+ console.log(`Writing to: ${toolCall.arguments.path}`);
517
+
518
+ // Content might be partial or missing
519
+ if (toolCall.arguments.content) {
520
+ console.log(`Content preview: ${toolCall.arguments.content.substring(0, 100)}...`);
521
+ }
522
+ }
523
+ }
524
+ }
525
+
526
+ if (event.type === 'toolcall_end') {
527
+ // Here toolCall.arguments is complete (but not yet validated)
528
+ const toolCall = event.toolCall;
529
+ console.log(`Tool completed: ${toolCall.name}`, toolCall.arguments);
530
+ }
531
+ }
532
+ ```
533
+
534
+ **Important notes about partial tool arguments:**
535
+ - During `toolcall_delta` events, `arguments` contains the best-effort parse of partial JSON
536
+ - Fields may be missing or incomplete - always check for existence before use
537
+ - String values may be truncated mid-word
538
+ - Arrays may be incomplete
539
+ - Nested objects may be partially populated
540
+ - At minimum, `arguments` will be an empty object `{}`, never `undefined`
541
+ - The Google provider does not support function call streaming. Instead, you will receive a single `toolcall_delta` event with the full arguments.
542
+
543
+ ### Validating Tool Arguments
544
+
545
+ When implementing your own tool execution loop, use `validateToolCall` to validate arguments before passing them to your tools:
546
+
547
+ ```typescript
548
+ import { validateToolCall, type Tool } from '@earendil-works/pi-ai';
549
+
550
+ const tools: Tool[] = [weatherTool, calculatorTool];
551
+ const s = models.stream(model, { messages, tools });
552
+
553
+ for await (const event of s) {
554
+ if (event.type === 'toolcall_end') {
555
+ const toolCall = event.toolCall;
556
+
557
+ try {
558
+ // Validate arguments against the tool's schema (throws on invalid args)
559
+ const validatedArgs = validateToolCall(tools, toolCall);
560
+ const result = await executeMyTool(toolCall.name, validatedArgs);
561
+ // ... add tool result to context
562
+ } catch (error) {
563
+ // Validation failed - return error as tool result so model can retry
564
+ context.messages.push({
565
+ role: 'toolResult',
566
+ toolCallId: toolCall.id,
567
+ toolName: toolCall.name,
568
+ content: [{ type: 'text', text: error.message }],
569
+ isError: true,
570
+ timestamp: Date.now()
571
+ });
572
+ }
573
+ }
574
+ }
575
+ ```
576
+
577
+ ### Complete Event Reference
578
+
579
+ All streaming events emitted during assistant message generation:
580
+
581
+ | Event Type | Description | Key Properties |
582
+ |------------|-------------|----------------|
583
+ | `start` | Stream begins | `partial`: Initial assistant message structure |
584
+ | `text_start` | Text block starts | `contentIndex`: Position in content array |
585
+ | `text_delta` | Text chunk received | `delta`: New text, `contentIndex`: Position |
586
+ | `text_end` | Text block complete | `content`: Full text, `contentIndex`: Position |
587
+ | `thinking_start` | Thinking block starts | `contentIndex`: Position in content array |
588
+ | `thinking_delta` | Thinking chunk received | `delta`: New text, `contentIndex`: Position |
589
+ | `thinking_end` | Thinking block complete | `content`: Full thinking, `contentIndex`: Position |
590
+ | `toolcall_start` | Tool call begins | `contentIndex`: Position in content array |
591
+ | `toolcall_delta` | Tool arguments streaming | `delta`: JSON chunk, `partial.content[contentIndex].arguments`: Partial parsed args |
592
+ | `toolcall_end` | Tool call complete | `toolCall`: Complete validated tool call with `id`, `name`, `arguments` |
593
+ | `done` | Stream complete | `reason`: Stop reason ("stop", "length", "toolUse"), `message`: Final assistant message |
594
+ | `error` | Error occurred | `reason`: Error type ("error" or "aborted"), `error`: AssistantMessage with partial content |
595
+
596
+ Streaming events for different content blocks are not guaranteed to be contiguous. Providers may emit deltas for text, thinking, and tool calls in the same upstream chunk, and pi may surface corresponding events interleaved, for example `text_start`, `text_delta`, `toolcall_start`, `text_delta`, `toolcall_delta`. Consumers must use `contentIndex` to associate each delta/end event with its block and must not assume that a block's `*_start`/`*_delta`/`*_end` sequence is uninterrupted by events for other blocks.
597
+
598
+ ## Image Input
599
+
600
+ Models with vision capabilities can process images. You can check if a model supports images via the `input` property. If you pass images to a non-vision model, they are silently ignored.
601
+
602
+ ```typescript
603
+ import { readFileSync } from 'fs';
604
+
605
+ const model = models.getModel('openai', 'gpt-4o-mini')!;
606
+
607
+ // Check if model supports images
608
+ if (model.input.includes('image')) {
609
+ console.log('Model supports vision');
610
+ }
611
+
612
+ const imageBuffer = readFileSync('image.png');
613
+ const base64Image = imageBuffer.toString('base64');
614
+
615
+ const response = await models.complete(model, {
616
+ messages: [{
617
+ role: 'user',
618
+ content: [
619
+ { type: 'text', text: 'What is in this image?' },
620
+ { type: 'image', data: base64Image, mimeType: 'image/png' }
621
+ ],
622
+ timestamp: Date.now()
623
+ }]
624
+ });
625
+
626
+ // Access the response
627
+ for (const block of response.content) {
628
+ if (block.type === 'text') {
629
+ console.log(block.text);
630
+ }
631
+ }
632
+ ```
633
+
634
+ ## Image Generation
635
+
636
+ Image generation uses a separate API surface from text/chat generation, mirroring the chat-side design: an `ImagesModels` collection holds `ImagesProvider`s, reads are sync, and auth resolves through the owning provider. Image generation is a one-shot API: `generateImages()` waits for the provider response and returns the final `AssistantImages` result — do not use the chat/stream APIs for it.
637
+
638
+ ### Basic Image Generation
639
+
640
+ ```typescript
641
+ import { builtinImagesModels } from '@earendil-works/pi-ai/providers/all';
642
+
643
+ // Every built-in image-generation provider; accepts the same options as createModels()
644
+ const imagesModels = builtinImagesModels();
645
+
646
+ const model = imagesModels.getModel('openrouter', 'google/gemini-2.5-flash-image')!;
647
+
648
+ // Auth resolves through the provider (OPENROUTER_API_KEY here); explicit apiKey wins
649
+ const result = await imagesModels.generateImages(model, {
650
+ input: [{ type: 'text', text: 'Generate a red circle on a plain white background.' }]
651
+ });
652
+
653
+ for (const block of result.output) {
654
+ if (block.type === 'text') {
655
+ console.log(block.text);
656
+ } else if (block.type === 'image') {
657
+ console.log(block.mimeType);
658
+ console.log(block.data.substring(0, 32));
659
+ }
660
+ }
661
+ ```
662
+
663
+ Like the chat side, you can build the collection from parts: `createImagesModels({ credentials?, authContext? })`, the `openrouterImagesProvider()` factory from `@earendil-works/pi-ai/providers/openrouter-images`, and `createImagesProvider({ id, auth, models, refreshModels?, api })` for custom image providers (with `imagesModels.refresh(provider?)` for dynamic lists). Failures never reject — they return an `AssistantImages` with `stopReason: "error"`. The collection's `getAuth(model)` works exactly like the chat-side one.
664
+
665
+ The old global API (`getImageModel()` / `getImageModels()` / `getImageProviders()` / `generateImages()`) remains available on the [compat entrypoint](#migrating-from-the-old-global-api):
666
+
667
+ ```typescript
668
+ import { getImageModel, generateImages } from '@earendil-works/pi-ai/compat';
669
+
670
+ const model = getImageModel('openrouter', 'google/gemini-2.5-flash-image');
671
+ const result = await generateImages(model, {
672
+ input: [{ type: 'text', text: 'Generate a red circle on a plain white background.' }]
673
+ }, {
674
+ apiKey: process.env.OPENROUTER_API_KEY
675
+ });
676
+ ```
677
+
678
+ Some models also support image input:
679
+
680
+ ```typescript
681
+ import { readFileSync } from 'fs';
682
+
683
+ const imageBuffer = readFileSync('input.png');
684
+ const result = await imagesModels.generateImages(model, {
685
+ input: [
686
+ { type: 'text', text: 'Create a variation of this image with a blue background.' },
687
+ { type: 'image', data: imageBuffer.toString('base64'), mimeType: 'image/png' }
688
+ ]
689
+ });
690
+ ```
691
+
692
+ Check capabilities on the model metadata:
693
+
694
+ ```typescript
695
+ console.log(model.input); // ['text', 'image']
696
+ console.log(model.output); // ['image'] or ['image', 'text']
697
+ ```
698
+
699
+ ### Notes and Limitations
700
+
701
+ - Image models live in `ImagesModels` collections, chat models in `Models` collections; the two are separate surfaces.
702
+ - Use `generateImages()`, not the chat/stream APIs.
703
+ - Image-generation models do not participate in tool calling.
704
+ - Outputs are returned in `AssistantImages.output` and can include both base64-encoded `ImageContent` blocks and `TextContent` blocks.
705
+ - Some models return only images, others return images plus text. Check `model.output`.
706
+ - Some models accept image input, others are text-to-image only. Check `model.input`.
707
+ - Like the streaming APIs, image generation supports options such as `apiKey`, `signal`, `headers`, `onPayload`, and `onResponse`, and results may include `stopReason`, `responseId`, and `usage`.
708
+ - If you want a model to analyze images in a conversation or call tools, use the regular chat APIs with a model that supports image input.
709
+ - At the moment, image generation is available through only one provider, OpenRouter.
710
+
711
+ ## Thinking/Reasoning
712
+
713
+ Many models support thinking/reasoning capabilities where they can show their internal thought process. You can check if a model supports reasoning via the `reasoning` property. If you pass reasoning options to a non-reasoning model, they are silently ignored.
714
+
715
+ ### Unified Interface (streamSimple/completeSimple)
716
+
717
+ ```typescript
718
+ // Many models across providers support thinking/reasoning
719
+ const model = models.getModel('anthropic', 'claude-sonnet-4-5')!;
720
+ // or models.getModel('openai', 'gpt-5-mini');
721
+ // or models.getModel('google', 'gemini-2.5-flash');
722
+ // or models.getModel('xai', 'grok-code-fast-1');
723
+
724
+ // Check if model supports reasoning
725
+ if (model.reasoning) {
726
+ console.log('Model supports reasoning/thinking');
727
+ }
728
+
729
+ // Use the simplified reasoning option
730
+ const response = await models.completeSimple(model, {
731
+ messages: [{ role: 'user', content: 'Solve: 2x + 5 = 13', timestamp: Date.now() }]
732
+ }, {
733
+ reasoning: 'medium' // 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'
734
+ });
735
+
736
+ // Access thinking and text blocks
737
+ for (const block of response.content) {
738
+ if (block.type === 'thinking') {
739
+ console.log('Thinking:', block.thinking);
740
+ } else if (block.type === 'text') {
741
+ console.log('Response:', block.text);
742
+ }
743
+ }
744
+ ```
745
+
746
+ ### Provider-Specific Options (stream/complete)
747
+
748
+ `models.stream()`/`complete()` accept the owning API's full option set. Use `hasApi()` to narrow a dynamically looked-up model to its API for full option typing:
749
+
750
+ ```typescript
751
+ import { hasApi } from '@earendil-works/pi-ai';
752
+
753
+ // OpenAI Reasoning (o1, o3, gpt-5)
754
+ const openaiModel = models.getModel('openai', 'gpt-5-mini')!;
755
+ if (hasApi(openaiModel, 'openai-responses')) {
756
+ await models.complete(openaiModel, context, {
757
+ reasoningEffort: 'medium',
758
+ reasoningSummary: 'detailed' // OpenAI Responses API only
759
+ });
760
+ }
761
+
762
+ // Anthropic Thinking
763
+ const anthropicModel = models.getModel('anthropic', 'claude-sonnet-4-5')!;
764
+ if (hasApi(anthropicModel, 'anthropic-messages')) {
765
+ await models.complete(anthropicModel, context, {
766
+ thinkingEnabled: true,
767
+ thinkingBudgetTokens: 8192 // Optional token limit
768
+ });
769
+ }
770
+
771
+ // Google Gemini Thinking
772
+ const googleModel = models.getModel('google', 'gemini-2.5-flash')!;
773
+ if (hasApi(googleModel, 'google-generative-ai')) {
774
+ await models.complete(googleModel, context, {
775
+ thinking: {
776
+ enabled: true,
777
+ budgetTokens: 8192 // -1 for dynamic, 0 to disable
778
+ }
779
+ });
780
+ }
781
+ ```
782
+
783
+ ### Streaming Thinking Content
784
+
785
+ When streaming, thinking content is delivered through specific events:
786
+
787
+ ```typescript
788
+ const s = models.streamSimple(model, context, { reasoning: 'high' });
789
+
790
+ for await (const event of s) {
791
+ switch (event.type) {
792
+ case 'thinking_start':
793
+ console.log('[Model started thinking]');
794
+ break;
795
+ case 'thinking_delta':
796
+ process.stdout.write(event.delta); // Stream thinking content
797
+ break;
798
+ case 'thinking_end':
799
+ console.log('\n[Thinking complete]');
800
+ break;
801
+ }
802
+ }
803
+ ```
804
+
805
+ ## Stop Reasons
806
+
807
+ Every `AssistantMessage` includes a `stopReason` field that indicates how the generation ended:
808
+
809
+ - `"stop"` - Normal completion, the model finished its response
810
+ - `"length"` - Output hit the maximum token limit
811
+ - `"toolUse"` - Model is calling tools and expects tool results
812
+ - `"error"` - An error occurred during generation
813
+ - `"aborted"` - Request was cancelled via abort signal
814
+
815
+ `AssistantMessage` may also include `responseId`, a provider-specific upstream response or message identifier when the underlying API exposes one. Do not assume it is always present across providers.
816
+
817
+ ## Error Handling
818
+
819
+ Request failures never throw out of the stream functions: when a request ends with an error (including aborts and tool call validation errors), the streaming API emits an error event and the final message carries the details:
820
+
821
+ ```typescript
822
+ // In streaming
823
+ for await (const event of s) {
824
+ if (event.type === 'error') {
825
+ // event.reason is either "error" or "aborted"
826
+ // event.error is the AssistantMessage with partial content
827
+ console.error(`Error (${event.reason}):`, event.error.errorMessage);
828
+ console.log('Partial content:', event.error.content);
829
+ }
830
+ }
831
+
832
+ // The final message will have the error details
833
+ const message = await s.result();
834
+ if (message.stopReason === 'error' || message.stopReason === 'aborted') {
835
+ console.error('Request failed:', message.errorMessage);
836
+ // message.content contains any partial content received before the error
837
+ // message.usage contains partial token counts and costs
838
+ }
839
+ ```
840
+
841
+ Auth failures (no key configured, OAuth refresh failed, unknown provider) surface the same way: as a stream error with `stopReason: "error"`.
842
+
843
+ ### Aborting Requests
844
+
845
+ The abort signal allows you to cancel in-progress requests. Aborted requests have `stopReason === 'aborted'`:
846
+
847
+ ```typescript
848
+ const controller = new AbortController();
849
+
850
+ // Abort after 2 seconds
851
+ setTimeout(() => controller.abort(), 2000);
852
+
853
+ const s = models.stream(model, {
854
+ messages: [{ role: 'user', content: 'Write a long story', timestamp: Date.now() }]
855
+ }, {
856
+ signal: controller.signal
857
+ });
858
+
859
+ for await (const event of s) {
860
+ if (event.type === 'text_delta') {
861
+ process.stdout.write(event.delta);
862
+ } else if (event.type === 'error') {
863
+ // event.reason tells you if it was "error" or "aborted"
864
+ console.log(`${event.reason === 'aborted' ? 'Aborted' : 'Error'}:`, event.error.errorMessage);
865
+ }
866
+ }
867
+
868
+ // Get results (may be partial if aborted)
869
+ const response = await s.result();
870
+ if (response.stopReason === 'aborted') {
871
+ console.log('Request was aborted:', response.errorMessage);
872
+ console.log('Partial content received:', response.content);
873
+ console.log('Tokens used:', response.usage);
874
+ }
875
+ ```
876
+
877
+ ### Continuing After Abort
878
+
879
+ Aborted messages can be added to the conversation context and continued in subsequent requests:
880
+
881
+ ```typescript
882
+ const context = {
883
+ messages: [
884
+ { role: 'user', content: 'Explain quantum computing in detail', timestamp: Date.now() }
885
+ ]
886
+ };
887
+
888
+ // First request gets aborted after 2 seconds
889
+ const controller1 = new AbortController();
890
+ setTimeout(() => controller1.abort(), 2000);
891
+
892
+ const partial = await models.complete(model, context, { signal: controller1.signal });
893
+
894
+ // Add the partial response to context
895
+ context.messages.push(partial);
896
+ context.messages.push({ role: 'user', content: 'Please continue', timestamp: Date.now() });
897
+
898
+ // Continue the conversation
899
+ const continuation = await models.complete(model, context);
900
+ ```
901
+
902
+ ### Debugging Provider Payloads
903
+
904
+ Use the `onPayload` callback to inspect the request payload sent to the provider. This is useful for debugging request formatting issues or provider validation errors.
905
+
906
+ ```typescript
907
+ const response = await models.complete(model, context, {
908
+ onPayload: (payload) => {
909
+ console.log('Provider payload:', JSON.stringify(payload, null, 2));
910
+ }
911
+ });
912
+ ```
913
+
914
+ The callback is supported by `stream`, `complete`, `streamSimple`, and `completeSimple`.
915
+
916
+ ## Custom Providers
917
+
918
+ ### createProvider()
919
+
920
+ `createProvider()` builds a provider from parts: identity, auth, a model list, and an API implementation. Use it for local inference servers, proxies, or any OpenAI/Anthropic-compatible endpoint:
921
+
922
+ ```typescript
923
+ import { createModels, createProvider, envApiKeyAuth, type Model } from '@earendil-works/pi-ai';
924
+ import { openAICompletionsApi } from '@earendil-works/pi-ai/api/openai-completions.lazy';
925
+
926
+ const ollamaModel: Model<'openai-completions'> = {
927
+ id: 'llama-3.1-8b',
928
+ name: 'Llama 3.1 8B (Ollama)',
929
+ api: 'openai-completions',
930
+ provider: 'ollama',
931
+ baseUrl: 'http://localhost:11434/v1',
932
+ reasoning: false,
933
+ input: ['text'],
934
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
935
+ contextWindow: 128000,
936
+ maxTokens: 32000
937
+ };
938
+
939
+ const ollama = createProvider({
940
+ id: 'ollama',
941
+ name: 'Ollama',
942
+ baseUrl: 'http://localhost:11434/v1',
943
+ // Every provider declares auth; keyless local servers resolve as configured with no key.
944
+ auth: { apiKey: { name: 'Ollama', resolve: async () => ({ auth: {} }) } },
945
+ models: [ollamaModel],
946
+ api: openAICompletionsApi(),
947
+ });
948
+
949
+ const models = createModels();
950
+ models.setProvider(ollama);
951
+
952
+ await models.complete(models.getModel('ollama', 'llama-3.1-8b')!, context);
953
+ ```
954
+
955
+ For providers with real keys, `envApiKeyAuth(displayName, envVars)` gives the standard behavior (stored credential wins, then the first set env var):
956
+
957
+ ```typescript
958
+ const proxy = createProvider({
959
+ id: 'my-proxy',
960
+ auth: { apiKey: envApiKeyAuth('My proxy API key', ['MY_PROXY_API_KEY']) },
961
+ models: [/* ... */],
962
+ api: openAICompletionsApi(),
963
+ });
964
+ ```
965
+
966
+ Mixed-API providers pass a map keyed by `model.api`; each model dispatches to its API's implementation:
967
+
968
+ ```typescript
969
+ import { anthropicMessagesApi } from '@earendil-works/pi-ai/api/anthropic-messages.lazy';
970
+ import { openAIResponsesApi } from '@earendil-works/pi-ai/api/openai-responses.lazy';
971
+
972
+ const gateway = createProvider({
973
+ id: 'my-gateway',
974
+ auth: { apiKey: envApiKeyAuth('Gateway key', ['GATEWAY_API_KEY']) },
975
+ models: [/* models with api: 'anthropic-messages' or 'openai-responses' */],
976
+ api: {
977
+ 'anthropic-messages': anthropicMessagesApi(),
978
+ 'openai-responses': openAIResponsesApi(),
979
+ },
980
+ });
981
+ ```
982
+
983
+ Dynamic model lists use `refreshModels`; the provider lists empty until the first `models.refresh()`:
984
+
985
+ ```typescript
986
+ const llamacpp = createProvider({
987
+ id: 'llamacpp',
988
+ auth: { apiKey: { name: 'llama.cpp', resolve: async () => ({ auth: {} }) } },
989
+ models: [],
990
+ refreshModels: async () => fetchModelsFromServer('http://localhost:8080'),
991
+ api: openAICompletionsApi(),
992
+ });
993
+
994
+ models.setProvider(llamacpp);
995
+ await models.refresh('llamacpp');
996
+ ```
997
+
998
+ Custom models can carry `headers` (e.g. proxies behind bot detection) and `compat` flags — see [OpenAI Compatibility Settings](#openai-compatibility-settings).
999
+
1000
+ Some OpenAI-compatible servers do not understand the `developer` role used for reasoning-capable models. For those providers, set `compat.supportsDeveloperRole` to `false` so the system prompt is sent as a `system` message instead. If the server also does not support `reasoning_effort`, set `compat.supportsReasoningEffort` to `false` too. This commonly applies to Ollama, vLLM, SGLang, and similar OpenAI-compatible servers.
1001
+
1002
+ Use model-level `thinkingLevelMap` to describe model-specific thinking controls. Keys are pi thinking levels (`off`, `minimal`, `low`, `medium`, `high`, `xhigh`). Missing keys use provider defaults, string values are sent to the provider, and `null` marks a level unsupported.
1003
+
1004
+ ```typescript
1005
+ const ollamaReasoningModel: Model<'openai-completions'> = {
1006
+ id: 'gpt-oss:20b',
1007
+ name: 'GPT-OSS 20B (Ollama)',
1008
+ api: 'openai-completions',
1009
+ provider: 'ollama',
1010
+ baseUrl: 'http://localhost:11434/v1',
1011
+ reasoning: true,
1012
+ input: ['text'],
1013
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
1014
+ contextWindow: 131072,
1015
+ maxTokens: 32000,
1016
+ thinkingLevelMap: {
1017
+ minimal: null,
1018
+ low: null,
1019
+ medium: null,
1020
+ high: 'high',
1021
+ xhigh: null,
1022
+ },
1023
+ compat: {
1024
+ supportsDeveloperRole: false,
1025
+ supportsReasoningEffort: false,
1026
+ }
1027
+ };
1028
+ ```
1029
+
1030
+ ### Calling API Implementations Directly
1031
+
1032
+ The API implementations are importable on their own. Each module exports exactly `stream` and `streamSimple` with that API's full option typing. Direct calls bypass provider auth — pass `apiKey` explicitly:
1033
+
1034
+ ```typescript
1035
+ import { stream } from '@earendil-works/pi-ai/api/anthropic-messages';
1036
+
1037
+ const s = stream(claudeModel, context, {
1038
+ apiKey: process.env.ANTHROPIC_API_KEY,
1039
+ thinkingEnabled: true,
1040
+ thinkingBudgetTokens: 2048,
1041
+ });
1042
+ ```
1043
+
1044
+ Built-in API implementations live under `./api/<api-id>`:
1045
+
1046
+ | API id | Options type |
1047
+ |--------|--------------|
1048
+ | `anthropic-messages` | `AnthropicOptions` |
1049
+ | `openai-completions` | `OpenAICompletionsOptions` |
1050
+ | `openai-responses` | `OpenAIResponsesOptions` |
1051
+ | `openai-codex-responses` | `OpenAICodexResponsesOptions` |
1052
+ | `azure-openai-responses` | `AzureOpenAIResponsesOptions` |
1053
+ | `google-generative-ai` | `GoogleOptions` |
1054
+ | `google-vertex` | `GoogleVertexOptions` |
1055
+ | `mistral-conversations` | `MistralOptions` |
1056
+ | `bedrock-converse-stream` | `BedrockOptions` |
1057
+
1058
+ Importing an implementation module loads its SDK. The `./api/<id>.lazy` wrappers (used by the provider factories) defer that load to the first request when the runtime or bundler supports dynamic import chunking. Legacy raw API subpaths from older releases (`./anthropic`, `./google`, `./mistral`, `./openai-completions`, ...) were removed; use `@earendil-works/pi-ai/api/<api-id>`.
1059
+
1060
+ ### OpenAI Compatibility Settings
1061
+
1062
+ The `openai-completions` API is implemented by many providers with minor differences. By default, the library auto-detects compatibility settings based on `baseUrl` for a small set of known OpenAI-compatible providers (Cerebras, xAI, Chutes, DeepSeek, NVIDIA NIM, Together AI, zAi, OpenCode, Cloudflare Workers AI, etc.). For custom proxies or unknown endpoints, you can override these settings via the `compat` field. For `openai-responses` models, the compat field supports Responses-specific flags.
1063
+
1064
+ ```typescript
1065
+ interface OpenAICompletionsCompat {
1066
+ supportsStore?: boolean; // Whether provider supports the `store` field (default: true)
1067
+ supportsDeveloperRole?: boolean; // Whether provider supports `developer` role vs `system` (default: true)
1068
+ supportsReasoningEffort?: boolean; // Whether provider supports `reasoning_effort` (default: true)
1069
+ supportsUsageInStreaming?: boolean; // Whether provider supports `stream_options: { include_usage: true }` (default: true)
1070
+ supportsStrictMode?: boolean; // Whether provider supports `strict` in tool definitions (default: true)
1071
+ sendSessionAffinityHeaders?: boolean; // Whether to send `session_id`, `x-client-request-id`, and `x-session-affinity` from `sessionId` when caching is enabled (default: false)
1072
+ maxTokensField?: 'max_completion_tokens' | 'max_tokens'; // Which field name to use (default: max_completion_tokens)
1073
+ requiresToolResultName?: boolean; // Whether tool results require the `name` field (default: false)
1074
+ requiresAssistantAfterToolResult?: boolean; // Whether tool results must be followed by an assistant message (default: false)
1075
+ requiresThinkingAsText?: boolean; // Whether thinking blocks must be converted to text (default: false)
1076
+ requiresReasoningContentOnAssistantMessages?: boolean; // Whether all replayed assistant messages must include empty reasoning_content when reasoning is enabled (default: auto-detected for DeepSeek)
1077
+ thinkingFormat?: 'openai' | 'openrouter' | 'deepseek' | 'together' | 'zai' | 'qwen' | 'chat-template' | 'qwen-chat-template' | 'string-thinking' | 'ant-ling'; // Format for reasoning param: 'openai' uses reasoning_effort, 'openrouter' uses reasoning: { effort }, 'deepseek' uses thinking: { type } plus reasoning_effort when supported, 'together' uses reasoning: { enabled } plus reasoning_effort when supported, 'zai' uses thinking: { type }, 'qwen' uses enable_thinking, 'chat-template' uses configurable chat_template_kwargs, 'qwen-chat-template' uses chat_template_kwargs.enable_thinking and preserve_thinking, 'string-thinking' uses top-level thinking, 'ant-ling' uses reasoning: { effort } only for mapped efforts (default: openai)
1078
+ chatTemplateKwargs?: Record<string, string | number | boolean | null | { '$var': 'thinking.enabled' | 'thinking.effort'; omitWhenOff?: boolean }>; // chat_template_kwargs values; use $var for pi-controlled thinking values
1079
+ cacheControlFormat?: 'anthropic'; // Anthropic-style cache_control on system prompt, last tool, and last user/assistant text content
1080
+ openRouterRouting?: OpenRouterRouting; // OpenRouter routing preferences (default: {})
1081
+ vercelGatewayRouting?: VercelGatewayRouting; // Vercel AI Gateway routing preferences (default: {})
1082
+ }
1083
+
1084
+ interface OpenAIResponsesCompat {
1085
+ supportsDeveloperRole?: boolean; // Whether provider supports `developer` role vs `system` (default: true)
1086
+ sendSessionIdHeader?: boolean; // Whether to send `session_id` from `sessionId` when caching is enabled (default: true)
1087
+ supportsLongCacheRetention?: boolean; // Whether provider supports `prompt_cache_retention: "24h"` (default: true)
1088
+ }
1089
+ ```
1090
+
1091
+ If `compat` is not set, the library falls back to URL-based detection. If `compat` is partially set, unspecified fields use the detected defaults. This is useful for:
1092
+
1093
+ - **LiteLLM proxies**: May not support `store` field
1094
+ - **Custom inference servers**: May use non-standard field names
1095
+ - **Self-hosted endpoints**: May have different feature support
1096
+
1097
+ ## Faux Provider for Tests
1098
+
1099
+ `fauxProvider()` builds an in-memory provider with scripted responses for tests and demos:
1100
+
1101
+ ```typescript
1102
+ import {
1103
+ createModels,
1104
+ fauxAssistantMessage,
1105
+ fauxProvider,
1106
+ fauxText,
1107
+ fauxThinking,
1108
+ fauxToolCall,
1109
+ } from '@earendil-works/pi-ai';
1110
+
1111
+ const faux = fauxProvider({
1112
+ tokensPerSecond: 50 // optional
1113
+ });
1114
+
1115
+ const models = createModels();
1116
+ models.setProvider(faux.provider);
1117
+
1118
+ const model = faux.getModel();
1119
+ const context = {
1120
+ messages: [{ role: 'user', content: 'Summarize package.json and then call echo', timestamp: Date.now() }]
1121
+ };
1122
+
1123
+ faux.setResponses([
1124
+ fauxAssistantMessage([
1125
+ fauxThinking('Need to inspect package metadata first.'),
1126
+ fauxToolCall('echo', { text: 'package.json' })
1127
+ ], { stopReason: 'toolUse' })
1128
+ ]);
1129
+
1130
+ const first = await models.complete(model, context, {
1131
+ sessionId: 'session-1',
1132
+ cacheRetention: 'short'
1133
+ });
1134
+ context.messages.push(first);
1135
+
1136
+ context.messages.push({
1137
+ role: 'toolResult',
1138
+ toolCallId: first.content.find((block) => block.type === 'toolCall')!.id,
1139
+ toolName: 'echo',
1140
+ content: [{ type: 'text', text: 'package.json contents here' }],
1141
+ isError: false,
1142
+ timestamp: Date.now()
1143
+ });
1144
+
1145
+ faux.setResponses([
1146
+ fauxAssistantMessage([
1147
+ fauxThinking('Now I can summarize the tool output.'),
1148
+ fauxText('Here is the summary.')
1149
+ ])
1150
+ ]);
1151
+
1152
+ const s = models.stream(model, context);
1153
+ for await (const event of s) {
1154
+ console.log(event.type);
1155
+ }
1156
+
1157
+ // Optional: multiple faux models for model-switching tests
1158
+ const multiModel = fauxProvider({
1159
+ provider: 'faux-multi',
1160
+ models: [
1161
+ { id: 'faux-fast', reasoning: false },
1162
+ { id: 'faux-thinker', reasoning: true }
1163
+ ]
1164
+ });
1165
+ models.setProvider(multiModel.provider);
1166
+ const thinker = multiModel.getModel('faux-thinker');
1167
+
1168
+ console.log(thinker?.reasoning);
1169
+ console.log(faux.getPendingResponseCount());
1170
+ console.log(faux.state.callCount);
1171
+ ```
1172
+
1173
+ Notes:
1174
+ - Responses are consumed from a queue in request start order.
1175
+ - If the queue is empty, the faux provider returns an assistant error message with `errorMessage: "No more faux responses queued"`.
1176
+ - Use `faux.setResponses([...])` to replace the remaining queue and `faux.appendResponses([...])` to add more responses.
1177
+ - `faux.models` exposes all faux models. `faux.getModel()` returns the first one, and `faux.getModel(id)` returns a specific one.
1178
+ - Use `fauxAssistantMessage(...)` for scripted assistant replies. Use `fauxText(...)`, `fauxThinking(...)`, and `fauxToolCall(...)` to build content blocks without filling in low-level fields manually.
1179
+ - Usage is estimated at roughly 1 token per 4 characters. When `sessionId` is present and `cacheRetention` is not `"none"`, prompt cache reads and writes are simulated automatically.
1180
+ - Tool call arguments stream incrementally via `toolcall_delta` chunks.
1181
+ - By default, each streamed chunk is emitted on its own microtask. Set `tokensPerSecond` to pace chunk delivery in real time.
1182
+ - The intended use is one deterministic scripted flow per handle. If you need independent concurrent flows, create separate faux providers with distinct `provider` ids.
1183
+
1184
+ ## Cross-Provider Handoffs
1185
+
1186
+ The library supports seamless handoffs between different LLM providers within the same conversation. This allows you to switch models mid-conversation while preserving context, including thinking blocks, tool calls, and tool results.
1187
+
1188
+ When messages from one provider are sent to a different provider, the library automatically transforms them for compatibility:
1189
+
1190
+ - **User and tool result messages** are passed through unchanged
1191
+ - **Assistant messages from the same provider/API** are preserved as-is
1192
+ - **Assistant messages from different providers** have their thinking blocks converted to text with `<thinking>` tags
1193
+ - **Tool calls and regular text** are preserved unchanged
1194
+
1195
+ ```typescript
1196
+ import { createModels, type Context } from '@earendil-works/pi-ai';
1197
+ import { anthropicProvider } from '@earendil-works/pi-ai/providers/anthropic';
1198
+ import { openaiProvider } from '@earendil-works/pi-ai/providers/openai';
1199
+ import { googleProvider } from '@earendil-works/pi-ai/providers/google';
1200
+
1201
+ const models = createModels();
1202
+ models.setProvider(anthropicProvider());
1203
+ models.setProvider(openaiProvider());
1204
+ models.setProvider(googleProvider());
1205
+
1206
+ const context: Context = { messages: [] };
1207
+
1208
+ // Start with Claude
1209
+ const claude = models.getModel('anthropic', 'claude-sonnet-4-5')!;
1210
+ context.messages.push({ role: 'user', content: 'What is 25 * 18?', timestamp: Date.now() });
1211
+ context.messages.push(await models.completeSimple(claude, context, { reasoning: 'medium' }));
1212
+
1213
+ // Switch to GPT-5 - it will see Claude's thinking as <thinking> tagged text
1214
+ const gpt5 = models.getModel('openai', 'gpt-5-mini')!;
1215
+ context.messages.push({ role: 'user', content: 'Is that calculation correct?', timestamp: Date.now() });
1216
+ context.messages.push(await models.complete(gpt5, context));
1217
+
1218
+ // Switch to Gemini
1219
+ const gemini = models.getModel('google', 'gemini-2.5-flash')!;
1220
+ context.messages.push({ role: 'user', content: 'What was the original question?', timestamp: Date.now() });
1221
+ const geminiResponse = await models.complete(gemini, context);
1222
+ ```
1223
+
1224
+ All providers can handle messages from other providers — text, tool calls and results (including images), thinking blocks (transformed to tagged text), and aborted messages with partial content. This enables flexible workflows: start with a fast model, switch to a more capable one for complex reasoning, or maintain continuity across provider outages.
1225
+
1226
+ ## Context Serialization
1227
+
1228
+ The `Context` object can be easily serialized and deserialized using standard JSON methods, making it simple to persist conversations, implement chat history, or transfer contexts between services:
1229
+
1230
+ ```typescript
1231
+ const context: Context = {
1232
+ systemPrompt: 'You are a helpful assistant.',
1233
+ messages: [
1234
+ { role: 'user', content: 'What is TypeScript?', timestamp: Date.now() }
1235
+ ]
1236
+ };
1237
+
1238
+ const model = models.getModel('openai', 'gpt-4o-mini')!;
1239
+ const response = await models.complete(model, context);
1240
+ context.messages.push(response);
1241
+
1242
+ // Serialize the entire context
1243
+ const serialized = JSON.stringify(context);
1244
+
1245
+ // Save to database, localStorage, file, etc.
1246
+ localStorage.setItem('conversation', serialized);
1247
+
1248
+ // Later: deserialize and continue the conversation
1249
+ const restored: Context = JSON.parse(localStorage.getItem('conversation')!);
1250
+ restored.messages.push({ role: 'user', content: 'Tell me more about its type system', timestamp: Date.now() });
1251
+
1252
+ // Continue with any model
1253
+ const newModel = models.getModel('anthropic', 'claude-3-5-haiku-20241022')!;
1254
+ const continuation = await models.complete(newModel, restored);
1255
+ ```
1256
+
1257
+ Models are plain serializable data too — no functions or implementations attached — so persisting "which model was this conversation using" is a `JSON.stringify` away.
1258
+
1259
+ > **Note**: If the context contains images (encoded as base64 as shown in the Image Input section), those will also be serialized.
1260
+
1261
+ ## Browser Usage
1262
+
1263
+ The library supports browser environments. The core entrypoint and provider factories are side-effect free and bundle cleanly. Environment variables are not available in browsers, so pass API keys explicitly — or inject a `CredentialStore` (e.g. localStorage-backed) and let provider auth resolve from stored credentials:
1264
+
1265
+ ```typescript
1266
+ import { createModels } from '@earendil-works/pi-ai';
1267
+ import { anthropicProvider } from '@earendil-works/pi-ai/providers/anthropic';
1268
+
1269
+ const models = createModels();
1270
+ models.setProvider(anthropicProvider());
1271
+
1272
+ const model = models.getModel('anthropic', 'claude-3-5-haiku-20241022')!;
1273
+ const response = await models.complete(model, {
1274
+ messages: [{ role: 'user', content: 'Hello!', timestamp: Date.now() }]
1275
+ }, {
1276
+ apiKey: 'your-api-key'
1277
+ });
1278
+ ```
1279
+
1280
+ > **Security Warning**: Exposing API keys in frontend code is dangerous. Anyone can extract and abuse your keys. Only use this approach for internal tools or demos. For production applications, use a backend proxy that keeps your API keys secure.
1281
+
1282
+ Browser compatibility notes:
1283
+
1284
+ - Amazon Bedrock (`bedrock-converse-stream`) is not supported in browser environments. It can still appear in model lists; calls fail at runtime.
1285
+ - OAuth login flows are Node-only. They are lazy-loaded behind bundler-opaque imports, so registering an OAuth-capable provider does not pull Node-only code into a browser bundle — only actually logging in would.
1286
+ - Use a server-side proxy or backend service if you need Bedrock or OAuth-based auth from a web app.
1287
+
1288
+ ## Bundling and Tree Shaking
1289
+
1290
+ For small bundles, import only the providers you need:
1291
+
1292
+ ```typescript
1293
+ import { createModels } from '@earendil-works/pi-ai';
1294
+ import { openaiProvider } from '@earendil-works/pi-ai/providers/openai';
1295
+
1296
+ const models = createModels();
1297
+ models.setProvider(openaiProvider());
1298
+ ```
1299
+
1300
+ Rules:
1301
+
1302
+ - `@earendil-works/pi-ai` is the core entrypoint and does not import built-in catalogs, provider factories, or SDK implementations.
1303
+ - `@earendil-works/pi-ai/providers/<provider>` imports that provider's catalog and lazy API wrapper only.
1304
+ - `@earendil-works/pi-ai/providers/all` imports every built-in provider factory and all catalogs. Use it only when you want the full built-in set.
1305
+ - With code splitting, provider SDKs stay in lazy chunks and load on first request.
1306
+ - Without code splitting, bundlers fold reachable lazy API implementations into the single bundle. A single-provider bundle then includes that provider's SDK; `providers/all` includes all statically visible SDKs. Bedrock is the exception: its AWS SDK implementation is loaded through a bundler-opaque Node-only import.
1307
+ - Importing `@earendil-works/pi-ai/api/<api-id>` directly loads that API implementation and its SDK immediately.
1308
+
1309
+ Avoid `@earendil-works/pi-ai/compat` in new bundled apps; it preserves the old global API and imports the full built-in catalog surface.
1310
+
1311
+ For single-file Node ESM bundles, some SDK dependencies may still use dynamic CommonJS `require()` internally. If you see errors such as `Dynamic require of "child_process" is not supported`, add a Node `require` shim to the bundle. With esbuild:
1312
+
1313
+ ```bash
1314
+ esbuild app.js --bundle --platform=node --format=esm \
1315
+ --banner:js='import { createRequire } from "module";const require = createRequire(import.meta.url);' \
1316
+ --outfile=app.bundle.js
1317
+ ```
1318
+
1319
+ This is only for Node bundles; it is not a browser or Cloudflare Workers workaround.
1320
+
1321
+ Bedrock is Node-only. Add it like any other provider:
1322
+
1323
+ ```typescript
1324
+ import { createModels } from '@earendil-works/pi-ai';
1325
+ import { amazonBedrockProvider } from '@earendil-works/pi-ai/providers/amazon-bedrock';
1326
+
1327
+ const models = createModels();
1328
+ models.setProvider(amazonBedrockProvider());
1329
+ ```
1330
+
1331
+ In normal Node package usage and code-split bundles, Bedrock loads its AWS SDK implementation lazily. For a standalone single-file bundle that must include Bedrock support, register the implementation module explicitly:
1332
+
1333
+ ```typescript
1334
+ import { setBedrockProviderModule } from '@earendil-works/pi-ai/api/bedrock-converse-stream.lazy';
1335
+ import { bedrockProviderModule } from '@earendil-works/pi-ai/bedrock-provider';
1336
+
1337
+ setBedrockProviderModule(bedrockProviderModule);
1338
+ ```
1339
+
1340
+ That explicit override bundles the AWS SDK. Without it, Bedrock's opaque runtime import expects the package's Bedrock implementation file to be available at runtime.
1341
+
1342
+ ### Provider-Scoped Environment Overrides
1343
+
1344
+ Pass `env` in stream options to scope provider configuration to a request. Values in `env` are used before process environment variables for provider auth and configuration such as Cloudflare account IDs, Azure OpenAI settings, Vertex project/location, Bedrock settings, `PI_CACHE_RETENTION`, and `HTTP_PROXY`/`HTTPS_PROXY`.
1345
+
1346
+ ```typescript
1347
+ const models = builtinModels();
1348
+ const model = models.getModel('cloudflare-ai-gateway', 'workers-ai/@cf/moonshotai/kimi-k2.6')!;
1349
+
1350
+ const response = await models.complete(model, context, {
1351
+ env: {
1352
+ CLOUDFLARE_API_KEY: '...',
1353
+ CLOUDFLARE_ACCOUNT_ID: 'account-id',
1354
+ CLOUDFLARE_GATEWAY_ID: 'gateway-id'
1355
+ }
1356
+ });
1357
+ ```
1358
+
1359
+ Use this when one process needs different provider settings per request, or when ambient environment variables should not leak into a provider call.
1360
+
1361
+ ## OAuth Providers
1362
+
1363
+ Several providers support OAuth authentication instead of static API keys:
1364
+
1365
+ - **Anthropic** (Claude Pro/Max subscription)
1366
+ - **OpenAI Codex** (ChatGPT Plus/Pro subscription, access to GPT-5.x Codex models)
1367
+ - **GitHub Copilot** (Copilot subscription)
1368
+
1369
+ Each of these providers carries an `OAuthAuth` on `provider.auth.oauth` with three operations: `login(callbacks)` runs the interactive flow and returns a credential, `refresh(credential)` exchanges the refresh token, and `toAuth(credential)` derives request auth (GitHub Copilot's per-account base URL comes from here). Refresh is automatic: `models.getAuth()` and the request paths refresh expired tokens under a credential-store lock, so concurrent requests and processes cannot double-refresh.
1370
+
1371
+ ```typescript
1372
+ import { createModels } from '@earendil-works/pi-ai';
1373
+ import { anthropicProvider } from '@earendil-works/pi-ai/providers/anthropic';
1374
+
1375
+ const models = createModels({ credentials: myStore }); // persistent CredentialStore
1376
+ models.setProvider(anthropicProvider());
1377
+
1378
+ // Login: drive the flow with prompt()/notify() callbacks, persist the credential
1379
+ const provider = models.getProvider('anthropic')!;
1380
+ const credential = await provider.auth.oauth!.login({
1381
+ prompt: async (p) => {
1382
+ // p.type: 'text' | 'secret' | 'select' | 'manual_code'
1383
+ // manual_code prompts race a local callback server; p.signal aborts them when the server wins
1384
+ return await askUser(p.message);
1385
+ },
1386
+ notify: (event) => {
1387
+ // event.type: 'auth_url' | 'device_code' | 'progress'
1388
+ if (event.type === 'auth_url') console.log(`Open: ${event.url}`);
1389
+ if (event.type === 'device_code') console.log(`Code: ${event.userCode} at ${event.verificationUri}`);
1390
+ if (event.type === 'progress') console.log(event.message);
1391
+ },
1392
+ });
1393
+ await myStore.modify('anthropic', async () => credential);
1394
+
1395
+ // From here on, requests resolve and refresh the token automatically
1396
+ const model = models.getModel('anthropic', 'claude-sonnet-4-5')!;
1397
+ await models.complete(model, context);
1398
+
1399
+ // Logout
1400
+ await myStore.delete('anthropic');
1401
+ ```
1402
+
1403
+ ### Vertex AI
1404
+
1405
+ Vertex AI models support either a Google Cloud API key or Application Default Credentials (ADC):
1406
+
1407
+ - **API key**: Set `GOOGLE_CLOUD_API_KEY` or pass `apiKey` in the call options.
1408
+ - **Local development (ADC)**: Run `gcloud auth application-default login`
1409
+ - **CI/Production (ADC)**: Set `GOOGLE_APPLICATION_CREDENTIALS` to point to a service account JSON key file
1410
+
1411
+ When using ADC, also set `GOOGLE_CLOUD_PROJECT` (or `GCLOUD_PROJECT`) and `GOOGLE_CLOUD_LOCATION`. You can also pass `project`/`location` in the call options. When using `GOOGLE_CLOUD_API_KEY`, `project` and `location` are not required.
1412
+
1413
+ ```bash
1414
+ # Local (uses your user credentials)
1415
+ gcloud auth application-default login
1416
+ export GOOGLE_CLOUD_PROJECT="my-project"
1417
+ export GOOGLE_CLOUD_LOCATION="us-central1"
1418
+
1419
+ # CI/Production (service account key file)
1420
+ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
1421
+ ```
1422
+
1423
+ Official docs: [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials)
1424
+
1425
+ ### CLI Login
1426
+
1427
+ The quickest way to authenticate:
1428
+
1429
+ ```bash
1430
+ npx @earendil-works/pi-ai login # interactive provider selection
1431
+ npx @earendil-works/pi-ai login anthropic # login to specific provider
1432
+ npx @earendil-works/pi-ai list # list available providers
1433
+ ```
1434
+
1435
+ Credentials are saved to `auth.json` in the current directory.
1436
+
1437
+ ### Programmatic OAuth
1438
+
1439
+ The legacy flow functions remain available via the `@earendil-works/pi-ai/oauth` entry point (`loginAnthropic`, `loginOpenAICodex`, `loginGitHubCopilot`, `refreshOAuthToken`, `getOAuthApiKey`); credential storage is the caller's responsibility there. New code should prefer the provider-owned `OAuthAuth` shown above — it composes with the credential store and gets locked auto-refresh for free.
1440
+
1441
+ Provider notes:
1442
+
1443
+ **OpenAI Codex**: Requires a ChatGPT Plus or Pro subscription. Provides access to GPT-5.x Codex models with extended context windows and reasoning capabilities. The library automatically handles session-based prompt caching when `sessionId` is provided in stream options. You can set `transport` in stream options to `"sse"`, `"websocket"`, or `"auto"` for Codex Responses transport selection. When using WebSocket with a `sessionId`, connections are reused per session and expire after 5 minutes of inactivity.
1444
+
1445
+ **Azure OpenAI (Responses)**: Uses the Responses API only. Set `AZURE_OPENAI_API_KEY` and either `AZURE_OPENAI_BASE_URL` or `AZURE_OPENAI_RESOURCE_NAME`. `AZURE_OPENAI_BASE_URL` supports both `https://<resource>.openai.azure.com` and `https://<resource>.cognitiveservices.azure.com`; root endpoints are normalized to `.../openai/v1` automatically. Use `AZURE_OPENAI_API_VERSION` (defaults to `v1`) to override the API version if needed. Deployment names are treated as model IDs by default, override with `azureDeploymentName` or `AZURE_OPENAI_DEPLOYMENT_NAME_MAP` using comma-separated `model-id=deployment` pairs (for example `gpt-4o-mini=my-deployment,gpt-4o=prod`). Legacy deployment-based URLs are intentionally unsupported.
1446
+
1447
+ **GitHub Copilot**: If you get "The requested model is not supported" error, enable the model manually in VS Code: open Copilot Chat, click the model selector, select the model (warning icon), and click "Enable".
1448
+
1449
+ ## Migrating from the Old Global API
1450
+
1451
+ Older versions exposed a global API: `stream()`/`complete()` dispatching on `model.api` via a global registry, sync `getModel()`/`getModels()`/`getProviders()` catalog reads, `registerApiProvider()`, `getEnvApiKey()`, and per-API lazy stream functions. That surface lives unchanged on the **compat entrypoint**:
1452
+
1453
+ ```typescript
1454
+ // Before
1455
+ import { getModel, complete } from '@earendil-works/pi-ai';
1456
+
1457
+ // After (verbatim behavior, one import-path change)
1458
+ import { getModel, complete } from '@earendil-works/pi-ai/compat';
1459
+ ```
1460
+
1461
+ Compat is a strict superset of the root entrypoint, so a file can switch its import path wholesale. It will be removed in a future release; migrate to `createModels()` + provider factories:
1462
+
1463
+ | Old | New |
1464
+ |-----|-----|
1465
+ | `getModel('openai', 'gpt-4o-mini')` | `models.getModel('openai', 'gpt-4o-mini')` or `getBuiltinModel()` from `providers/all` |
1466
+ | `getModels('anthropic')` / `getProviders()` | `models.getModels('anthropic')` / `models.getProviders()` or `getBuiltin*` |
1467
+ | `stream(model, ctx, opts)` (env-key injection) | `models.stream(model, ctx, opts)` (provider auth resolution) |
1468
+ | `registerApiProvider({ api, stream, streamSimple })` | `createProvider({ id, auth, models, api })` + `models.setProvider()` |
1469
+ | `getEnvApiKey('openai')` | `await models.getAuth(model)` |
1470
+ | `streamAnthropic(model, ctx, opts)` | `stream` from `@earendil-works/pi-ai/api/anthropic-messages`, or a provider in a collection |
1471
+ | `registerFauxProvider()` | `fauxProvider()` + `models.setProvider()` |
1472
+
1473
+ ## Development
1474
+
1475
+ ### Adding a New Provider
1476
+
1477
+ Adding a new LLM provider requires changes across multiple files. The layered layout: API implementations live in `src/api/`, provider factories in `src/providers/`, generated catalogs in `src/providers/<id>.models.ts`. This checklist covers all necessary steps:
1478
+
1479
+ #### 1. Core Types (`src/types.ts`)
1480
+
1481
+ - Add the API identifier to `KnownApi` (for example `"bedrock-converse-stream"`), if it is a new API
1482
+ - Add the provider name to `KnownProvider` (for example `"amazon-bedrock"`)
1483
+ - Add the options type to `ApiOptionsMap`
1484
+
1485
+ #### 2. API Implementation (`src/api/<api-id>.ts`, only for a new API)
1486
+
1487
+ Create a new API implementation file (for example `bedrock-converse-stream.ts`) that exports exactly `stream` and `streamSimple`, plus:
1488
+
1489
+ - An options interface extending `StreamOptions` (for example `BedrockOptions`)
1490
+ - Message conversion functions to transform `Context` to provider format
1491
+ - Tool conversion if the provider supports tools
1492
+ - Response parsing to emit standardized events (`text`, `tool_call`, `thinking`, `usage`, `stop`)
1493
+
1494
+ Add a lazy wrapper `src/api/<api-id>.lazy.ts` (`<name>Api()` via `lazyApi()`) so providers can reference the implementation without importing its SDK. Add any root-level `export type` re-exports in `src/index.ts` that should remain available from `@earendil-works/pi-ai`.
1495
+
1496
+ #### 3. Model Generation (`scripts/generate-models.ts`, `scripts/generate-image-models.ts`)
1497
+
1498
+ - Add logic to fetch and parse models from the provider's source (e.g., models.dev API)
1499
+ - Map chat/tool-capable provider model data to the standardized `Model` interface via `scripts/generate-models.ts`; regeneration emits `src/providers/<id>.models.ts` and the aggregator
1500
+ - Map image-generation provider model data to the standardized `ImagesModel` interface via `scripts/generate-image-models.ts`
1501
+ - Handle provider-specific quirks (pricing format, capability flags, model ID transformations)
1502
+
1503
+ #### 4. Provider Factory (`src/providers/<id>.ts`)
1504
+
1505
+ - `createProvider()` wiring catalog + auth + the lazy API wrapper
1506
+ - Auth: `envApiKeyAuth` for standard key providers, a custom `ApiKeyAuth` for ambient auth (AWS profiles, ADC), `lazyOAuth` where an OAuth flow exists
1507
+ - Register the factory in `src/providers/all.ts`
1508
+ - If it is a new API: register it in the builtin list in `src/compat.ts` and add the package subpath export in `package.json`
1509
+
1510
+ #### 5. Tests (`test/`)
1511
+
1512
+ Create or update test files to cover the new provider:
1513
+
1514
+ - `stream.test.ts` - Basic streaming and tool use
1515
+ - `tokens.test.ts` - Token usage reporting
1516
+ - `abort.test.ts` - Request cancellation
1517
+ - `empty.test.ts` - Empty message handling
1518
+ - `context-overflow.test.ts` - Context limit errors
1519
+ - `image-limits.test.ts` - Image support (if applicable)
1520
+ - `unicode-surrogate.test.ts` - Unicode handling
1521
+ - `tool-call-without-result.test.ts` - Orphaned tool calls
1522
+ - `image-tool-result.test.ts` - Images in tool results
1523
+ - `total-tokens.test.ts` - Token counting accuracy
1524
+ - `cross-provider-handoff.test.ts` - Cross-provider context replay
1525
+ - `providers.test.ts` - Provider listing and auth resolution
1526
+
1527
+ For `cross-provider-handoff.test.ts`, add at least one provider/model pair. If the provider exposes multiple model families (for example GPT and Claude), add at least one pair per family.
1528
+
1529
+ For providers with non-standard auth (AWS, Google Vertex), create a utility like `bedrock-utils.ts` with credential detection helpers.
1530
+
1531
+ #### 6. Coding Agent Integration (`../coding-agent/`)
1532
+
1533
+ Update `src/core/model-resolver.ts`:
1534
+
1535
+ - Add a default model ID for the provider in `DEFAULT_MODELS`
1536
+
1537
+ Update `src/cli/args.ts`:
1538
+
1539
+ - Add environment variable documentation in the help text
1540
+
1541
+ Update `README.md`:
1542
+
1543
+ - Add the provider to the providers section with setup instructions
1544
+
1545
+ #### 7. Documentation
1546
+
1547
+ Update `packages/ai/README.md`:
1548
+
1549
+ - Add to the Supported Providers table
1550
+ - Document any provider-specific options or authentication requirements
1551
+ - Add environment variable to the Environment Variables section
1552
+
1553
+ #### 8. Changelog
1554
+
1555
+ Add an entry to `packages/ai/CHANGELOG.md` under `## [Unreleased]`:
1556
+
1557
+ ```markdown
1558
+ ### Added
1559
+ - Added support for [Provider Name] provider ([#PR](link) by [@author](link))
1560
+ ```
1561
+
1562
+ ## License
1563
+
1564
+ MIT