@opencode/ai 2.1.4 → 2.2.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 (354) hide show
  1. package/README.md +339 -166
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/cache-policy.d.ts +4 -0
  5. package/dist/cache-policy.js +20 -6
  6. package/dist/decision-client.d.ts +21 -0
  7. package/dist/decision-client.js +55 -0
  8. package/dist/decision.d.ts +472 -0
  9. package/dist/decision.js +158 -0
  10. package/dist/effect.d.ts +38 -0
  11. package/dist/effect.js +27 -0
  12. package/dist/effort-updates.d.ts +2 -2
  13. package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
  14. package/dist/experimental/cloudflare-run-extraction.js +83 -0
  15. package/dist/experimental/extraction.d.ts +183 -0
  16. package/dist/experimental/extraction.js +102 -0
  17. package/dist/experimental/realtime.d.ts +7 -2
  18. package/dist/experimental/realtime.js +5 -5
  19. package/dist/experimental.d.ts +2 -3
  20. package/dist/experimental.js +1 -2
  21. package/dist/image-client.d.ts +50 -14
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +6 -176
  24. package/dist/image.js +4 -11
  25. package/dist/index.d.ts +1444 -34
  26. package/dist/index.js +139 -24
  27. package/dist/llm.d.ts +16 -1
  28. package/dist/llm.js +34 -0
  29. package/dist/media-client.d.ts +3 -1
  30. package/dist/media-client.js +1 -0
  31. package/dist/media-model.d.ts +3 -0
  32. package/dist/media-model.js +4 -1
  33. package/dist/media.d.ts +0 -7
  34. package/dist/media.js +0 -6
  35. package/dist/protocols/alibaba-chat.d.ts +59 -4
  36. package/dist/protocols/alibaba-images.d.ts +22 -0
  37. package/dist/protocols/alibaba-images.js +77 -0
  38. package/dist/protocols/alibaba-messages.d.ts +52 -17
  39. package/dist/protocols/alibaba-responses.d.ts +26 -6
  40. package/dist/protocols/anthropic-messages.d.ts +160 -54
  41. package/dist/protocols/anthropic-messages.js +44 -13
  42. package/dist/protocols/bedrock-converse.d.ts +110 -15
  43. package/dist/protocols/bedrock-converse.js +112 -15
  44. package/dist/protocols/bedrock-event-stream.js +1 -0
  45. package/dist/protocols/cartesia-speech.d.ts +0 -18
  46. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  47. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  48. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  49. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  50. package/dist/protocols/deepgram-speech.d.ts +0 -18
  51. package/dist/protocols/elevenlabs-speech.d.ts +0 -18
  52. package/dist/protocols/gemini.d.ts +3 -0
  53. package/dist/protocols/gemini.js +11 -6
  54. package/dist/protocols/google-images.d.ts +2 -2
  55. package/dist/protocols/google-images.js +10 -37
  56. package/dist/protocols/google-interactions.d.ts +4 -0
  57. package/dist/protocols/google-interactions.js +12 -5
  58. package/dist/protocols/google-speech.d.ts +0 -18
  59. package/dist/protocols/google-speech.js +0 -1
  60. package/dist/protocols/google-transcription.d.ts +0 -18
  61. package/dist/protocols/google-transcription.js +0 -1
  62. package/dist/protocols/google-video.d.ts +1 -1
  63. package/dist/protocols/google-video.js +2 -7
  64. package/dist/protocols/index.d.ts +3 -0
  65. package/dist/protocols/index.js +3 -0
  66. package/dist/protocols/meta-images.d.ts +7 -1
  67. package/dist/protocols/meta-images.js +10 -8
  68. package/dist/protocols/meta-messages.d.ts +52 -17
  69. package/dist/protocols/meta-messages.js +14 -1
  70. package/dist/protocols/meta-responses.d.ts +46 -6
  71. package/dist/protocols/meta-responses.js +29 -1
  72. package/dist/protocols/minimax-images.d.ts +25 -0
  73. package/dist/protocols/minimax-images.js +150 -0
  74. package/dist/protocols/open-responses.d.ts +212 -27
  75. package/dist/protocols/open-responses.js +116 -54
  76. package/dist/protocols/openai-chat.d.ts +1135 -31
  77. package/dist/protocols/openai-chat.js +155 -60
  78. package/dist/protocols/openai-compatible-chat.d.ts +57 -5
  79. package/dist/protocols/openai-compatible-responses.d.ts +28 -8
  80. package/dist/protocols/openai-decisions.d.ts +22 -0
  81. package/dist/protocols/openai-decisions.js +128 -0
  82. package/dist/protocols/openai-freeform.d.ts +47 -0
  83. package/dist/protocols/openai-freeform.js +54 -0
  84. package/dist/protocols/openai-images.d.ts +36 -24
  85. package/dist/protocols/openai-images.js +137 -39
  86. package/dist/protocols/openai-responses.d.ts +202 -42
  87. package/dist/protocols/openai-responses.js +49 -10
  88. package/dist/protocols/openai-speech.d.ts +0 -18
  89. package/dist/protocols/openai-speech.js +15 -5
  90. package/dist/protocols/openai-transcription.d.ts +0 -18
  91. package/dist/protocols/openai-transcription.js +3 -4
  92. package/dist/protocols/runway-video.d.ts +1 -1
  93. package/dist/protocols/runway-video.js +1 -1
  94. package/dist/protocols/shared.d.ts +9 -1
  95. package/dist/protocols/shared.js +13 -2
  96. package/dist/protocols/system-one.d.ts +101 -0
  97. package/dist/protocols/system-one.js +230 -0
  98. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  99. package/dist/protocols/utils/bedrock-cache.js +7 -6
  100. package/dist/protocols/utils/cache.d.ts +14 -3
  101. package/dist/protocols/utils/cache.js +11 -4
  102. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  103. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  104. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  105. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  106. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  107. package/dist/protocols/utils/image-sizing.js +73 -0
  108. package/dist/protocols/utils/media-input.d.ts +4 -5
  109. package/dist/protocols/utils/media-input.js +8 -5
  110. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  111. package/dist/protocols/utils/speech-stream.js +0 -1
  112. package/dist/protocols/utils/tool-schema.js +15 -5
  113. package/dist/protocols/utils/tool-stream.d.ts +9 -0
  114. package/dist/protocols/venice-chat.d.ts +58 -4
  115. package/dist/protocols/venice-chat.js +2 -2
  116. package/dist/protocols/xai-images.d.ts +7 -2
  117. package/dist/protocols/xai-images.js +11 -5
  118. package/dist/protocols/xai-responses.d.ts +30 -3
  119. package/dist/protocols/xai-responses.js +30 -3
  120. package/dist/protocols/xai-video.d.ts +1 -1
  121. package/dist/protocols/xai-video.js +11 -8
  122. package/dist/protocols/zai-chat.d.ts +60 -4
  123. package/dist/protocols/zai-images.d.ts +3 -1
  124. package/dist/protocols/zai-images.js +12 -11
  125. package/dist/protocols/zai-messages.d.ts +52 -17
  126. package/dist/provider-error.js +23 -7
  127. package/dist/provider-package.d.ts +2 -0
  128. package/dist/providers/alibaba/images.d.ts +2 -0
  129. package/dist/providers/alibaba/images.js +1 -0
  130. package/dist/providers/alibaba.d.ts +137 -28
  131. package/dist/providers/alibaba.js +16 -8
  132. package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
  133. package/dist/providers/amazon-bedrock-mantle.js +1 -1
  134. package/dist/providers/amazon-bedrock.d.ts +34 -14
  135. package/dist/providers/amazon-bedrock.js +11 -11
  136. package/dist/providers/anthropic-compatible.d.ts +53 -18
  137. package/dist/providers/anthropic.d.ts +53 -18
  138. package/dist/providers/anthropic.js +1 -1
  139. package/dist/providers/azure/images.d.ts +2 -0
  140. package/dist/providers/azure/images.js +1 -0
  141. package/dist/providers/azure.d.ts +129 -24
  142. package/dist/providers/azure.js +19 -1
  143. package/dist/providers/baseten/decisions.d.ts +2 -0
  144. package/dist/providers/baseten/decisions.js +1 -0
  145. package/dist/providers/baseten.d.ts +124 -12
  146. package/dist/providers/baseten.js +41 -8
  147. package/dist/providers/cerebras.d.ts +115 -11
  148. package/dist/providers/cerebras.js +1 -1
  149. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  150. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  151. package/dist/providers/cloudflare-ai-gateway.d.ts +290 -60
  152. package/dist/providers/cloudflare-ai-gateway.js +32 -4
  153. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  154. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  155. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  156. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  157. package/dist/providers/cloudflare-workers-ai.d.ts +128 -12
  158. package/dist/providers/cloudflare-workers-ai.js +45 -9
  159. package/dist/providers/cohere/chat.d.ts +1 -1
  160. package/dist/providers/cohere/chat.js +1 -1
  161. package/dist/providers/cohere.d.ts +115 -11
  162. package/dist/providers/cohere.js +1 -1
  163. package/dist/providers/deepinfra.d.ts +115 -11
  164. package/dist/providers/deepinfra.js +1 -1
  165. package/dist/providers/deepseek.d.ts +115 -11
  166. package/dist/providers/deepseek.js +1 -1
  167. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  168. package/dist/providers/digitalocean/decisions.js +1 -0
  169. package/dist/providers/digitalocean/images.d.ts +2 -0
  170. package/dist/providers/digitalocean/images.js +1 -0
  171. package/dist/providers/digitalocean/responses.d.ts +4 -0
  172. package/dist/providers/digitalocean/responses.js +1 -0
  173. package/dist/providers/digitalocean.d.ts +390 -20
  174. package/dist/providers/digitalocean.js +53 -11
  175. package/dist/providers/fireworks.d.ts +115 -11
  176. package/dist/providers/fireworks.js +1 -1
  177. package/dist/providers/google/images.d.ts +2 -0
  178. package/dist/providers/google/images.js +1 -0
  179. package/dist/providers/google/interactions.d.ts +1 -1
  180. package/dist/providers/google/interactions.js +1 -1
  181. package/dist/providers/google-vertex/images.d.ts +2 -0
  182. package/dist/providers/google-vertex/images.js +1 -0
  183. package/dist/providers/google-vertex-chat.d.ts +57 -5
  184. package/dist/providers/google-vertex-chat.js +1 -1
  185. package/dist/providers/google-vertex-interactions.d.ts +1 -1
  186. package/dist/providers/google-vertex-interactions.js +1 -1
  187. package/dist/providers/google-vertex-messages.d.ts +53 -18
  188. package/dist/providers/google-vertex-messages.js +1 -1
  189. package/dist/providers/google-vertex-mistral.d.ts +1 -1
  190. package/dist/providers/google-vertex-mistral.js +1 -1
  191. package/dist/providers/google-vertex-responses.d.ts +24 -4
  192. package/dist/providers/google-vertex-responses.js +1 -1
  193. package/dist/providers/google-vertex.d.ts +4 -2
  194. package/dist/providers/google-vertex.js +30 -13
  195. package/dist/providers/google.d.ts +6 -5
  196. package/dist/providers/google.js +15 -8
  197. package/dist/providers/groq.d.ts +119 -15
  198. package/dist/providers/groq.js +1 -7
  199. package/dist/providers/index.d.ts +0 -4
  200. package/dist/providers/index.js +0 -4
  201. package/dist/providers/meta/images.d.ts +2 -0
  202. package/dist/providers/meta/images.js +1 -0
  203. package/dist/providers/meta.d.ts +254 -146
  204. package/dist/providers/meta.js +2 -1
  205. package/dist/providers/minimax/chat.d.ts +1 -1
  206. package/dist/providers/minimax/chat.js +1 -1
  207. package/dist/providers/minimax/images.d.ts +3 -0
  208. package/dist/providers/minimax/images.js +1 -0
  209. package/dist/providers/minimax/responses.d.ts +1 -1
  210. package/dist/providers/minimax/responses.js +1 -1
  211. package/dist/providers/minimax.d.ts +139 -26
  212. package/dist/providers/minimax.js +22 -9
  213. package/dist/providers/mistral.d.ts +3 -3
  214. package/dist/providers/mistral.js +1 -1
  215. package/dist/providers/moonshot/messages.d.ts +1 -1
  216. package/dist/providers/moonshot/messages.js +1 -1
  217. package/dist/providers/moonshot/responses.d.ts +1 -1
  218. package/dist/providers/moonshot/responses.js +1 -1
  219. package/dist/providers/moonshot.d.ts +132 -25
  220. package/dist/providers/moonshot.js +1 -1
  221. package/dist/providers/openai/images.d.ts +2 -0
  222. package/dist/providers/openai/images.js +1 -0
  223. package/dist/providers/openai-compatible/images.d.ts +2 -0
  224. package/dist/providers/openai-compatible/images.js +1 -0
  225. package/dist/providers/openai-compatible-responses.d.ts +24 -4
  226. package/dist/providers/openai-compatible.d.ts +62 -8
  227. package/dist/providers/openai-compatible.js +29 -10
  228. package/dist/providers/openai-options.d.ts +3 -1
  229. package/dist/providers/openai.d.ts +103 -18
  230. package/dist/providers/openai.js +23 -5
  231. package/dist/providers/opencode/decisions.d.ts +2 -0
  232. package/dist/providers/opencode/decisions.js +1 -0
  233. package/dist/providers/opencode.d.ts +11 -12
  234. package/dist/providers/opencode.js +10 -8
  235. package/dist/providers/openrouter/decisions.d.ts +2 -0
  236. package/dist/providers/openrouter/decisions.js +1 -0
  237. package/dist/providers/openrouter/images.d.ts +2 -0
  238. package/dist/providers/openrouter/images.js +1 -0
  239. package/dist/providers/openrouter/responses.d.ts +4 -0
  240. package/dist/providers/openrouter/responses.js +1 -0
  241. package/dist/providers/openrouter.d.ts +446 -35
  242. package/dist/providers/openrouter.js +78 -27
  243. package/dist/providers/togetherai.d.ts +115 -11
  244. package/dist/providers/togetherai.js +1 -1
  245. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  246. package/dist/providers/typesafe-ai/decisions.js +1 -0
  247. package/dist/providers/typesafe-ai.d.ts +11 -12
  248. package/dist/providers/typesafe-ai.js +10 -8
  249. package/dist/providers/venice/responses.d.ts +4 -0
  250. package/dist/providers/venice/responses.js +1 -0
  251. package/dist/providers/venice.d.ts +261 -9
  252. package/dist/providers/venice.js +33 -17
  253. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  254. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  255. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  256. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  257. package/dist/providers/vercel-ai-gateway.d.ts +16 -22
  258. package/dist/providers/vercel-ai-gateway.js +41 -85
  259. package/dist/providers/xai/images.d.ts +2 -0
  260. package/dist/providers/xai/images.js +1 -0
  261. package/dist/providers/xai.d.ts +66 -12
  262. package/dist/providers/xai.js +15 -8
  263. package/dist/providers/zai/images.d.ts +2 -0
  264. package/dist/providers/zai/images.js +1 -0
  265. package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
  266. package/dist/providers/zai-coding-plan/messages.js +1 -1
  267. package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
  268. package/dist/providers/zai-coding-plan/responses.js +1 -1
  269. package/dist/providers/zai-coding-plan.d.ts +132 -25
  270. package/dist/providers/zai-coding-plan.js +1 -1
  271. package/dist/providers/zai.d.ts +62 -9
  272. package/dist/providers/zai.js +15 -8
  273. package/dist/route/auth.d.ts +1 -1
  274. package/dist/route/client.d.ts +2 -2
  275. package/dist/route/client.js +26 -4
  276. package/dist/route/decision.d.ts +58 -0
  277. package/dist/route/decision.js +75 -0
  278. package/dist/route/executor.d.ts +1 -1
  279. package/dist/route/framing.d.ts +2 -0
  280. package/dist/route/index.d.ts +3 -0
  281. package/dist/route/index.js +3 -0
  282. package/dist/route/media-protocol.d.ts +3 -4
  283. package/dist/route/media-protocol.js +12 -8
  284. package/dist/route/media.d.ts +6 -2
  285. package/dist/route/media.js +8 -6
  286. package/dist/route/transport/http.js +1 -0
  287. package/dist/route/transport/index.d.ts +1 -0
  288. package/dist/schema/events.d.ts +148 -6
  289. package/dist/schema/events.js +20 -0
  290. package/dist/schema/messages.d.ts +41 -3
  291. package/dist/schema/messages.js +23 -0
  292. package/dist/schema/options.d.ts +5 -3
  293. package/dist/schema/options.js +8 -3
  294. package/dist/speech-client.d.ts +53 -14
  295. package/dist/speech-client.js +0 -1
  296. package/dist/speech.d.ts +0 -135
  297. package/dist/speech.js +2 -4
  298. package/dist/testing/decision.d.ts +16 -0
  299. package/dist/testing/decision.js +20 -0
  300. package/dist/testing/image.d.ts +14 -0
  301. package/dist/testing/image.js +12 -0
  302. package/dist/testing/media.d.ts +18 -0
  303. package/dist/testing/media.js +36 -0
  304. package/dist/testing/script.d.ts +28 -0
  305. package/dist/testing/script.js +60 -0
  306. package/dist/testing/speech.d.ts +14 -0
  307. package/dist/testing/speech.js +12 -0
  308. package/dist/testing/transcription.d.ts +14 -0
  309. package/dist/testing/transcription.js +12 -0
  310. package/dist/testing/video.d.ts +14 -0
  311. package/dist/testing/video.js +12 -0
  312. package/dist/testing.d.ts +35 -45
  313. package/dist/testing.js +14 -75
  314. package/dist/tool.d.ts +12 -1
  315. package/dist/tool.js +10 -2
  316. package/dist/transcription-client.d.ts +69 -14
  317. package/dist/transcription.d.ts +0 -135
  318. package/dist/transcription.js +1 -1
  319. package/dist/utils/media-type.js +22 -1
  320. package/dist/video-client.d.ts +46 -14
  321. package/dist/video-client.js +0 -1
  322. package/dist/video.d.ts +1 -136
  323. package/dist/video.js +3 -5
  324. package/package.json +497 -11
  325. package/dist/experimental/evaluation-client.d.ts +0 -21
  326. package/dist/experimental/evaluation-client.js +0 -64
  327. package/dist/experimental/evaluation.d.ts +0 -242
  328. package/dist/experimental/evaluation.js +0 -108
  329. package/dist/experimental/system-one.d.ts +0 -16
  330. package/dist/experimental/system-one.js +0 -135
  331. package/dist/promise.d.ts +0 -1021
  332. package/dist/promise.js +0 -101
  333. package/dist/protocols/bfl-images.d.ts +0 -38
  334. package/dist/protocols/bfl-images.js +0 -153
  335. package/dist/protocols/fal-images.d.ts +0 -25
  336. package/dist/protocols/fal-images.js +0 -104
  337. package/dist/protocols/fal-video.d.ts +0 -29
  338. package/dist/protocols/fal-video.js +0 -73
  339. package/dist/protocols/replicate-images.d.ts +0 -28
  340. package/dist/protocols/replicate-images.js +0 -127
  341. package/dist/protocols/stability-images.d.ts +0 -39
  342. package/dist/protocols/stability-images.js +0 -136
  343. package/dist/protocols/utils/fal-queue.d.ts +0 -26
  344. package/dist/protocols/utils/fal-queue.js +0 -67
  345. package/dist/provider.d.ts +0 -23
  346. package/dist/provider.js +0 -2
  347. package/dist/providers/black-forest-labs.d.ts +0 -21
  348. package/dist/providers/black-forest-labs.js +0 -23
  349. package/dist/providers/fal.d.ts +0 -24
  350. package/dist/providers/fal.js +0 -26
  351. package/dist/providers/replicate.d.ts +0 -21
  352. package/dist/providers/replicate.js +0 -17
  353. package/dist/providers/stability.d.ts +0 -23
  354. package/dist/providers/stability.js +0 -18
