@opencode/ai 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/README.md +283 -114
  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 +13 -22
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +154 -324
  24. package/dist/image.js +4 -11
  25. package/dist/index.d.ts +1426 -34
  26. package/dist/index.js +127 -24
  27. package/dist/llm.d.ts +16 -1
  28. package/dist/llm.js +34 -0
  29. package/dist/media-client.d.ts +2 -1
  30. package/dist/media-model.d.ts +3 -0
  31. package/dist/media-model.js +4 -1
  32. package/dist/media.d.ts +0 -7
  33. package/dist/media.js +0 -6
  34. package/dist/protocols/alibaba-chat.d.ts +32 -12
  35. package/dist/protocols/alibaba-images.d.ts +22 -0
  36. package/dist/protocols/alibaba-images.js +77 -0
  37. package/dist/protocols/alibaba-messages.d.ts +62 -27
  38. package/dist/protocols/alibaba-responses.d.ts +41 -38
  39. package/dist/protocols/anthropic-messages.d.ts +196 -94
  40. package/dist/protocols/anthropic-messages.js +47 -16
  41. package/dist/protocols/bedrock-converse.d.ts +140 -47
  42. package/dist/protocols/bedrock-converse.js +114 -18
  43. package/dist/protocols/bedrock-event-stream.js +1 -0
  44. package/dist/protocols/bfl-images.d.ts +9 -0
  45. package/dist/protocols/bfl-images.js +17 -15
  46. package/dist/protocols/cartesia-speech.d.ts +32 -50
  47. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  48. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  49. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  50. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  51. package/dist/protocols/cohere-chat.d.ts +7 -8
  52. package/dist/protocols/deepgram-speech.d.ts +32 -50
  53. package/dist/protocols/elevenlabs-speech.d.ts +32 -50
  54. package/dist/protocols/fal-images.d.ts +10 -1
  55. package/dist/protocols/fal-images.js +16 -25
  56. package/dist/protocols/fal-video.js +1 -1
  57. package/dist/protocols/gemini.d.ts +37 -34
  58. package/dist/protocols/gemini.js +13 -8
  59. package/dist/protocols/google-images.d.ts +2 -2
  60. package/dist/protocols/google-images.js +8 -37
  61. package/dist/protocols/google-interactions.d.ts +18 -14
  62. package/dist/protocols/google-interactions.js +14 -7
  63. package/dist/protocols/google-speech.d.ts +32 -50
  64. package/dist/protocols/google-speech.js +0 -1
  65. package/dist/protocols/google-transcription.d.ts +32 -50
  66. package/dist/protocols/google-transcription.js +0 -1
  67. package/dist/protocols/google-video.d.ts +1 -1
  68. package/dist/protocols/google-video.js +2 -7
  69. package/dist/protocols/index.d.ts +3 -0
  70. package/dist/protocols/index.js +3 -0
  71. package/dist/protocols/meta-images.d.ts +7 -1
  72. package/dist/protocols/meta-images.js +10 -8
  73. package/dist/protocols/meta-messages.d.ts +73 -38
  74. package/dist/protocols/meta-messages.js +14 -1
  75. package/dist/protocols/meta-responses.d.ts +84 -78
  76. package/dist/protocols/meta-responses.js +29 -1
  77. package/dist/protocols/mistral-chat.d.ts +81 -78
  78. package/dist/protocols/mistral-chat.js +2 -1
  79. package/dist/protocols/open-responses-channel.js +47 -46
  80. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  81. package/dist/protocols/open-responses-continuation.js +3 -1
  82. package/dist/protocols/open-responses.d.ts +426 -396
  83. package/dist/protocols/open-responses.js +16 -25
  84. package/dist/protocols/openai-chat.d.ts +764 -52
  85. package/dist/protocols/openai-chat.js +38 -25
  86. package/dist/protocols/openai-compatible-chat.d.ts +35 -15
  87. package/dist/protocols/openai-compatible-responses.d.ts +44 -42
  88. package/dist/protocols/openai-decisions.d.ts +22 -0
  89. package/dist/protocols/openai-decisions.js +128 -0
  90. package/dist/protocols/openai-images.d.ts +53 -56
  91. package/dist/protocols/openai-images.js +100 -34
  92. package/dist/protocols/openai-responses.d.ts +322 -264
  93. package/dist/protocols/openai-responses.js +33 -3
  94. package/dist/protocols/openai-speech.d.ts +32 -50
  95. package/dist/protocols/openai-speech.js +15 -5
  96. package/dist/protocols/openai-transcription.d.ts +32 -50
  97. package/dist/protocols/openai-transcription.js +15 -11
  98. package/dist/protocols/replicate-images.js +1 -1
  99. package/dist/protocols/runway-video.d.ts +1 -1
  100. package/dist/protocols/runway-video.js +1 -1
  101. package/dist/protocols/shared.d.ts +9 -1
  102. package/dist/protocols/shared.js +13 -2
  103. package/dist/protocols/stability-images.d.ts +5 -0
  104. package/dist/protocols/stability-images.js +4 -9
  105. package/dist/protocols/system-one.d.ts +101 -0
  106. package/dist/protocols/system-one.js +230 -0
  107. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  108. package/dist/protocols/utils/bedrock-cache.js +7 -6
  109. package/dist/protocols/utils/cache.d.ts +14 -3
  110. package/dist/protocols/utils/cache.js +11 -4
  111. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  112. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  113. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  114. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  115. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  116. package/dist/protocols/utils/image-sizing.js +73 -0
  117. package/dist/protocols/utils/media-input.d.ts +4 -5
  118. package/dist/protocols/utils/media-input.js +8 -5
  119. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  120. package/dist/protocols/utils/partial-json-options.js +0 -1
  121. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  122. package/dist/protocols/utils/speech-stream.js +0 -1
  123. package/dist/protocols/utils/tool-schema.js +15 -5
  124. package/dist/protocols/utils/tool-stream.d.ts +10 -1
  125. package/dist/protocols/venice-chat.d.ts +71 -53
  126. package/dist/protocols/venice-chat.js +7 -6
  127. package/dist/protocols/xai-images.d.ts +1 -2
  128. package/dist/protocols/xai-images.js +9 -2
  129. package/dist/protocols/xai-responses.d.ts +88 -78
  130. package/dist/protocols/xai-responses.js +28 -2
  131. package/dist/protocols/xai-video.d.ts +1 -1
  132. package/dist/protocols/xai-video.js +11 -8
  133. package/dist/protocols/zai-chat.d.ts +54 -30
  134. package/dist/protocols/zai-chat.js +8 -3
  135. package/dist/protocols/zai-images.d.ts +3 -1
  136. package/dist/protocols/zai-images.js +12 -11
  137. package/dist/protocols/zai-messages.d.ts +72 -35
  138. package/dist/protocols/zai-messages.js +3 -2
  139. package/dist/provider-error.js +24 -7
  140. package/dist/providers/alibaba/images.d.ts +2 -0
  141. package/dist/providers/alibaba/images.js +1 -0
  142. package/dist/providers/alibaba.d.ts +146 -85
  143. package/dist/providers/alibaba.js +16 -8
  144. package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
  145. package/dist/providers/amazon-bedrock.d.ts +48 -28
  146. package/dist/providers/amazon-bedrock.js +11 -11
  147. package/dist/providers/anthropic-compatible.d.ts +64 -29
  148. package/dist/providers/anthropic.d.ts +64 -29
  149. package/dist/providers/azure/images.d.ts +2 -0
  150. package/dist/providers/azure/images.js +1 -0
  151. package/dist/providers/azure.d.ts +156 -115
  152. package/dist/providers/azure.js +19 -1
  153. package/dist/providers/baseten/decisions.d.ts +2 -0
  154. package/dist/providers/baseten/decisions.js +1 -0
  155. package/dist/providers/baseten.d.ts +75 -25
  156. package/dist/providers/baseten.js +41 -8
  157. package/dist/providers/cerebras.d.ts +66 -24
  158. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  159. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  160. package/dist/providers/cloudflare-ai-gateway.d.ts +409 -272
  161. package/dist/providers/cloudflare-ai-gateway.js +33 -6
  162. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  163. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  164. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  165. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  166. package/dist/providers/cloudflare-workers-ai.d.ts +79 -25
  167. package/dist/providers/cloudflare-workers-ai.js +45 -9
  168. package/dist/providers/cohere.d.ts +117 -75
  169. package/dist/providers/deepinfra.d.ts +66 -24
  170. package/dist/providers/deepseek.d.ts +66 -24
  171. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  172. package/dist/providers/digitalocean/decisions.js +1 -0
  173. package/dist/providers/digitalocean/images.d.ts +2 -0
  174. package/dist/providers/digitalocean/images.js +1 -0
  175. package/dist/providers/digitalocean.d.ts +108 -37
  176. package/dist/providers/digitalocean.js +39 -8
  177. package/dist/providers/fireworks.d.ts +66 -24
  178. package/dist/providers/google/images.d.ts +2 -0
  179. package/dist/providers/google/images.js +1 -0
  180. package/dist/providers/google-vertex/images.d.ts +2 -0
  181. package/dist/providers/google-vertex/images.js +1 -0
  182. package/dist/providers/google-vertex-chat.d.ts +33 -12
  183. package/dist/providers/google-vertex-messages.d.ts +64 -29
  184. package/dist/providers/google-vertex-mistral.d.ts +17 -17
  185. package/dist/providers/google-vertex-responses.d.ts +38 -35
  186. package/dist/providers/google-vertex.d.ts +20 -18
  187. package/dist/providers/google-vertex.js +32 -15
  188. package/dist/providers/google.d.ts +22 -21
  189. package/dist/providers/google.js +15 -8
  190. package/dist/providers/groq.d.ts +66 -28
  191. package/dist/providers/groq.js +0 -6
  192. package/dist/providers/meta.d.ts +144 -85
  193. package/dist/providers/minimax.d.ts +145 -86
  194. package/dist/providers/mistral.d.ts +28 -28
  195. package/dist/providers/moonshot.d.ts +277 -218
  196. package/dist/providers/open-responses-options.d.ts +0 -1
  197. package/dist/providers/open-responses-options.js +1 -1
  198. package/dist/providers/openai/images.d.ts +2 -0
  199. package/dist/providers/openai/images.js +1 -0
  200. package/dist/providers/openai-compatible/images.d.ts +2 -0
  201. package/dist/providers/openai-compatible/images.js +1 -0
  202. package/dist/providers/openai-compatible-responses.d.ts +38 -35
  203. package/dist/providers/openai-compatible.d.ts +36 -13
  204. package/dist/providers/openai-compatible.js +22 -10
  205. package/dist/providers/openai-options.d.ts +3 -2
  206. package/dist/providers/openai-options.js +0 -1
  207. package/dist/providers/openai.d.ts +146 -109
  208. package/dist/providers/openai.js +20 -4
  209. package/dist/providers/opencode/decisions.d.ts +2 -0
  210. package/dist/providers/opencode/decisions.js +1 -0
  211. package/dist/providers/opencode.d.ts +9 -10
  212. package/dist/providers/opencode.js +10 -8
  213. package/dist/providers/openrouter/decisions.d.ts +2 -0
  214. package/dist/providers/openrouter/decisions.js +1 -0
  215. package/dist/providers/openrouter/images.d.ts +2 -0
  216. package/dist/providers/openrouter/images.js +1 -0
  217. package/dist/providers/openrouter.d.ts +128 -47
  218. package/dist/providers/openrouter.js +38 -16
  219. package/dist/providers/togetherai.d.ts +66 -24
  220. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  221. package/dist/providers/typesafe-ai/decisions.js +1 -0
  222. package/dist/providers/typesafe-ai.d.ts +9 -10
  223. package/dist/providers/typesafe-ai.js +10 -8
  224. package/dist/providers/venice.d.ts +214 -20
  225. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  226. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  227. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  228. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  229. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  230. package/dist/providers/vercel-ai-gateway.js +31 -85
  231. package/dist/providers/xai/images.d.ts +2 -0
  232. package/dist/providers/xai/images.js +1 -0
  233. package/dist/providers/xai.d.ts +40 -17
  234. package/dist/providers/xai.js +15 -8
  235. package/dist/providers/zai/images.d.ts +2 -0
  236. package/dist/providers/zai/images.js +1 -0
  237. package/dist/providers/zai-coding-plan.d.ts +224 -85
  238. package/dist/providers/zai.d.ts +110 -23
  239. package/dist/providers/zai.js +15 -8
  240. package/dist/route/auth-options.d.ts +0 -3
  241. package/dist/route/auth.d.ts +0 -2
  242. package/dist/route/auth.js +0 -2
  243. package/dist/route/client.d.ts +2 -4
  244. package/dist/route/client.js +29 -8
  245. package/dist/route/decision.d.ts +58 -0
  246. package/dist/route/decision.js +75 -0
  247. package/dist/route/executor-service.js +1 -1
  248. package/dist/route/executor.d.ts +1 -1
  249. package/dist/route/framing.d.ts +2 -0
  250. package/dist/route/index.d.ts +3 -0
  251. package/dist/route/index.js +3 -0
  252. package/dist/route/media-protocol.d.ts +1 -0
  253. package/dist/route/media-protocol.js +12 -8
  254. package/dist/route/media.d.ts +5 -1
  255. package/dist/route/media.js +6 -2
  256. package/dist/route/transport/http.js +1 -0
  257. package/dist/route/transport/index.d.ts +1 -0
  258. package/dist/schema/events.d.ts +148 -6
  259. package/dist/schema/events.js +20 -0
  260. package/dist/schema/messages.d.ts +6 -2
  261. package/dist/schema/messages.js +3 -0
  262. package/dist/schema/options.d.ts +5 -3
  263. package/dist/schema/options.js +8 -3
  264. package/dist/speech-client.d.ts +13 -22
  265. package/dist/speech-client.js +0 -1
  266. package/dist/speech.d.ts +148 -283
  267. package/dist/speech.js +2 -4
  268. package/dist/testing.d.ts +25 -24
  269. package/dist/testing.js +3 -21
  270. package/dist/transcription-client.d.ts +13 -22
  271. package/dist/transcription.d.ts +148 -283
  272. package/dist/transcription.js +1 -1
  273. package/dist/utils/media-type.js +22 -1
  274. package/dist/video-client.d.ts +13 -22
  275. package/dist/video-client.js +0 -1
  276. package/dist/video.d.ts +115 -250
  277. package/dist/video.js +3 -5
  278. package/package.json +516 -13
  279. package/dist/experimental/evaluation-client.d.ts +0 -21
  280. package/dist/experimental/evaluation-client.js +0 -64
  281. package/dist/experimental/evaluation.d.ts +0 -242
  282. package/dist/experimental/evaluation.js +0 -115
  283. package/dist/experimental/system-one.d.ts +0 -16
  284. package/dist/experimental/system-one.js +0 -135
  285. package/dist/promise.d.ts +0 -1021
  286. package/dist/promise.js +0 -101
  287. package/dist/provider.d.ts +0 -23
  288. package/dist/provider.js +0 -2