package/README.md CHANGED
@@ -1,10 +1,33 @@
1
1
  # @opencode/ai
2
2
 
3
- Schema-first APIs for text, images, video, speech, and transcription, built with Effect.
3
+ Schema-first APIs for text, images, video, speech, transcription, and decisions, built with Effect.
4
+
5
+ `@opencode/ai` is the Promise API: one managed runtime behind the LLM and media methods, plus asset helpers. `ai.file`
6
+ and `ai.write` load `node:fs/promises` on first use, so no Effect `FileSystem` is needed:
7
+
8
+ ```ts
9
+ import { AI } from "@opencode/ai"
10
+ import { OpenAI } from "@opencode/ai/providers"
11
+
12
+ const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY })
13
+
14
+ const ai = AI.make()
15
+ const input = { model: openai.responses("gpt-4o-mini"), prompt: "Say hello." }
16
+ const response = await ai.llm.generate(input)
17
+ console.log(response.text)
18
+ const generated = await ai.image.generate({ model: openai.image("gpt-image-2"), prompt: "A lighthouse" })
19
+ await ai.write(generated.image, "./lighthouse.png") // also ai.file(path), ai.bytes(asset), ai.base64(asset), ai.materialize(asset)
20
+ for await (const event of ai.llm.stream(ai.llm.request(input))) {
21
+ // LLMEvent
22
+ }
23
+ await ai.dispose()
24
+ ```
25
+
26
+ The Effect API lives at `@opencode/ai/effect`. Its methods return `Effect` or `Stream`:
4
27
 
5
28
  ```ts
6
29
  import { Effect } from "effect"
7
- import { AIClient, LLM } from "@opencode/ai"
30
+ import { AIClient, LLM } from "@opencode/ai/effect"
8
31
  import { OpenAI } from "@opencode/ai/providers"
9
32
 
10
33
  const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY })
@@ -27,6 +50,91 @@ Run `LLM.stream(...)` instead of `generate` when you want incremental `LLMEvent`
27
50
  `LLM.request(...)`. The event stream is provider-neutral — same shape across OpenAI Chat, OpenAI Responses,
28
51
  Anthropic Messages, Gemini, Bedrock Converse, and any OpenAI-compatible deployment.
29
52
 
53
+ ### Tool loop
54
+
55
+ `stream` runs one model call; `loop` runs the model's tool calls and calls the model again until it stops calling
56
+ tools. Events from every step arrive on one stream, with a `tool-result` after each tool runs. `until` is checked
57
+ after each step that has tool calls, with every step's `LLMResponse`; returning `true` ends the loop without running
58
+ them. `AI.tool` takes a plain `async` execute; a throw or rejection goes back to the model as an error result, and
59
+ `signal` aborts when the loop is interrupted.
60
+ `Tool.make` from `@opencode/ai/effect` is the Effect form, with a validated `success` schema:
61
+
62
+ ```ts
63
+ import { readFile } from "node:fs/promises"
64
+ import { Schema } from "effect"
65
+ import { AI } from "@opencode/ai"
66
+
67
+ const read_file = AI.tool({
68
+ description: "Read a UTF-8 file.",
69
+ parameters: Schema.Struct({ path: Schema.String }),
70
+ execute: ({ path }, { signal }) => readFile(path, { encoding: "utf8", signal }),
71
+ })
72
+
73
+ const events = ai.llm.loop({
74
+ model,
75
+ prompt: "Summarize package.json.",
76
+ tools: { read_file },
77
+ until: ({ steps }) => steps.length >= 8,
78
+ })
79
+ for await (const event of events) {
80
+ if (event.type === "text-delta") process.stdout.write(event.text)
81
+ }
82
+ ```
83
+
84
+ ### Freeform tools
85
+
86
+ A tool with exactly one required string parameter can set `freeform`, so the model writes that parameter as raw text
87
+ instead of JSON arguments: unconstrained `text`, or text matching a `regex` or `lark` grammar.
88
+
89
+ ```ts
90
+ const run_code = AI.tool({
91
+ description: "Run JavaScript",
92
+ parameters: Schema.Struct({ code: Schema.String }),
93
+ freeform: { type: "lark", grammar: JS_GRAMMAR },
94
+ execute: ({ code }) => runCode(code),
95
+ })
96
+ ```
97
+
98
+ OpenAI Responses and Chat Completions, and every provider that reuses them, send it as a
99
+ [custom tool](https://platform.openai.com/docs/guides/function-calling#custom-tools). Other protocols send the normal
100
+ JSON tool. Only set `freeform` for models that accept custom tools in that format; nothing checks this or falls back
101
+ to JSON, so an unsupported model returns the provider's error. Calls, tool input events, results and history always
102
+ use the `{ code }` object, and past calls replay the way the tool is declared in the current request, so the same
103
+ history works with or without `freeform`.
104
+
105
+ ### Structured output
106
+
107
+ `generateObject` forces a tool call and decodes its input against `schema`; pass `jsonSchema` instead for an
108
+ unvalidated `unknown` object:
109
+
110
+ ```ts
111
+ const { object } = await ai.llm.generateObject({
112
+ model,
113
+ prompt: "Pick a city.",
114
+ schema: Schema.Struct({ city: Schema.String }),
115
+ })
116
+ ```
117
+
118
+ ### Raw provider events
119
+
120
+ Set `includeRaw: true` on a request to also receive every provider frame as `{ type: "raw", data }`, in order and
121
+ before the events parsed from that frame. `data` is the parsed JSON frame, so frames this package doesn't handle yet
122
+ are visible too. Raw events are off by default, and `generate` ignores them. Translate a frame with a stream map:
123
+
124
+ ```ts
125
+ import { Stream } from "effect"
126
+ import { LLM, LLMEvent } from "@opencode/ai/effect"
127
+
128
+ const flagged = (data: unknown) =>
129
+ typeof data === "object" && data !== null && "type" in data && data.type === "moderation.flagged"
130
+
131
+ const events = LLM.stream({ model, prompt: "Say hello.", includeRaw: true }).pipe(
132
+ Stream.map((event) =>
133
+ event.type === "raw" && flagged(event.data) ? LLMEvent.providerError({ message: "Flagged by moderation" }) : event,
134
+ ),
135
+ )
136
+ ```
137
+
30
138
  ### Google Interactions
31
139
 
32
140
  `Google.configure({ apiKey }).interactions(modelID)` selects the Interactions API; `.model(modelID)` still selects
@@ -62,13 +170,14 @@ provider's image route from the model and returns `Media.Asset`s with lazily dec
62
170
 
63
171
  ```ts
64
172
  import { NodeFileSystem } from "@effect/platform-node"
65
- import { Image, Media } from "@opencode/ai"
173
+ import { Image, Media } from "@opencode/ai/effect"
66
174
 