@@ -8,7 +8,7 @@ import { Framing } from "../route/framing.js";
8
8
  import { Protocol } from "../route/protocol.js";
9
9
  import { Headers } from "effect/http";
10
10
  import { HttpTransport } from "../route/transport/index.js";
11
- import { AIError, HttpOptions, LLMRequest, LLMEvent, mergeJsonRecords, Usage, } from "../schema/index.js";
11
+ import { AIError, CacheTTL, HttpOptions, LLMRequest, LLMEvent, mergeJsonRecords, Usage, } from "../schema/index.js";
12
12
  import { JsonObject, knownString, optionalArray, optionalNull, ProviderShared, withUntypedFrames } from "./shared.js";
13
13
  import { classifyProviderFailure } from "../provider-error.js";
14
14
  import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js";
@@ -50,9 +50,10 @@ export const ContextManagement = Schema.Struct({
50
50
  // =============================================================================
51
51
  const AnthropicCacheControl = Schema.Struct({
52
52
  type: Schema.tag("ephemeral"),
53
- ttl: Schema.optional(Schema.Literals(["5m", "1h"])),
53
+ ttl: Schema.optional(CacheTTL),
54
54
  });
55
55
  const AnthropicServiceTier = knownString();
56
+ const AnthropicSpeed = knownString();
56
57
  const AnthropicTextBlock = Schema.Struct({
57
58
  type: Schema.tag("text"),
58
59
  text: Schema.String,
@@ -81,6 +82,11 @@ const AnthropicImageBlock = Schema.Struct({
81
82
  cache_control: Schema.optional(AnthropicCacheControl),
82
83
  transformations: Schema.optional(AnthropicImageTransformations),
83
84
  });
85
+ const AnthropicVideoBlock = Schema.Struct({
86
+ type: Schema.tag("video"),
87
+ source: AnthropicImageSource,
88
+ cache_control: Schema.optional(AnthropicCacheControl),
89
+ });
84
90
  // SDK: Base64PDFSource:209 {type:"base64", media_type:"application/pdf", data}, PlainTextSource:2716 {type:"text", media_type:"text/plain", data},
85
91
  // SDK: URLPDFSource:3823 {type:"url", url}, FileDocumentSource:2344 {type:"file", file_id}, ContentBlockSource:2266 {type:"content", content}
86
92
  // SDK: DocumentBlockParam:2297 {source: 5-way union, cache_control, citations, context, title}
@@ -157,7 +163,12 @@ const AnthropicServerToolResultBlock = Schema.Struct({
157
163
  // Anthropic accepts either a plain string or an ordered array of text, image, and
158
164
  // document blocks inside `tool_result.content`. The array form keeps media as native
159
165
  // model input instead of JSON-stringifying base64 into prompt text.
160
- const AnthropicToolResultContent = Schema.Union([AnthropicTextBlock, AnthropicImageBlock, AnthropicDocumentBlock]);
166
+ const AnthropicToolResultContent = Schema.Union([
167
+ AnthropicTextBlock,
168
+ AnthropicImageBlock,
169
+ AnthropicDocumentBlock,
170
+ AnthropicVideoBlock,
171
+ ]);
161
172
  const AnthropicToolResultBlock = Schema.Struct({
162
173
  type: Schema.tag("tool_result"),
163
174
  tool_use_id: Schema.String,
@@ -169,6 +180,7 @@ const AnthropicUserBlock = Schema.Union([
169
180
  AnthropicTextBlock,
170
181
  AnthropicImageBlock,
171
182
  AnthropicDocumentBlock,
183
+ AnthropicVideoBlock,
172
184
  AnthropicToolResultBlock,
173
185
  ]);
174
186
  const AnthropicCompactionBlock = Schema.Struct({
@@ -276,6 +288,7 @@ const Options = Schema.Struct({
276
288
  effort: Schema.optional(Schema.String),
277
289
  service_tier: Schema.optional(AnthropicServiceTier),
278
290
  serviceTier: Schema.optional(AnthropicServiceTier),
291
+ speed: Schema.optional(AnthropicSpeed),
279
292
  metadata: Schema.optional(AnthropicMetadata),
280
293
  container: Schema.optional(AnthropicContainer),
281
294
  inference_geo: optionalNull(Schema.String),
@@ -314,6 +327,7 @@ const AnthropicBodyFields = {
314
327
  inference_geo: Schema.optional(Schema.NullOr(Schema.String)),
315
328
  metadata: Schema.optional(AnthropicMetadata),
316
329
  service_tier: Schema.optional(AnthropicServiceTier),
330
+ speed: Schema.optional(AnthropicSpeed),
317
331
  };
318
332
  export const AnthropicMessagesBody = Schema.Struct(AnthropicBodyFields);
319
333
  const AnthropicIterationUsage = Schema.StructWithRest(Schema.Struct({
@@ -385,8 +399,6 @@ const invalid = ProviderShared.invalidRequest;
385
399
  // 400 — so the lowering layer counts emitted markers and silently drops any
386
400
  // that exceed it.
387
401
  const ANTHROPIC_BREAKPOINT_CAP = 4;
388
- const EPHEMERAL_5M = { type: "ephemeral" };
389
- const EPHEMERAL_1H = { type: "ephemeral", ttl: "1h" };
390
402
  const cacheControl = (breakpoints, cache) => {
391
403
  if (cache?.type !== "ephemeral" && cache?.type !== "persistent")
392
404
  return undefined;
@@ -395,7 +407,7 @@ const cacheControl = (breakpoints, cache) => {
395
407
  return undefined;
396
408
  }
397
409
  breakpoints.remaining -= 1;
398
- return Cache.ttlBucket(cache.ttlSeconds) === "1h" ? EPHEMERAL_1H : EPHEMERAL_5M;
410
+ return { type: "ephemeral", ...(cache.ttl === undefined ? {} : { ttl: cache.ttl }) };
399
411
  };
400
412
  const providerMetadata = (key, metadata) => ({ [key]: metadata });
401
413
  const signatureFromMetadata = (metadata, key) => {
@@ -539,9 +551,22 @@ const citationsFromMetadata = (metadata) => {
539
551
  return undefined;
540
552
  };
541
553
  const isHttpUrl = (value) => /^https?:\/\//i.test(value.trim());
542
- const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
554
+ const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
543
555
  const mime = part.media.mediaType.toLowerCase();
544
556
  const cacheControlValue = breakpoints ? cacheControl(breakpoints, part.cache) : undefined;
557
+ if (mime.startsWith("video/")) {
558
+ const inline = part.media.inline();
559
+ const source = inline
560
+ ? { type: "base64", media_type: mime, data: inline.base64 }
561
+ : yield* ProviderShared.mediaReference(part.media, request.model.provider, "Messages video").pipe(Effect.map((reference) => reference.type === "ref" && !reference.value.includes("://")
562
+ ? { type: "file", file_id: reference.value }
563
+ : { type: "url", url: reference.value }));
564
+ return {
565
+ type: "video",
566
+ source,
567
+ ...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
568
+ };
569
+ }
545
570
  const fileId = fileIdFromMetadata(part.metadata);
546
571
  // SDK file sources: FileImageSource:2350 / FileDocumentSource:2344 {type:"file", file_id}
547
572
  if (fileId) {
@@ -644,19 +669,19 @@ const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
644
669
  });
645
670
  // Tool results may carry structured text, images, and documents. Keep media as provider-native
646
671
  // content instead of JSON-stringifying base64 into a prompt string.
647
- const lowerToolResultContentItem = Effect.fnUntraced(function* (item) {
672
+ const lowerToolResultContentItem = Effect.fnUntraced(function* (item, request) {
648
673
  if (item.type === "text")
649
674
  return { type: "text", text: item.text };
650
- return yield* lowerMedia(ProviderShared.toolFileMedia(item));
675
+ return yield* lowerMedia(ProviderShared.toolFileMedia(item), request);
651
676
  });
652
- const lowerToolResultContent = Effect.fnUntraced(function* (part) {
677
+ const lowerToolResultContent = Effect.fnUntraced(function* (part, request) {
653
678
  // Text / json / error results stay as a string for backward compatibility
654
679
  // with existing cassettes and provider expectations.
655
680
  if (part.result.type !== "content")
656
681
  return ProviderShared.toolResultText(part);
657
682
  // Preserve the narrowed array element type when compiled through a consumer package.
658
683
  const content = part.result.value;
659
- return yield* Effect.forEach(content, lowerToolResultContentItem);
684
+ return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request));
660
685
  });
661
686
  const requireThinkingSignature = (request) => {
662
687
  if (request.model.compatibility?.requireSignature !== undefined)
@@ -678,7 +703,7 @@ const requireThinkingSignature = (request) => {
678
703
  };
679
704
  // Opus 4.8 and every Claude 5 model accept mid-conversation system messages; later versions inherit support.
680
705
  const supportsNativeSystemUpdates = (request) => {
681
- const version = claudeVersion(String(request.model.id));
706
+ const version = claudeVersion(request.model.id);
682
707
  if (version === undefined)
683
708
  return false;
684
709
  if (version.family === "opus" && version.major === 4)
@@ -723,7 +748,7 @@ const appendToUserTurn = (messages, block) => {
723
748
  };
724
749
  const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
725
750
  const messages = [];
726
- const providerMetadataKey = request.model.route.providerMetadataKey ?? String(request.model.provider);
751
+ const providerMetadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
727
752
  // Text updates stay where they are unless a user turn follows them; then they move after the latest
728
753
  // user turn, the nearest spot where Anthropic accepts a native system message.
729
754
  const holdUpdates = supportsNativeSystemUpdates(request);
@@ -763,7 +788,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
763
788
  continue;
764
789
  }
765
790
  if (part.type === "media") {
766
- content.push(yield* lowerMedia(part, breakpoints));
791
+ content.push(yield* lowerMedia(part, request, breakpoints));
767
792
  continue;
768
793
  }
769
794
  return yield* ProviderShared.unsupportedContent("Anthropic Messages", "user", ["text", "media"]);
@@ -839,7 +864,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
839
864
  content.push({
840
865
  type: "tool_result",
841
866
  tool_use_id: scrubToolCallID(part.id),
842
- content: yield* lowerToolResultContent(part),
867
+ content: yield* lowerToolResultContent(part, request),
843
868
  is_error: part.result.type === "error" ? true : undefined,
844
869
  cache_control: cacheControl(breakpoints, part.cache),
845
870
  });
@@ -940,6 +965,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
940
965
  inference_geo: options.inference_geo ?? options.inferenceGeo ?? undefined,
941
966
  metadata: options.metadata,
942
967
  service_tier: options.service_tier ?? options.serviceTier,
968
+ speed: options.speed,
943
969
  };
944
970
  if (!management)
945
971
  return body;
@@ -996,6 +1022,7 @@ const mapUsage = (usage, providerMetadataKey) => {
996
1022
  cacheWriteInputTokens: cacheWrite,
997
1023
  reasoningTokens: ProviderShared.sumTokens(...iterations.map((item) => item.output_tokens_details?.thinking_tokens)),
998
1024
  totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
1025
+ ...ProviderShared.reportedBilling(usage),
999
1026
  providerMetadata: { [providerMetadataKey]: usage },
1000
1027
  });
1001
1028
  };
@@ -1024,6 +1051,7 @@ const mergeUsage = (left, right, providerMetadataKey) => {
1024
1051
  cacheWriteInputTokens,
1025
1052
  reasoningTokens,
1026
1053
  totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
1054
+ cost: right.cost ?? left.cost,
1027
1055
  providerMetadata: {
1028
1056
  [providerMetadataKey]: mergeJsonRecords(left.providerMetadata?.[providerMetadataKey], right.providerMetadata?.[providerMetadataKey]) ??
1029
1057
  {},
@@ -1385,7 +1413,7 @@ export const protocol = Protocol.make({
1385
1413
  initial: (request) => ({
1386
1414
  provider: request.model.provider,
1387
1415
  compactions: {},
1388
- providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
1416
+ providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
1389
1417
  tools: ToolStream.empty(),
1390
1418
  reasoningSignatures: {},
1391
1419
  lifecycle: Lifecycle.initial(),
@@ -1431,6 +1459,9 @@ function requiredBetaHeaders(body) {
1431
1459
  betas.push("compact-2026-01-12");
1432
1460
  if (body.messages.some((message) => message.role === "system" && message.output_config !== undefined))
1433
1461
  betas.push("mid-conversation-output-config-2026-07-01");
1462
+ // Opus 5.5 accepts `speed` without this header; earlier fast-mode models reject `speed` without it.
1463
+ if (body.speed !== undefined)
1464
+ betas.push("fast-mode-2026-02-01");
1434
1465
  const thinking = body.thinking;
1435
1466
  if (thinking && !isThinkingOff(thinking) && thinking.block_binding)
1436
1467
  betas.push(THINKING_BINDING_BETA);
@@ -1,8 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
- import { Usage, type FinishReasonDetails } from "../schema/index.js";
5
- import { BedrockAuth } from "./utils/bedrock-auth.js";
4
+ import { Usage, type FinishReasonDetails, type ProviderOptions } from "../schema/index.js";
6
5
  import { Lifecycle } from "./utils/lifecycle.js";
7
6
  import { ToolStream } from "./utils/tool-stream.js";
8
7
  export type { Credentials as BedrockCredentials } from "./utils/bedrock-auth.js";
@@ -55,7 +54,7 @@ declare const BedrockConverseBody: Schema.Struct<{
55
54
  }>, Schema.Struct<{
56
55
  readonly cachePoint: Schema.Struct<{
57
56
  readonly type: Schema.tag<"default">;
58
- readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
57
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
59
58
  }>;
60
59
  }>]>>;
61
60
  }>, Schema.Struct<{
@@ -80,7 +79,7 @@ declare const BedrockConverseBody: Schema.Struct<{
80
79
  }>, Schema.Struct<{
81
80
  readonly cachePoint: Schema.Struct<{
82
81
  readonly type: Schema.tag<"default">;
83
- readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
82
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
84
83
  }>;
85
84
  }>]>>;
86
85
  }>]>>;
@@ -89,7 +88,7 @@ declare const BedrockConverseBody: Schema.Struct<{
89
88
  }>, Schema.Struct<{
90
89
  readonly cachePoint: Schema.Struct<{
91
90
  readonly type: Schema.tag<"default">;
92
- readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
91
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
93
92
  }>;
94
93
  }>]>>>;
95
94
  inferenceConfig: Schema.optional<Schema.Struct<{
@@ -110,7 +109,7 @@ declare const BedrockConverseBody: Schema.Struct<{
110
109
  }>, Schema.Struct<{
111
110
  readonly cachePoint: Schema.Struct<{
112
111
  readonly type: Schema.tag<"default">;
113
- readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
112
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
114
113
  }>;
115
114
  }>]>>;
116
115
  readonly toolChoice: Schema.optional<Schema.Union<readonly [Schema.Struct<{
@@ -124,15 +123,62 @@ declare const BedrockConverseBody: Schema.Struct<{
124
123
  }>]>>;
125
124
  }>>;
126
125
  additionalModelRequestFields: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
126
+ serviceTier: Schema.optional<Schema.Struct<{
127
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">, import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">>;
128
+ }>>;
129
+ guardrailConfig: Schema.optional<Schema.Struct<{
130
+ readonly guardrailIdentifier: Schema.String;
131
+ readonly guardrailVersion: Schema.String;
132
+ readonly trace: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">, import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">>>;
133
+ readonly streamProcessingMode: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"async" | "sync">, import("../schema/options.js").OpenString<"async" | "sync">>>;
134
+ }>>;
135
+ outputConfig: Schema.optional<Schema.Struct<{
136
+ readonly textFormat: Schema.Struct<{
137
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_schema">, import("../schema/options.js").OpenString<"json_schema">>;
138
+ readonly structure: Schema.Struct<{
139
+ readonly jsonSchema: Schema.Struct<{
140
+ readonly schema: Schema.String;
141
+ readonly name: Schema.optional<Schema.String>;
142
+ readonly description: Schema.optional<Schema.String>;
143
+ }>;
144
+ }>;
145
+ }>;
146
+ }>>;
147
+ requestMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
127
148
  }>;
128
149
  export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>;
129
150
  declare const Options: Schema.Struct<{
130
- readonly thinking: Schema.optional<Schema.Struct<{
151
+ /** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
152
+ readonly thinking: Schema.optional<Schema.Union<readonly [Schema.Struct<{
131
153
  readonly type: Schema.Literal<"enabled">;
132
154
  readonly budgetTokens: Schema.Number;
155
+ }>, Schema.Struct<{
156
+ readonly type: Schema.Literal<"adaptive">;
157
+ readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"omitted" | "summarized">, import("../schema/options.js").OpenString<"omitted" | "summarized">>>;
158
+ }>, Schema.Struct<{
159
+ readonly type: Schema.Literal<"disabled">;
160
+ }>]>>;
161
+ /** Reasoning effort, sent in the field each model family reads. */
162
+ readonly effort: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "max" | "medium" | "xhigh">, import("../schema/options.js").OpenString<"high" | "low" | "max" | "medium" | "xhigh">>>;
163
+ readonly serviceTier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">, import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">>>;
164
+ /** Constrains the response text to a JSON schema. */
165
+ readonly outputFormat: Schema.optional<Schema.Struct<{
166
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_schema">, import("../schema/options.js").OpenString<"json_schema">>;
167
+ readonly schema: Schema.$Record<Schema.String, Schema.Unknown>;
168
+ readonly name: Schema.optional<Schema.String>;
169
+ readonly description: Schema.optional<Schema.String>;
133
170
  }>>;
171
+ readonly guardrail: Schema.optional<Schema.Struct<{
172
+ readonly identifier: Schema.String;
173
+ readonly version: Schema.String;
174
+ readonly trace: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">, import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">>>;
175
+ readonly streamProcessingMode: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"async" | "sync">, import("../schema/options.js").OpenString<"async" | "sync">>>;
176
+ }>>;
177
+ /** Key-value pairs for filtering invocation logs. */
178
+ readonly requestMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
134
179
  }>;
135
- export type OptionsInput = typeof Options.Type;
180
+ /** Caller-facing provider options; unknown keys are accepted and ignored. */
181
+ export type OptionsInput = ProviderOptions & typeof Options.Encoded;
136
182
  /**
137
183
  * The Bedrock Converse protocol — request body construction, body schema, and
138
184
  * the streaming-event state machine.
@@ -144,7 +190,22 @@ export declare const protocol: Protocol<{
144
190
  readonly content: readonly ({
145
191
  readonly cachePoint: {
146
192
  readonly type: "default";
147
- readonly ttl?: "1h" | "5m" | undefined;
193
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
194
+ };
195
+ } | {
196
+ readonly image: {
197
+ readonly format: "gif" | "jpeg" | "png" | "webp";
198
+ readonly source: {
199
+ readonly bytes: string;
200
+ };
201
+ };
202
+ } | {
203
+ readonly document: {
204
+ readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
205
+ readonly name: string;
206
+ readonly source: {
207
+ readonly bytes: string;
208
+ };
148
209
  };
149
210
  } | {
150
211
  readonly text: string;
@@ -173,28 +234,13 @@ export declare const protocol: Protocol<{
173
234
  })[];
174
235
  readonly status?: "error" | "success" | undefined;
175
236
  };
176
- } | {
177
- readonly image: {
178
- readonly format: "gif" | "jpeg" | "png" | "webp";
179
- readonly source: {
180
- readonly bytes: string;
181
- };
182
- };
183
- } | {
184
- readonly document: {
185
- readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
186
- readonly name: string;
187
- readonly source: {
188
- readonly bytes: string;
189
- };
190
- };
191
237
  })[];
192
238
  } | {
193
239
  readonly role: "assistant";
194
240
  readonly content: readonly ({
195
241
  readonly cachePoint: {
196
242
  readonly type: "default";
197
- readonly ttl?: "1h" | "5m" | undefined;
243
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
198
244
  };
199
245
  } | {
200
246
  readonly text: string;
@@ -218,7 +264,7 @@ export declare const protocol: Protocol<{
218
264
  readonly system?: readonly ({
219
265
  readonly cachePoint: {
220
266
  readonly type: "default";
221
- readonly ttl?: "1h" | "5m" | undefined;
267
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
222
268
  };
223
269
  } | {
224
270
  readonly text: string;
@@ -233,7 +279,7 @@ export declare const protocol: Protocol<{
233
279
  readonly tools: readonly ({
234
280
  readonly cachePoint: {
235
281
  readonly type: "default";
236
- readonly ttl?: "1h" | "5m" | undefined;
282
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
237
283
  };
238
284
  } | {
239
285
  readonly toolSpec: {
@@ -259,6 +305,30 @@ export declare const protocol: Protocol<{
259
305
  readonly additionalModelRequestFields?: {
260
306
  readonly [x: string]: unknown;
261
307
  } | undefined;
308
+ readonly serviceTier?: {
309
+ readonly type: import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">;
310
+ } | undefined;
311
+ readonly guardrailConfig?: {
312
+ readonly guardrailIdentifier: string;
313
+ readonly guardrailVersion: string;
314
+ readonly trace?: import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full"> | undefined;
315
+ readonly streamProcessingMode?: import("../schema/options.js").OpenString<"async" | "sync"> | undefined;
316
+ } | undefined;
317
+ readonly outputConfig?: {
318
+ readonly textFormat: {
319
+ readonly type: import("../schema/options.js").OpenString<"json_schema">;
320
+ readonly structure: {
321
+ readonly jsonSchema: {
322
+ readonly schema: string;
323
+ readonly name?: string | undefined;
324
+ readonly description?: string | undefined;
325
+ };
326
+ };
327
+ };
328
+ } | undefined;
329
+ readonly requestMetadata?: {
330
+ readonly [x: string]: string;
331
+ } | undefined;
262
332
  }, {
263
333
  readonly [x: string]: unknown;
264
334
  readonly rawBody: string;
@@ -332,7 +402,22 @@ export declare const route: Route<{
332
402
  readonly content: readonly ({
333
403
  readonly cachePoint: {
334
404
  readonly type: "default";
335
- readonly ttl?: "1h" | "5m" | undefined;
405
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
406
+ };
407
+ } | {
408
+ readonly image: {
409
+ readonly format: "gif" | "jpeg" | "png" | "webp";
410
+ readonly source: {
411
+ readonly bytes: string;
412
+ };
413
+ };
414
+ } | {
415
+ readonly document: {
416
+ readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
417
+ readonly name: string;
418
+ readonly source: {
419
+ readonly bytes: string;
420
+ };
336
421
  };
337
422
  } | {
338
423
  readonly text: string;
@@ -361,28 +446,13 @@ export declare const route: Route<{
361
446
  })[];
362
447
  readonly status?: "error" | "success" | undefined;
363
448
  };
364
- } | {
365
- readonly image: {
366
- readonly format: "gif" | "jpeg" | "png" | "webp";
367
- readonly source: {
368
- readonly bytes: string;
369
- };
370
- };
371
- } | {
372
- readonly document: {
373
- readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
374
- readonly name: string;
375
- readonly source: {
376
- readonly bytes: string;
377
- };
378
- };
379
449
  })[];
380
450
  } | {
381
451
  readonly role: "assistant";
382
452
  readonly content: readonly ({
383
453
  readonly cachePoint: {
384
454
  readonly type: "default";
385
- readonly ttl?: "1h" | "5m" | undefined;
455
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
386
456
  };
387
457
  } | {
388
458
  readonly text: string;
@@ -406,7 +476,7 @@ export declare const route: Route<{
406
476
  readonly system?: readonly ({
407
477
  readonly cachePoint: {
408
478
  readonly type: "default";
409
- readonly ttl?: "1h" | "5m" | undefined;
479
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
410
480
  };
411
481
  } | {
412
482
  readonly text: string;
@@ -421,7 +491,7 @@ export declare const route: Route<{
421
491
  readonly tools: readonly ({
422
492
  readonly cachePoint: {
423
493
  readonly type: "default";
424
- readonly ttl?: "1h" | "5m" | undefined;
494
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
425
495
  };
426
496
  } | {
427
497
  readonly toolSpec: {
@@ -447,9 +517,32 @@ export declare const route: Route<{
447
517
  readonly additionalModelRequestFields?: {
448
518
  readonly [x: string]: unknown;
449
519
  } | undefined;
520
+ readonly serviceTier?: {
521
+ readonly type: import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">;
522
+ } | undefined;
523
+ readonly guardrailConfig?: {
524
+ readonly guardrailIdentifier: string;
525
+ readonly guardrailVersion: string;
526
+ readonly trace?: import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full"> | undefined;
527
+ readonly streamProcessingMode?: import("../schema/options.js").OpenString<"async" | "sync"> | undefined;
528
+ } | undefined;
529
+ readonly outputConfig?: {
530
+ readonly textFormat: {
531
+ readonly type: import("../schema/options.js").OpenString<"json_schema">;
532
+ readonly structure: {
533
+ readonly jsonSchema: {
534
+ readonly schema: string;
535
+ readonly name?: string | undefined;
536
+ readonly description?: string | undefined;
537
+ };
538
+ };
539
+ };
540
+ } | undefined;
541
+ readonly requestMetadata?: {
542
+ readonly [x: string]: string;
543
+ } | undefined;
450
544
  }, import("../route/transport/http.js").HttpPrepared<{
451
545
  readonly [x: string]: unknown;
452
546
  readonly rawBody: string;
453
547
  }>, import("../route/client.js").CompactionOperations | undefined>;
454
- export declare const sigV4Auth: typeof BedrockAuth.sigV4;
455
548
  export * as BedrockConverse from "./bedrock-converse.js";