67
175
  const image = Effect.gen(function* () {
68
176
  const response = yield* Image.generate({
69
177
  model: openai.image("gpt-image-2"),
70
178
  prompt: "A robot tending a rooftop garden",
71
- size: "1024x1024",
179
+ aspect: "1:1",
180
+ resolution: "1K",
72
181
  providerOptions: { quality: "high" }, // typed per image model
73
182
  })
74
183
  yield* Media.write(response.image, "./garden.png")
@@ -94,30 +203,13 @@ const logged = RequestExecutor.middleware((request, next) =>
94
203
  const everything = AIClient.layerWith(logged) // or AI.make({ layer: logged })
95
204
  ```
96
205
 
97
- Prefer promises? `@opencode/ai/promise` exposes the same LLM and media APIs over one managed runtime, plus asset
98
- helpers; `ai.file` and `ai.write` load `node:fs/promises` on first use, so no Effect `FileSystem` is needed:
99
-
100
- ```ts
101
- import { AI } from "@opencode/ai/promise"
102
-
103
- const ai = AI.make()
104
- const input = { model: openai.responses("gpt-4o-mini"), prompt: "Say hello." }
105
- const text = await ai.llm.generate(input)
106
- const generated = await ai.image.generate({ model: openai.image("gpt-image-2"), prompt: "A lighthouse" })
107
- await ai.write(generated.image, "./lighthouse.png") // also ai.file(path), ai.bytes(asset), ai.base64(asset), ai.materialize(asset)
108
- for await (const event of ai.llm.stream(ai.llm.request(input))) {
109
- // LLMEvent
110
- }
111
- await ai.dispose()
112
- ```
113
-
114
206
  ## Venice AI
115
207
 
116
208
  `Venice` provides native Chat Completions with streaming tools and reasoning. `model` and `chat`
117
- select the same API; credentials default to `VENICE_API_KEY`.
209
+ select the same API, and `responses` selects its Responses API; credentials default to `VENICE_API_KEY`.
118
210
 
119
211
  ```ts
120
- import { LLM } from "@opencode/ai"
212
+ import { LLM } from "@opencode/ai/effect"
121
213
  import { Venice } from "@opencode/ai/providers"
122
214
  import { Effect } from "effect"
123
215
 
@@ -143,60 +235,111 @@ signatures, including per-tool signatures. Venice's encrypted scalar trailers ar
143
235
  reasoning but retained in provider metadata for replay. Cache affinity uses `promptCacheKey`, and cache-write
144
236
  usage reads Venice's `cache_creation_input_tokens` field.
145
237
 
146
- The native package entrypoint is `@opencode/ai/providers/venice`. Image generation, embeddings, Responses, and
147
- client-side E2EE are not implemented by this provider.
238
+ The native package entrypoints are `@opencode/ai/providers/venice` and `@opencode/ai/providers/venice/responses`.
239
+ Image generation, embeddings, and client-side E2EE are not implemented by this provider.
148
240
 
149
- ## Experimental evaluation
241
+ ## Decisions
150
242
 
151
- Evaluation models compare shared state with typed choice, score, and boolean questions. The API is
152
- isolated under an experimental entrypoint and provider namespace while the contract evolves:
243
+ Decision models answer typed questions about an input: a yes/no `predicate` (a probability), a `choice` from listed
244
+ values, or a `score` on ordered levels, each with the probability of every option.
153
245
 
154
246
  ```ts
155
247
  import { Effect } from "effect"
156
- import { Evaluation, EvaluationClient } from "@opencode/ai/experimental"
157
- import { TypeSafeAI } from "@opencode/ai/providers"
158
-
159
- const model = TypeSafeAI.configure().experimental.evaluation("jev-latest")
248
+ import { Decision, DecisionClient, Media } from "@opencode/ai/effect"
249
+ import { OpenAI } from "@opencode/ai/providers"
160
250
 
161
- const program = Evaluation.run({
162
- model,
163
- state: "I was charged twice. Please refund the duplicate payment.",
164
- questions: {
165
- department: {
251
+ const program = Decision.generate({
252
+ model: OpenAI.configure().decision("gpt-6-luna"),
253
+ input: [
254
+ { type: "text", text: "I was charged twice. Please refund the duplicate payment." },
255
+ { type: "media", media: Media.url("https://example.com/receipt.png", { mediaType: "image/png" }) },
256
+ ],
257
+ questions: [
258
+ { name: "refund", type: "predicate", instructions: "Is the customer asking for a refund?" },
259
+ {
260
+ name: "department",
166
261
  type: "choice",
167
262
  instructions: "Which team should handle this?",
168
- criteria: { billing: "Payments and refunds", technical: "Bugs and outages" },
263
+ choices: [{ value: "billing", description: "Payments and refunds" }, { value: "technical" }],
169
264
  },
170
- urgency: {
265
+ {
266
+ name: "urgency",
171
267
  type: "score",
172
268
  instructions: "How urgent is this?",
173
- criteria: ["Can wait", "Needs prompt attention", "Blocking revenue"],
269
+ levels: [{ label: "Can wait" }, { label: "Needs prompt attention" }, { label: "Blocking revenue" }],
174
270
  },
175
- refund: { type: "boolean", instructions: "Is the customer asking for a refund?" },
176
- },
271
+ ],
177
272
  })
178
273
 
179
- const response = await Effect.runPromise(program.pipe(Effect.provide(EvaluationClient.fetchLayer)))
180
-
181
- console.log(response.answers.department.choice)
182
- console.log(response.answers.refund.probability)
274
+ const response = await Effect.runPromise(program.pipe(Effect.provide(DecisionClient.fetchLayer)))
275
+ const [refund, department] = response.answers
183
276
  ```
184
277
 
185
- `TypeSafeAI` reads `TYPESAFE_API_KEY`. `OpenCode` exposes the same selector and reads
186
- `OPENCODE_API_KEY`. OpenRouter and Vercel AI Gateway use the same provider shape:
278
+ `input` is a JSON object or an ordered list of `text`, `json` and `media` parts. Answers come back in question order.
279
+ A question the host declines is `{ name, type: "error", reason, message? }`, with `reason` such as `"refusal"`; the
280
+ other answers still come back.
281
+ `response.usage` has `inputTokens`, `outputTokens`, `totalTokens` and the host's reported `cost` when it sends one;
282
+ the host's raw usage stays in `providerMetadata`.
283
+ Media goes wherever the host reads it, and a kind the host has no place for fails the call. Host-specific fields go in
284
+ `providerOptions`, typed by the selected model (OpenAI `promptCacheKey` and `safetyIdentifier`, OpenRouter
285
+ `provider` routing, Baseten `max_len`).
187
286
 
188
287
  ```ts
189
- import { OpenRouter, VercelAIGateway } from "@opencode/ai/providers"
288
+ import {
289
+ Baseten,
290
+ CloudflareAIGateway,
291
+ CloudflareWorkersAI,
292
+ DigitalOcean,
293
+ OpenCode,
294
+ OpenRouter,
295
+ TypeSafeAI,
296
+ VercelAIGateway,
297
+ } from "@opencode/ai/providers"
298
+
299
+ TypeSafeAI.configure().decision("jev-latest")
300
+ OpenCode.configure().decision("jev-1.13")
301
+ OpenRouter.configure().decision("typesafe/jev-1.13")
302
+ VercelAIGateway.configure().decision("typesafe-ai/jev")
303
+ Baseten.configure().decision("decision-models/baseten-elephant-9b-latest")
304
+ DigitalOcean.configure().decision("typesafe-jev-1.13.0")
305
+ CloudflareWorkersAI.configure({ accountId }).decision("@cf/cloudflare/clef")
306
+ CloudflareAIGateway.configure({ accountId }).decision("typesafe/jev")
307
+ ```
190
308
 
191
- OpenRouter.configure().experimental.evaluation("typesafe/jev-1.13")
192
- VercelAIGateway.configure().experimental.evaluation("typesafe-ai/jev")
309
+ OpenAI and Vercel AI Gateway use OpenAI's `/v1/decisions` API. TypeSafe, OpenCode, OpenRouter, Baseten and
310
+ DigitalOcean use System One (`/systemone`), and Cloudflare sends the System One body through `/ai/run`.
311
+
312
+ ### Extraction (experimental)
313
+
314
+ Extraction models read typed values out of text instead of answering questions with probabilities. A field of type
315
+ `text`, `number`, `date`, `time`, `datetime`, `duration`, `list`, `estimate` or `forecast` gets an answer typed to
316
+ match; other types are sent and answered as-is. Only Cloudflare's Clairic serves it today, so it lives under
317
+ `@opencode/ai/experimental`.
318
+
319
+ ```ts
320
+ import { ai } from "@opencode/ai"
321
+ import { Extraction } from "@opencode/ai/experimental"
322
+ import { CloudflareWorkersAI } from "@opencode/ai/providers"
323
+
324
+ const response = await ai.run(
325
+ Extraction.generate({
326
+ model: CloudflareWorkersAI.configure({ accountId }).experimental.extraction("@cf/cloudflare/clairic"),
327
+ input: "Invoice INV-2291, issued 2026-09-02, net 30. Total $1,080.00. Contact: Dana Ruiz, Priya Shah.",
328
+ fields: {
329
+ invoiceNumber: { type: "text" },
330
+ dueDate: { type: "date", instructions: "Issue date plus the net payment days" },
331
+ total: { type: "number", decimals: 2, unit: "USD" },
332
+ contacts: { type: "list", items: "text" },
333
+ },
334
+ }),
335
+ )
336
+ response.answers.total.value // 1080, or null when the input does not say
193
337
  ```
194
338
 
195
- OpenRouter reads `OPENROUTER_API_KEY`. Vercel reads `AI_GATEWAY_API_KEY`, then `VERCEL_OIDC_TOKEN`.
196
- The common API uses `boolean`; System One routes lower it to native `noul`.
197
- Choice and score answers include `confidence` when the provider returns it, such as
198
- `response.answers.department.confidence`. Score legends remain available in provider metadata, and
199
- the provider's rounded probabilities are returned unchanged.
339
+ Value answers carry `guess`, `nullProbability` and `confidence`; text answers carry a `span` into `input`. Estimates and
340
+ forecasts return `median`, `p10` and `p90`. Field options other than `type`, `instructions` and `nullThreshold` go to
341
+ Clairic as written. Effect users provide `RequestExecutor.fetchLayer` (or `AIClient.layer`). Images are not supported
342
+ yet.
200
343
 
201
344
  ## Alibaba Cloud Model Studio
202
345
 
@@ -205,7 +348,7 @@ Chat Completions (`.model` or `.chat`), Anthropic-compatible Messages (`.message
205
348
  Responses (`.responses`). These routes use HTTP/SSE.
206
349
 
207
350
  ```ts
208
- import { LLM } from "@opencode/ai"
351
+ import { LLM } from "@opencode/ai/effect"
209
352
  import { Alibaba } from "@opencode/ai/providers"
210
353
 
211
354
  const alibaba = Alibaba.configure({
@@ -270,13 +413,22 @@ Package entrypoints are `@opencode/ai/providers/alibaba`, `alibaba/chat`, `aliba
270
413
  and `alibaba/responses`. Live recordings cover all three APIs in Singapore; regional URL construction
271
414
  is unit-tested for all six regions.
272
415
 
416
+ ### Images
417
+
418
+ `alibaba.image(...)` uses the native multimodal generation API (`/api/v1/services/aigc/multimodal-generation/generation`)
419
+ for Qwen-Image (`qwen-image-2.0`, `qwen-image-2.0-pro`) and Wan (`wan2.7-image`, `wan2.7-image-pro`). `aspect` and
420
+ `resolution` lower to a `W*H` size, `providerOptions.size` sets it exactly, and `images` are sent as URLs or data URLs
421
+ for editing. Native `parameters` include `size`, `seed`, `negativePrompt`, `promptExtend`, `watermark`, `thinkingMode`,
422
+ and `enableSequential`; raw keys such as `bbox_list` pass through. Results are URLs that Model Studio keeps for 24
423
+ hours. A complete `baseURL` for images includes `/api/v1`.
424
+
273
425
  ## Z.AI
274
426
 
275
427
  `ZAI` uses the standard API. Chat Completions is the default language-model API;
276
428
  the existing `.image(...)` selector provides image generation.
277
429
 
278
430
  ```ts
279
- import { LLM } from "@opencode/ai"
431
+ import { LLM } from "@opencode/ai/effect"
280
432
  import { ZAI, ZAICodingPlan } from "@opencode/ai/providers"
281
433
 
282
434
  const zai = ZAI.configure({ apiKey: process.env.ZAI_API_KEY })
@@ -342,7 +494,7 @@ Package entrypoints are `@opencode/ai/providers/zai`, `zai/chat`, `zai-coding-pl
342
494
  Moonshot defaults to Chat Completions, with Messages and Responses selectors for Kimi K3:
343
495
 
344
496
  ```ts
345
- import { LLM } from "@opencode/ai"
497
+ import { LLM } from "@opencode/ai/effect"
346
498
  import { Moonshot } from "@opencode/ai/providers"
347
499
 
348
500
  const moonshot = Moonshot.configure({ apiKey: process.env.MOONSHOT_API_KEY })
@@ -404,7 +556,7 @@ MiniMax defaults to its Messages API and reads `MINIMAX_API_KEY` when `apiKey` i
404
556
 
405
557
  ```ts
406
558
  import { Effect } from "effect"
407
- import { AIClient, LLM } from "@opencode/ai"
559
+ import { AIClient, LLM } from "@opencode/ai/effect"
408
560
  import { MiniMax } from "@opencode/ai/providers"
409
561
 
410
562
  const minimax = MiniMax.configure({ apiKey: process.env.MINIMAX_API_KEY })
@@ -434,7 +586,9 @@ M2.x models always think, even when a disabling option is supplied. For tool con
434
586
  `response.message` in history before adding `Message.tool(...)` results; this preserves reasoning and any signatures.
435
587
 
436
588
  The default API bases are `https://api.minimax.io/anthropic/v1` for Messages and `https://api.minimax.io/v1` for
437
- Chat and Responses. `configure({ baseURL })` replaces the selected API's base, including its version prefix.
589
+ Chat, Responses and Images. `configure({ baseURL })` replaces the selected API's base, including its version prefix;
590
+ use `https://api.minimax.cn/v1` for the mainland China platform. `minimax.image("image-01")` (also
591
+ `@opencode/ai/providers/minimax/images`) generates images; see [MiniMax images](#minimax-images).
438
592
 
439
593
  ## Meta
440
594
 
@@ -481,7 +635,7 @@ citations or separate result blocks. Retain `response.message` for either API's
481
635
  Use `Image.generate` for one-off generation or editing:
482
636
 
483
637
  ```ts
484
- import { Image, Media } from "@opencode/ai"
638
+ import { Image, Media } from "@opencode/ai/effect"
485
639
 
486
640
  const generation = Image.generate({
487
641
  model: meta.image("muse-image-1.0"),
@@ -494,13 +648,13 @@ const edit = Image.generate({
494
648
  model: meta.image("muse-image-1.0"),
495
649
  prompt: "Make the square purple.",
496
650
  images: [Media.bytes(imageBytes, "image/webp")],
497
- format: "png",
498
- providerOptions: { reasoningStrength: "low" },
651
+ providerOptions: { reasoningStrength: "low", outputFormat: "png" },
499
652
  })
500
653
  ```
501
654
 
502
- The default image format is WEBP; `format` also accepts PNG/JPEG and `responseFormat: "url"`
503
- returns a signed URL. `size` is an aspect-ratio hint. For conversational images, select
655
+ The default image format is WEBP; `outputFormat` also accepts PNG/JPEG and `responseFormat: "url"`
656
+ returns a signed URL. `aspect` lowers to Meta's `size`, which is only an aspect-ratio hint: Meta renders about 2.5
657
+ megapixels whatever you ask, so `resolution` is ignored. For conversational images, select
504
658
  `meta.responses("muse-image-1.0")` with `tools: [Meta.imageGeneration({ reasoningStrength: "low" })]`.
505
659
  Generated images are provider-executed tool results with file content. Retain `response.message` to
506
660
  replay the signed image handle on the next request. Muse Image accepts only the `image_generation` tool.
@@ -512,11 +666,12 @@ Meta Responses is explicitly HTTP/SSE-only and does not use WebSockets, even whe
512
666
 
513
667
  Use `Image.generate` with an image model for direct asset generation. `Image.request` mirrors `LLM.request`: the
514
668
  model comes from the facade's `.image(...)` selector (mirroring `.responses(...)`), common fields
515
- (`images`, `mask`, `n`, `size`, `aspectRatio`, `seed`, `format`) lower natively or fail typed, and
516
- `providerOptions` is inferred from the selected model:
669
+ (`images`, `n`, `aspect`, `resolution`) lower natively or fail typed, and `providerOptions` is inferred from the
670
+ selected model. `aspect` is a ratio such as `"16:9"`; `resolution` is a size tier (`"1K"` is about 1024×1024 pixels
671
+ at that ratio, `"2K"` about 2048×2048). Exact sizes, seeds, masks, and output formats are provider options:
517
672
 
518
673
  ```ts
519
- import { Image, Media } from "@opencode/ai"
674
+ import { Image, Media } from "@opencode/ai/effect"
520
675
  import { OpenAI } from "@opencode/ai/providers"
521
676
 
522
677
  const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY })
@@ -526,9 +681,10 @@ const program = Effect.gen(function* () {
526
681
  model: openai.image("gpt-image-2"),
527
682
  prompt: "A robot tending a rooftop garden",
528
683
  n: 2,
529
- size: "1024x1024",
530
- format: "webp",
684
+ aspect: "16:9",
685
+ resolution: "2K",
531
686
  providerOptions: {
687
+ outputFormat: "webp",
532
688
  quality: "high", // inferred from the OpenAI image model
533
689
  future_option: true, // unknown native options pass through unchanged
534
690
  },
@@ -538,24 +694,35 @@ const program = Effect.gen(function* () {
538
694
  })
539
695
  ```
540
696
 
541
- Common fields are portable in shape, not in support. Unsupported fields fail with a typed `AIError` before any network
542
- call rather than being dropped, so check this table before swapping only the `model`:
543
-
544
- | Provider | `n` | `size` | `aspectRatio` | `seed` | `format` | `images` | `mask` |
545
- | --------------------- | --- | --------- | ------------- | ------ | -------- | -------------------------------- | ------------------- |
546
- | OpenAI | ✓¹ | ✓ | ✗ | ✗ | ✓ | ✓ | ✓ |
547
- | Google (Gemini) | 1 | ✗ | ✓ | ✓ | ✗ | ✓ (no public URLs) | ✗ |
548
- | xAI | ✓ | ✗ | ✓ | ✗ | ✗ | ✓ | ✗ |
549
- | Z.ai | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
550
- | Meta | ✓ | ✓ (hint) | ✗ | ✗ | ✓ | ✓ | ✗ |
551
- | Black Forest Labs | 1 | per model | per model | ✓ | ✓ | per model (1–8) | `flux-pro-1.0-fill` |
552
- | fal | ✓ | per model | per model | ✓ | ✓ | 1 (several on `/edit`, `/multi`) | ✓ |
553
- | Replicate | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ (use `providerOptions`) | ✗ |
554
- | Stability `image` | 1 | ✗ | ✓ | ✓ | ✓ | 1 (not on `core`) | ✗ |
555
- | Stability `upscale()` | ✗ | ✗ | ✗ | ✓ | ✓ | exactly 1 (required) | ✗ |
556
-
557
- ✓ lowers natively; ✗ fails whenever the field is set (including `n: 1`); `1` means `n > 1` fails. ¹ `Image.stream` on OpenAI generates one image. fal
558
- rejects `size` and `aspectRatio` together; which one a fal or BFL model takes depends on the model.
697
+ Common fields are portable in shape, not in support. Some routes approximate `aspect` or `resolution` with the nearest
698
+ size they offer; others fail with a typed `AIError` before any network call rather than dropping them, so check this
699
+ table before swapping only the `model`:
700
+
701
+ | Provider | `n` | `aspect` | `resolution` | `images` | Moved to `providerOptions` |
702
+ | --------------------- | --- | -------------------- | --------------------- | -------------------------------- | -------------------------------------------------- |
703
+ | OpenAI | ✓¹ | nearest size | nearest size | ✓ | `size`, `outputFormat`, `mask` |
704
+ | Google (Gemini) | 1 | ✓ | ✓ (`0.5K` as `512`) | ✓ (no public URLs) | `seed` |
705
+ | xAI | ✓ | ✓ | `1k`/`2k` | ✓ | none |
706
+ | Meta | ✓ | ✓ (hint) | ignored | ✓ | `size`, `outputFormat` |
707
+ | Z.ai | ✗ | width × height | width × height | ✗ | `size` |
708
+ | Alibaba | ✓ | width × height | width × height | ✓ | `size`, `seed` |
709
+ | MiniMax | ✓ | preset or w × h⁴ | preset or w × h⁴ | 1 (portrait subject) | `aspect_ratio`, `width`, `height`, `seed` |
710
+ | Vercel AI Gateway | ✓ | as OpenAI³ | as OpenAI³ | per model | as OpenAI |
711
+ | OpenRouter | ✓ | ✓ (`aspect_ratio`) | tier⁵ | per model⁵ | `size`, `outputFormat` (no `mask`) |
712
+ | Cloudflare Workers AI | 1 | width × height² | width × height² | ✗ | `width`, `height`, `seed` |
713
+
714
+ ✓ lowers natively; ✗ fails whenever the field is set (including `n: 1`); `1` means `n > 1` fails. "width × height"
715
+ computes a size the provider accepts and fails when the request falls outside its limits. ¹ `Image.stream` on OpenAI
716
+ generates one image. On OpenAI, `gpt-image-2` and later get a computed size; older models get the nearest of their
717
+ fixed sizes. `providerOptions.size` replaces `aspect` and `resolution`, so setting both fails. Vercel AI Gateway
718
+ forwards `outputFormat` but does not apply it, so the returned bytes keep the upstream model's own format. ² Workers AI
719
+ `@cf/black-forest-labs/flux-1-schnell` takes no size, and the provider rejects it. ³ Non-OpenAI gateway models
720
+ (`bfl/flux-2-pro`) get a computed width × height, which the gateway passes through; models with a fixed list, such as
721
+ Recraft, reject sizes outside it. Grok (`spacexai/*`, `xai/*`) ignores `size`, so it gets `providerOptions.xai`
722
+ `aspect_ratio` and `1k`/`2k` instead. ⁴ MiniMax sends its `aspect_ratio` preset for a preset aspect at about `1K` and an
723
+ exact width × height (512–2048 px, steps of 8) otherwise; `image-01-live` takes only the presets, minus `21:9`.
724
+ ⁵ OpenRouter takes `512`, `768`, `1K`, `1.5K`, `2K` or `4K` rather than pixels; other values are left out. It has no
725
+ edits endpoint, so input images go to `/images/generations` as `input_references` (data URLs or http(s) URLs).
559
726
 
560
727
  `Media.Asset` is the one asset type shared by image requests, image responses, LLM messages, and tool results.
561
728
  `asset.source` is the serializable `Media.Source` (`bytes`, `base64`, `url`, or `ref`); `asset.bytes()`,
@@ -587,15 +754,15 @@ only forward refs that belong to their own provider (OpenAI, xAI, and Gemini ima
587
754
  returns a ref yet, and `asset.bytes()` / `materialize()` on a ref fail by design. Raw strings are not accepted as
588
755
  image inputs, avoiding ambiguity between base64, URLs, and provider IDs. Empty or omitted `images` uses text-to-image generation; a
589
756
  non-empty array selects the provider's edit behavior (see the table above for routes that limit the count). OpenAI
590
- uses multipart for byte/data-URL edits and its JSON reference body for URL or file-ID edits. The common `mask`
591
- field selects inpainting; routes that cannot honor it fail with `UnsupportedOperation`:
757
+ uses multipart for byte/data-URL edits and its JSON reference body for URL or file-ID edits. Inpainting is a
758
+ provider option on the routes that support it (OpenAI):
592
759
 
593
760
  ```ts
594
761
  const inpainted = Image.generate({
595
762
  model: openai.image("gpt-image-2"),
596
763
  prompt,
597
764
  images: [Media.bytes(sourceBytes, "image/png")],
598
- mask: Media.bytes(maskBytes, "image/png"),
765
+ providerOptions: { mask: Media.bytes(maskBytes, "image/png") },
599
766
  })
600
767
  ```
601
768
 
@@ -624,10 +791,10 @@ const xai = Image.generate({
624
791
  model: XAI.configure({ apiKey }).image("any-model-id"),
625
792
  prompt,
626
793
  n: 2,
627
- aspectRatio: "16:9",
794
+ aspect: "16:9",
795
+ resolution: "1K",
628
796
  providerOptions: {
629
- resolution: "1k",
630
- responseFormat: "b64_json",
797
+ responseFormat: "url", // defaults to "b64_json" (inline bytes)
631
798
  future_option: true,
632
799
  },
633
800
  http,
@@ -643,10 +810,10 @@ const googleProgram = Effect.gen(function* () {
643
810
  const response = yield* Image.generate({
644
811
  model: Google.configure({ apiKey }).image("any-model-id"),
645
812
  prompt: "A robot tending a rooftop garden",
646
- aspectRatio: "16:9",
647
- seed: 42,
813
+ aspect: "16:9",
814
+ resolution: "2K",
648
815
  providerOptions: {
649
- imageSize: "2K",
816
+ seed: 42,
650
817
  thinkingLevel: "HIGH",
651
818
  includeThoughts: true,
652
819
  futureOption: true,
@@ -684,6 +851,26 @@ Z.ai does not include trustworthy MIME metadata for output URLs, so generated im
684
851
  `application/octet-stream` until materialized. Output URLs expire after 30 days; call `asset.materialize()` and
685
852
  persist the bytes promptly if they must remain available.
686
853
 
854
+ ### MiniMax images
855
+
856
+ ```ts
857
+ import { MiniMax } from "@opencode/ai/providers"
858
+
859
+ const minimax = Image.generate({
860
+ model: MiniMax.configure({ apiKey }).image("image-01"),
861
+ prompt,
862
+ n: 2,
863
+ aspect: "16:9",
864
+ images: [Media.url("https://example.com/portrait.jpg")], // optional subject reference
865
+ providerOptions: { promptOptimizer: true, seed: 42 },
866
+ })
867
+ ```
868
+
869
+ The reference image is sent as a `character` subject, so it should be a single front-facing portrait. Images come
870
+ back inline (`responseFormat: "base64"` by default); `responseFormat: "url"` returns links that expire after 24 hours
871
+ and carry no MIME type until materialized. MiniMax status codes map to typed errors; code 1026 is a `ContentPolicy`
872
+ error.
873
+
687
874
  ### Partial images
688
875
 
689
876
  OpenAI's GPT image models stream previews. `Image.stream` sends `stream: true` with `partialImages` (0–3, default 2)
@@ -691,7 +878,7 @@ and emits `image-partial` events before each final `image`; `Image.generate` kee
691
878
 
692
879
  ```ts
693
880
  import { Stream } from "effect"
694
- import { ImageEvent } from "@opencode/ai"
881
+ import { ImageEvent } from "@opencode/ai/effect"
695
882
 
696
883
  const previews = Image.stream({
697
884
  model: openai.image("gpt-image-2"),
@@ -702,49 +889,6 @@ const previews = Image.stream({
702
889
 
703
890
  The provider may send fewer previews than requested when the final image is ready first.
704
891
 
705
- ### Queued image providers
706
-
707
- Black Forest Labs, fal, Replicate, and Stability's creative upscaler are submit-then-poll routes. `Image.generate`
708
- and `Image.stream` poll for you (pass `{ poll }` to tune the interval and timeout); `Image.start` returns a
709
- `Generation` whose `token` is serializable JSON for `Image.resume` in another process:
710
-
711
- ```ts
712
- import { BlackForestLabs, Stability } from "@opencode/ai/providers"
713
-
714
- const bfl = BlackForestLabs.configure({ apiKey: process.env.BFL_API_KEY })
715
-
716
- const submit = Effect.gen(function* () {
717
- const generation = yield* Image.start({ model: bfl.image("flux-2-pro"), prompt, size: "1024x768" })
718
- persist({ provider: "black-forest-labs", modelID: "flux-2-pro", token: generation.token })
719
- })
720
-
721
- const finish = Effect.gen(function* () {
722
- const saved = load()
723
- const resumed = yield* Image.resume(bfl.image(saved.modelID), saved.token)
724
- return yield* resumed.await({ poll: { interval: "2 seconds" } })
725
- })
726
- ```
727
-
728
- The token carries no route identity, so persist the provider and model ID alongside it: `resume` needs the model.
729
-
730
- - **Black Forest Labs** — results are downloaded before returning, because `result.sample` expires in 10 minutes.
731
- - **Replicate** — inputs are model-defined, so only `prompt` lowers: sizing, count, seed, format, and files go in
732
- `providerOptions` under the model's names, with files as `Media.Asset` (data URLs up to 256 KB, larger by URL).
733
- Outputs are removed an hour after the prediction completes. `Prefer: wait=60` in `headers` or `http.headers` holds
734
- the submission open so a fast prediction costs one result read.
735
- - **Stability** — `stability.image(id)` generates inline; `stability.upscale()` is the creative upscaler, queued:
736
-
737
- ```ts
738
- const stability = Stability.configure({ apiKey: process.env.STABILITY_API_KEY })
739
- const upscaled = Effect.gen(function* () {
740
- const small = yield* Media.file("./small.png")
741
- return yield* Image.generate(
742
- { model: stability.upscale(), prompt: "A lighthouse", images: [small] },
743
- { poll: { interval: "5 seconds" } },
744
- )
745
- })
746
- ```
747
-
748
892
  Imagen is not available: Google shut it down on the Gemini API, and Vertex discontinued the Imagen 4 models on
749
893
  2026-06-30. `Google.image(...)` uses Gemini-native image models.
750
894
 
@@ -769,13 +913,13 @@ The hosted result is represented as a provider-executed tool call and a tool res
769
913
  ## Video generation
770
914
 
771
915
  Video mirrors `Image` with one difference: every provider is asynchronous, so the route is a submit-then-poll
772
- `Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, `Fal`, and `Runway` facades.
773
- Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspectRatio`, `resolution`, `audio`, `n`, `seed`,
916
+ `Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, and `Runway` facades.
917
+ Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`, `resolution`, `audio`, `n`, `seed`,
774
918
  `negativePrompt`) lower natively or fail with a typed `AIError` before any network call; provider-native controls live
775
919
  under `providerOptions`, inferred from the selected model.
776
920
 
777
921
  ```ts
778
- import { Video } from "@opencode/ai"
922
+ import { Video } from "@opencode/ai/effect"
779
923
  import { Google, Runway } from "@opencode/ai/providers"
780
924
 
781
925
  const google = Google.configure({ apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY })
@@ -786,7 +930,7 @@ const program = Effect.gen(function* () {
786
930
  {
787
931
  model: google.video("veo-3.1-generate-preview"),
788
932
  prompt: "Panning wide shot of a calico kitten sleeping in the sunshine",
789
- aspectRatio: "16:9",
933
+ aspect: "16:9",
790
934
  resolution: "1080p",
791
935
  durationSeconds: 8,
792
936
  providerOptions: { personGeneration: "allow_adult" },
@@ -804,7 +948,7 @@ const controlled = Effect.gen(function* () {
804
948
  const generation = yield* Video.start({ model: google.video("veo-3.1-generate-preview"), prompt })
805
949
  generation.id // provider operation / task / request id
806
950
  generation.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
807
- generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, `{ taskID }`, or fal's follow-up URLs
951
+ generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, or `{ taskID }`
808
952
  // The token carries no route identity: persist the provider and model ID alongside it, since `resume` needs the model.
809
953
  const saved = JSON.stringify(generation.token)
810
954
 
@@ -823,8 +967,9 @@ failures (rate limits, provider 5xx, network errors) with backoff that honors `r
823
967
  `poll.timeout`; submits and cancels never retry. Interrupting a wait (or aborting its `signal`) does not cancel the
824
968
  provider job, which keeps running and billing: call `cancel()` to stop it. Failed,
825
969
  cancelled, and expired generations fail typed with the provider's terminal document on `reason.body`; moderation
826
- outcomes (Veo `raiMediaFilteredReasons`, xAI `respect_moderation`, Runway `SAFETY.*` codes) surface as `notices` when
827
- a video is still returned and as a `ContentPolicy` reason when nothing is.
970
+ outcomes (Veo `raiMediaFilteredReasons`, xAI `respect_moderation`, Runway `SAFETY.*` codes) fail with a
971
+ `ContentPolicy` reason when no video comes back; when one still does, Veo and xAI keep the raw outcome in
972
+ `providerMetadata`.
828
973
 
829
974
  Provider notes:
830
975
 
@@ -833,10 +978,7 @@ Provider notes:
833
978
  download, which the returned asset holds transiently (see above).
834
979
  - **xAI** sends a `video` input to `/videos/edits`, or `/videos/extensions` with `providerOptions.mode: "extend"`.
835
980
  `seed` and `negativePrompt` are not supported.
836
- - **fal** endpoints are model-specific: `durationSeconds`, `references`, and `frames.last` fail typed and belong in
837
- `providerOptions` under the model's own names (`duration: "8s"`, `end_image_url`, …). Auth is
838
- `Authorization: Key <FAL_KEY>`.
839
- - **Runway** expects pixel ratios in `aspectRatio` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
981
+ - **Runway** expects pixel ratios in `aspect` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
840
982
  `usage: { type: "credits" }`, and its output URLs expire after 24–48 hours.
841
983
 
842
984
  The promise client exposes the same surface: `ai.video.start(...)` resolves to a handle with `await`, `events`,
@@ -847,7 +989,7 @@ aborting rejects the Promise or throws from the `for await` loop with `signal.re
847
989
  unless `abort(reason)` passed one), while `break` stops a stream without throwing.
848
990
 
849
991
  ```ts
850
- import { ai } from "@opencode/ai/promise"
992
+ import { ai } from "@opencode/ai"
851
993
 
852
994
  const generation = await ai.video.start({ model, prompt })
853
995
  for await (const event of generation.events({ poll: { interval: 10_000 } })) console.log(event.type)
@@ -864,7 +1006,7 @@ selectors on the `OpenAI`, `Google` (Gemini TTS), `ElevenLabs`, `Cartesia`, and
864
1006
  before any network call; provider-native controls live under `providerOptions`, inferred from the selected model.
865
1007
 
866
1008
  ```ts
867
- import { Media, Speech, SpeechClient, SpeechEvent } from "@opencode/ai"
1009
+ import { Media, Speech, SpeechClient, SpeechEvent } from "@opencode/ai/effect"
868
1010
  import { ElevenLabs, OpenAI } from "@opencode/ai/providers"
869
1011
 
870
1012
  const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY })
@@ -929,7 +1071,7 @@ Provider notes:
929
1071
  The promise client mirrors the Effect API; `ai.speech.stream` is an `AsyncIterable`.
930
1072
 
931
1073
  ```ts
932
- import { ai } from "@opencode/ai/promise"
1074
+ import { ai } from "@opencode/ai"
933
1075
 
934
1076
  const response = await ai.speech.generate({ model, text: "Hello from OpenCode.", voice: "coral" })
935
1077
  await ai.write(response.audio, "hello.mp3")
@@ -951,7 +1093,7 @@ any network call; a route may return more than asked.
951
1093
 
952
1094
  ```ts
953
1095
  import { Console, Effect, Stream } from "effect"
954
- import { Media, Transcription, TranscriptionEvent } from "@opencode/ai"
1096
+ import { Media, Transcription, TranscriptionEvent } from "@opencode/ai/effect"
955
1097
  import { AssemblyAI, Deepgram, OpenAI } from "@opencode/ai/providers"
956
1098
 
957
1099
  const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY })
@@ -1012,8 +1154,11 @@ const transcript = await generation.await({ poll: { interval: 3_000 } })
1012
1154
 
1013
1155
  ## Public API
1014
1156
 
1157
+ Everything below is exported from `@opencode/ai/effect` unless noted.
1158
+
1015
1159
  - **`LLM.request({...})`** — build a provider-neutral `LLMRequest`. Accepts ergonomic inputs (`system: string`, `prompt: string`) that normalize into the canonical Schema classes.
1016
1160
  - **`LLM.generate` / `LLM.stream`** — run direct input or an `LLMRequest` through `LLMClient` for one-import use.
1161
+ - **`LLM.loop`** — stream model calls, running `Tool.make(...)` tools between them until the model stops calling tools.
1017
1162
  - **`Message.user(...)` / `Message.assistant(...)` / `Message.tool(...)`** — message constructors from the canonical schema model.
1018
1163
  - **`LanguageModel.make(...)` / `ToolCallPart.make(...)` / `ToolResultPart.make(...)` / `ToolDefinition.make(...)`** — model and tool-related constructors from the canonical schema model.
1019
1164
  - **`LLMEvent.is.*`** — typed guards (`is.textDelta`, `is.toolCall`, `is.finish`, …) for filtering streams.
@@ -1024,8 +1169,10 @@ const transcript = await generation.await({ poll: { interval: 3_000 } })
1024
1169
  - **`Video.request` / `generate` / `stream` / `start` / `resume`** — queued video generation through a provider-neutral request; `VideoClient` is its Effect service and layer.
1025
1170
  - **`Speech.request` / `Speech.generate` / `Speech.stream`** — text-to-speech through a provider-neutral request; `SpeechClient` is its Effect service and layer.
1026
1171
  - **`Transcription.request` / `generate` / `stream` / `start` / `resume`** — speech-to-text over inline, streaming, and queued routes; `TranscriptionClient` is its Effect service and layer.
1172
+ - **`Decision.request` / `Decision.generate`** — typed predicate, choice, and score questions over text, JSON, and media input; `DecisionClient` is its Effect service and layer.
1027
1173
  - **`AIClient.layer` / `AIClient.layerWith(executor)`** — every modality client plus the request executor in one layer.
1028
- - **`@opencode/ai/promise`** — `AI.make({ layer? })` and a default `ai` client exposing `llm`, `image`, `video`, `speech`, and `transcription` as Promise / `AsyncIterable` APIs, plus `file`, `write`, `bytes`, `base64`, and `materialize` for assets.
1174
+ - **`@opencode/ai`** (Promise root) — `AI.make({ layer?, clients? })` and a default `ai` client exposing `llm`, `image`, `video`, `speech`, `transcription`, and `decision` as Promise / `AsyncIterable` APIs, `run(effect)` for any package Effect, plus `file`, `write`, `bytes`, `base64`, and `materialize` for assets.
1175
+ - **`@opencode/ai/experimental`** — APIs that may still change: `Extraction` (typed values read out of text) and `Realtime` (`Realtime.connect` starts an OpenAI, xAI, or Gemini voice session and returns a WebRTC answer SDP or a short-lived WebSocket URL and token).
1029
1176
 
1030
1177
  ## Testing
1031
1178
 
@@ -1071,6 +1218,10 @@ For explicit compaction, script a `CompactionResponse` through `push`, `always`,
1071
1218
 
1072
1219
  For `compact(request, { mechanism: "trigger" })`, script a `CompactionCheckpointResponse` instead. It carries `checkpoint`, `responseID`, and optional `usage`. Endpoint and trigger calls reject each other's fixtures; both share the same queue, gates, lazy recording, and fallback controls.
1073
1220
 
1221
+ `TestImage`, `TestVideo`, `TestSpeech`, `TestTranscription`, and `TestDecision` follow the same pattern: `testLayer()` provides the modality's client and `Test`, with the same `push`, `always`, `serve`, `requests`, `wait`, and `gate` controls. Script an `ImageResponse` (or the modality's response) or an `AIError`. `stream` expands the response into its events, and `start` returns an already finished generation that `resume` accepts by token. Decision responses are returned as scripted, without checking the answers against the questions.
1222
+
1223
+ The Promise client accepts the same layers as `AI.make({ clients: TestImage.testLayer() })`; `ai.run(TestImage.Test.use(...))` reaches the controls.
1224
+
1074
1225
  The published legacy `Service`, `layer`, `clientLayer`, and module-level controls remain available as adapters
1075
1226
  over the same implementation, including the legacy live `requests` array. New tests should use `Test` and
1076
1227
  `testLayer`.
@@ -1097,6 +1248,8 @@ const compacted = Effect.gen(function* () {
1097
1248
  })
1098
1249
  ```
1099
1250
 
1251
+ From the Promise API, `await ai.llm.compact(request)` takes the same request and options (plus `signal`) and returns the same result.
1252
+
1100
1253
  `replacement` replaces the complete input window. Do not append it to the original transcript or extract only the encrypted item: the provider may retain additional messages in its output. Retained user and assistant messages remain ordinary messages with typed text, media, or reasoning parts, in their original order. Provider-specific message IDs, status, and phase use `providerMetadata`, not a raw output array hidden in an assistant message. Unsupported returned item types fail explicitly.
1101
1254
 
1102
1255
  The selected model carries explicit-compaction capability through request construction and updates. Calls using unsupported routes fail type checking. When the model is selected dynamically, narrow the request with `LLMClient.canCompact(request)` before calling `LLMClient.compact`; a model or route switch does not inherit the old capability. Runtime validation still rejects unsupported calls from untyped consumers. Capability describes the route's API, not whether every model or custom deployment supports the operation.
@@ -1150,7 +1303,7 @@ Enable OpenAI compaction with typed provider options:
1150
1303
 
1151
1304
  ```ts
1152
1305
  import { Effect } from "effect"
1153
- import { LLM, LLMClient, LLMRequest, Message } from "@opencode/ai"
1306
+ import { LLM, LLMClient, LLMRequest, Message } from "@opencode/ai/effect"
1154
1307
  import { OpenAI } from "@opencode/ai/providers"
1155
1308
 
1156
1309
  const request = LLM.request({
@@ -1173,7 +1326,7 @@ const continued = Effect.gen(function* () {
1173
1326
  A compaction part has `provider` and exactly one representation: `encrypted` for Responses, or `text` for Anthropic. Responses also preserves the optional checkpoint `id`. These fields survive message serialization without becoming visible assistant text. Sending a checkpoint to another provider or an incompatible API fails rather than silently losing context.
1174
1327
 
1175
1328
  ```ts
1176
- import { CompactionPart, ProviderID } from "@opencode/ai"
1329
+ import { CompactionPart, ProviderID } from "@opencode/ai/effect"
1177
1330
 
1178
1331
  CompactionPart.make({ provider: ProviderID.make("openai"), id: "cmp_123", encrypted: "..." })
1179
1332
  CompactionPart.make({ provider: ProviderID.make("anthropic"), text: "Summary of the conversation..." })
@@ -1244,13 +1397,33 @@ cache: {
1244
1397
  tools?: boolean,
1245
1398
  system?: boolean,
1246
1399
  messages?: "latest-user-message" | "latest-assistant" | { tail: number },
1247
- ttlSeconds?: number, // ≥ 3600 → 1h on Anthropic/Bedrock; else 5m
1400
+ ttl?: CacheTTL, // "5m", "30m", "1h", "12h", "24h", ...
1248
1401
  }
1249
1402
  ```
1250
1403
 
1404
+ An object with placement fields places exactly those breakpoints. An object with only `ttl` keeps automatic placement.
1405
+
1406
+ ### Cache lifetime
1407
+
1408
+ `ttl` is a duration in models.dev's format (`<number>` followed by `ms`, `s`, `m`, `h` or `d`). It is sent to the provider as given, so use one the provider accepts. Leaving it unset keeps the provider default.
1409
+
1410
+ ```ts
1411
+ LLM.request({ model, system, prompt, cache: { ttl: "1h" } })
1412
+ ```
1413
+
1414
+ | Protocol | How `ttl` is sent |
1415
+ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
1416
+ | Anthropic Messages family, Meta Messages | `ttl` on every `cache_control` marker |
1417
+ | Bedrock Converse | `ttl` on every `cachePoint`; older Claude releases that only cache for 5m drop `"1h"` |
1418
+ | OpenRouter, DigitalOcean, Alibaba Chat markers | `ttl` on every `cache_control` marker |
1419
+ | OpenAI Responses (OpenAI, Azure, Cloudflare AI Gateway) | `"24h"` → `prompt_cache_retention: "24h"`; anything else → `prompt_cache_options: { ttl }` |
1420
+ | Chat Completions without markers (OpenAI-compatible, Moonshot, DeepInfra) | same mapping as OpenAI Responses |
1421
+
1422
+ OpenAI's two fields cover different models: `prompt_cache_retention` (`"in_memory"` or `"24h"`) is the only control before GPT-5.6, and GPT-5.6+ reads `prompt_cache_options.ttl` (`"30m"` or `"12h"`). Sending `prompt_cache_options` to an older model returns a 400. `"in_memory"` is not a duration; send it with an HTTP body overlay.
1423
+
1251
1424
  ### Manual hints
1252
1425
 
1253
- Inline `CacheHint` on any text / system / tool / tool-result part overrides automatic placement. The auto policy preserves manual hints, counts them against Anthropic and Bedrock's four-breakpoint limit, and only fills the remaining slots.
1426
+ Inline `CacheHint` (`{ type: "ephemeral", ttl? }`) on any text / system / tool / tool-result part overrides automatic placement. The auto policy preserves manual hints, counts them against Anthropic and Bedrock's four-breakpoint limit, and only fills the remaining slots.
1254
1427
 
1255
1428
  ```ts
1256
1429
  LLM.request({
@@ -1283,12 +1456,12 @@ import { OpenAI, CloudflareAIGateway } from "@opencode/ai/providers"
1283
1456
 
1284
1457
  const openai = OpenAI.configure({ apiKey: process.env.OPENAI_API_KEY }).responses("gpt-4o-mini")
1285
1458
  const gateway = CloudflareAIGateway.configure({
1286
- accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
1459
+ accountId,
1287
1460
  gatewayApiKey: process.env.CLOUDFLARE_API_TOKEN,
1288
1461
  }).model("workers-ai/@cf/meta/llama-3.1-8b-instruct")
1289
1462
  ```
1290
1463
 
1291
- Included LLM providers: OpenAI, Anthropic, Google (Gemini), Google Vertex, Amazon Bedrock, Azure OpenAI, Baseten, Cerebras, Cohere, Cloudflare AI Gateway, Cloudflare Workers AI, DeepInfra, DeepSeek, Fireworks, Groq, Mistral, OpenRouter, TogetherAI, Vercel AI Gateway, and xAI. Z.ai currently exposes image generation. Generic Chat Completions, Responses, and Anthropic Messages-compatible entrypoints support custom endpoints.
1464
+ Included LLM providers: OpenAI, Anthropic, Google (Gemini), Google Vertex, Amazon Bedrock (Converse and Mantle), Azure OpenAI, Alibaba, Baseten, Cerebras, Cohere, Cloudflare AI Gateway, Cloudflare Workers AI, DeepInfra, DeepSeek, DigitalOcean, Fireworks, Groq, Meta, MiniMax, Mistral, Moonshot, OpenRouter, TogetherAI, Venice, Vercel AI Gateway, xAI, Z.ai, and Z.ai Coding Plan. TypeSafe AI and OpenCode expose decision models only. Generic Chat Completions, Responses, and Anthropic Messages-compatible entrypoints support custom endpoints.
1292
1465
 
1293
1466
  Each named provider owns its module, endpoint, authentication, and route setup. Providers with the same wire format compose the shared protocol directly:
1294
1467
 
@@ -1393,10 +1566,10 @@ Compose a route with `Route.make({ protocol, endpoint, auth, framing, ... })`. T
1393
1566
 
1394
1567
  ## Effect
1395
1568
 
1396
- This package is built on Effect. Public methods return `Effect` or `Stream`; provide `AIClient.layer` (or `AIClient.layerWith(executor)`) for every modality, then import the provider/protocol modules for the routes you use. The example at `example/tutorial.ts` is a runnable walkthrough.
1569
+ This package is built on Effect. Public methods in `@opencode/ai/effect` return `Effect` or `Stream`; provide `AIClient.layer` (or `AIClient.layerWith(executor)`) for every modality, then import the provider/protocol modules for the routes you use. The example at `example/tutorial.ts` is a runnable walkthrough.
1397
1570
 
1398
1571
  ## See also
1399
1572
 
1400
1573
  - `AGENTS.md` — architecture, route construction, contributor guide
1401
- - `example/tutorial.ts` — runnable end-to-end walkthrough
1574
+ - `example/tutorial.ts` — runnable end-to-end walkthrough (`bun example/tutorial.ts <example>`)
1402
1575
  - `test/provider/*.test.ts` — fixture-first protocol tests; `*.recorded.test.ts` files cover live cassettes