@opencode/ai 2.1.4 → 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 (269) 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 +5 -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 +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 +20 -0
  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 +52 -17
  38. package/dist/protocols/alibaba-responses.d.ts +6 -3
  39. package/dist/protocols/anthropic-messages.d.ts +160 -54
  40. package/dist/protocols/anthropic-messages.js +44 -13
  41. package/dist/protocols/bedrock-converse.d.ts +110 -15
  42. package/dist/protocols/bedrock-converse.js +112 -15
  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 +0 -18
  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/deepgram-speech.d.ts +0 -18
  52. package/dist/protocols/elevenlabs-speech.d.ts +0 -18
  53. package/dist/protocols/fal-images.d.ts +10 -1
  54. package/dist/protocols/fal-images.js +16 -25
  55. package/dist/protocols/fal-video.js +1 -1
  56. package/dist/protocols/gemini.d.ts +3 -0
  57. package/dist/protocols/gemini.js +11 -6
  58. package/dist/protocols/google-images.d.ts +2 -2
  59. package/dist/protocols/google-images.js +8 -37
  60. package/dist/protocols/google-interactions.d.ts +4 -0
  61. package/dist/protocols/google-interactions.js +12 -5
  62. package/dist/protocols/google-speech.d.ts +0 -18
  63. package/dist/protocols/google-speech.js +0 -1
  64. package/dist/protocols/google-transcription.d.ts +0 -18
  65. package/dist/protocols/google-transcription.js +0 -1
  66. package/dist/protocols/google-video.d.ts +1 -1
  67. package/dist/protocols/google-video.js +2 -7
  68. package/dist/protocols/index.d.ts +3 -0
  69. package/dist/protocols/index.js +3 -0
  70. package/dist/protocols/meta-images.d.ts +7 -1
  71. package/dist/protocols/meta-images.js +10 -8
  72. package/dist/protocols/meta-messages.d.ts +52 -17
  73. package/dist/protocols/meta-messages.js +14 -1
  74. package/dist/protocols/meta-responses.d.ts +6 -0
  75. package/dist/protocols/meta-responses.js +29 -1
  76. package/dist/protocols/open-responses.d.ts +30 -0
  77. package/dist/protocols/open-responses.js +8 -18
  78. package/dist/protocols/openai-chat.d.ts +713 -1
  79. package/dist/protocols/openai-chat.js +35 -22
  80. package/dist/protocols/openai-compatible-chat.d.ts +22 -1
  81. package/dist/protocols/openai-compatible-responses.d.ts +8 -5
  82. package/dist/protocols/openai-decisions.d.ts +22 -0
  83. package/dist/protocols/openai-decisions.js +128 -0
  84. package/dist/protocols/openai-images.d.ts +21 -24
  85. package/dist/protocols/openai-images.js +100 -34
  86. package/dist/protocols/openai-responses.d.ts +82 -24
  87. package/dist/protocols/openai-responses.js +32 -2
  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/replicate-images.js +1 -1
  93. package/dist/protocols/runway-video.d.ts +1 -1
  94. package/dist/protocols/runway-video.js +1 -1
  95. package/dist/protocols/shared.d.ts +9 -1
  96. package/dist/protocols/shared.js +13 -2
  97. package/dist/protocols/stability-images.d.ts +5 -0
  98. package/dist/protocols/stability-images.js +4 -9
  99. package/dist/protocols/system-one.d.ts +101 -0
  100. package/dist/protocols/system-one.js +230 -0
  101. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  102. package/dist/protocols/utils/bedrock-cache.js +7 -6
  103. package/dist/protocols/utils/cache.d.ts +14 -3
  104. package/dist/protocols/utils/cache.js +11 -4
  105. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  106. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  107. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  108. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  109. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  110. package/dist/protocols/utils/image-sizing.js +73 -0
  111. package/dist/protocols/utils/media-input.d.ts +4 -5
  112. package/dist/protocols/utils/media-input.js +8 -5
  113. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  114. package/dist/protocols/utils/speech-stream.js +0 -1
  115. package/dist/protocols/utils/tool-schema.js +15 -5
  116. package/dist/protocols/utils/tool-stream.d.ts +9 -0
  117. package/dist/protocols/venice-chat.d.ts +19 -0
  118. package/dist/protocols/venice-chat.js +1 -1
  119. package/dist/protocols/xai-images.d.ts +1 -2
  120. package/dist/protocols/xai-images.js +9 -2
  121. package/dist/protocols/xai-responses.d.ts +10 -0
  122. package/dist/protocols/xai-responses.js +28 -2
  123. package/dist/protocols/xai-video.d.ts +1 -1
  124. package/dist/protocols/xai-video.js +11 -8
  125. package/dist/protocols/zai-chat.d.ts +21 -0
  126. package/dist/protocols/zai-images.d.ts +3 -1
  127. package/dist/protocols/zai-images.js +12 -11
  128. package/dist/protocols/zai-messages.d.ts +52 -17
  129. package/dist/provider-error.js +19 -4
  130. package/dist/providers/alibaba/images.d.ts +2 -0
  131. package/dist/providers/alibaba/images.js +1 -0
  132. package/dist/providers/alibaba.d.ts +79 -18
  133. package/dist/providers/alibaba.js +16 -8
  134. package/dist/providers/amazon-bedrock-mantle.d.ts +197 -138
  135. package/dist/providers/amazon-bedrock.d.ts +34 -14
  136. package/dist/providers/amazon-bedrock.js +11 -11
  137. package/dist/providers/anthropic-compatible.d.ts +52 -17
  138. package/dist/providers/anthropic.d.ts +52 -17
  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 +50 -9
  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 +51 -1
  146. package/dist/providers/baseten.js +41 -8
  147. package/dist/providers/cerebras.d.ts +42 -0
  148. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  149. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  150. package/dist/providers/cloudflare-ai-gateway.d.ts +177 -43
  151. package/dist/providers/cloudflare-ai-gateway.js +32 -4
  152. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  153. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  154. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  155. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  156. package/dist/providers/cloudflare-workers-ai.d.ts +55 -1
  157. package/dist/providers/cloudflare-workers-ai.js +45 -9
  158. package/dist/providers/cohere.d.ts +42 -0
  159. package/dist/providers/deepinfra.d.ts +42 -0
  160. package/dist/providers/deepseek.d.ts +42 -0
  161. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  162. package/dist/providers/digitalocean/decisions.js +1 -0
  163. package/dist/providers/digitalocean/images.d.ts +2 -0
  164. package/dist/providers/digitalocean/images.js +1 -0
  165. package/dist/providers/digitalocean.d.ts +72 -1
  166. package/dist/providers/digitalocean.js +39 -8
  167. package/dist/providers/fireworks.d.ts +42 -0
  168. package/dist/providers/google/images.d.ts +2 -0
  169. package/dist/providers/google/images.js +1 -0
  170. package/dist/providers/google-vertex/images.d.ts +2 -0
  171. package/dist/providers/google-vertex/images.js +1 -0
  172. package/dist/providers/google-vertex-chat.d.ts +21 -0
  173. package/dist/providers/google-vertex-messages.d.ts +52 -17
  174. package/dist/providers/google-vertex-responses.d.ts +3 -0
  175. package/dist/providers/google-vertex.d.ts +3 -1
  176. package/dist/providers/google-vertex.js +30 -13
  177. package/dist/providers/google.d.ts +5 -4
  178. package/dist/providers/google.js +15 -8
  179. package/dist/providers/groq.d.ts +42 -4
  180. package/dist/providers/groq.js +0 -6
  181. package/dist/providers/meta.d.ts +197 -138
  182. package/dist/providers/minimax.d.ts +76 -17
  183. package/dist/providers/moonshot.d.ts +76 -17
  184. package/dist/providers/openai/images.d.ts +2 -0
  185. package/dist/providers/openai/images.js +1 -0
  186. package/dist/providers/openai-compatible/images.d.ts +2 -0
  187. package/dist/providers/openai-compatible/images.js +1 -0
  188. package/dist/providers/openai-compatible-responses.d.ts +3 -0
  189. package/dist/providers/openai-compatible.d.ts +24 -1
  190. package/dist/providers/openai-compatible.js +21 -9
  191. package/dist/providers/openai-options.d.ts +3 -1
  192. package/dist/providers/openai.d.ts +46 -9
  193. package/dist/providers/openai.js +20 -4
  194. package/dist/providers/opencode/decisions.d.ts +2 -0
  195. package/dist/providers/opencode/decisions.js +1 -0
  196. package/dist/providers/opencode.d.ts +9 -10
  197. package/dist/providers/opencode.js +10 -8
  198. package/dist/providers/openrouter/decisions.d.ts +2 -0
  199. package/dist/providers/openrouter/decisions.js +1 -0
  200. package/dist/providers/openrouter/images.d.ts +2 -0
  201. package/dist/providers/openrouter/images.js +1 -0
  202. package/dist/providers/openrouter.d.ts +92 -11
  203. package/dist/providers/openrouter.js +38 -16
  204. package/dist/providers/togetherai.d.ts +42 -0
  205. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  206. package/dist/providers/typesafe-ai/decisions.js +1 -0
  207. package/dist/providers/typesafe-ai.d.ts +9 -10
  208. package/dist/providers/typesafe-ai.js +10 -8
  209. package/dist/providers/venice.d.ts +19 -0
  210. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  211. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  212. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  213. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  214. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  215. package/dist/providers/vercel-ai-gateway.js +31 -85
  216. package/dist/providers/xai/images.d.ts +2 -0
  217. package/dist/providers/xai/images.js +1 -0
  218. package/dist/providers/xai.d.ts +28 -5
  219. package/dist/providers/xai.js +15 -8
  220. package/dist/providers/zai/images.d.ts +2 -0
  221. package/dist/providers/zai/images.js +1 -0
  222. package/dist/providers/zai-coding-plan.d.ts +76 -17
  223. package/dist/providers/zai.d.ts +26 -4
  224. package/dist/providers/zai.js +15 -8
  225. package/dist/route/client.d.ts +2 -2
  226. package/dist/route/client.js +26 -4
  227. package/dist/route/decision.d.ts +58 -0
  228. package/dist/route/decision.js +75 -0
  229. package/dist/route/executor.d.ts +1 -1
  230. package/dist/route/framing.d.ts +2 -0
  231. package/dist/route/index.d.ts +3 -0
  232. package/dist/route/index.js +3 -0
  233. package/dist/route/media-protocol.d.ts +1 -0
  234. package/dist/route/media-protocol.js +12 -8
  235. package/dist/route/media.d.ts +5 -1
  236. package/dist/route/media.js +6 -2
  237. package/dist/route/transport/http.js +1 -0
  238. package/dist/route/transport/index.d.ts +1 -0
  239. package/dist/schema/events.d.ts +148 -6
  240. package/dist/schema/events.js +20 -0
  241. package/dist/schema/messages.d.ts +6 -2
  242. package/dist/schema/messages.js +3 -0
  243. package/dist/schema/options.d.ts +5 -3
  244. package/dist/schema/options.js +8 -3
  245. package/dist/speech-client.d.ts +5 -14
  246. package/dist/speech-client.js +0 -1
  247. package/dist/speech.d.ts +0 -135
  248. package/dist/speech.js +2 -4
  249. package/dist/testing.d.ts +25 -24
  250. package/dist/testing.js +3 -21
  251. package/dist/transcription-client.d.ts +5 -14
  252. package/dist/transcription.d.ts +0 -135
  253. package/dist/transcription.js +1 -1
  254. package/dist/utils/media-type.js +22 -1
  255. package/dist/video-client.d.ts +5 -14
  256. package/dist/video-client.js +0 -1
  257. package/dist/video.d.ts +1 -136
  258. package/dist/video.js +3 -5
  259. package/package.json +513 -11
  260. package/dist/experimental/evaluation-client.d.ts +0 -21
  261. package/dist/experimental/evaluation-client.js +0 -64
  262. package/dist/experimental/evaluation.d.ts +0 -242
  263. package/dist/experimental/evaluation.js +0 -108
  264. package/dist/experimental/system-one.d.ts +0 -16
  265. package/dist/experimental/system-one.js +0 -135
  266. package/dist/promise.d.ts +0 -1021
  267. package/dist/promise.js +0 -101
  268. package/dist/provider.d.ts +0 -23
  269. 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)
@@ -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
  {},
@@ -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,7 +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";
4
+ import { Usage, type FinishReasonDetails, type ProviderOptions } from "../schema/index.js";
5
5
  import { Lifecycle } from "./utils/lifecycle.js";
6
6
  import { ToolStream } from "./utils/tool-stream.js";
7
7
  export type { Credentials as BedrockCredentials } from "./utils/bedrock-auth.js";
@@ -54,7 +54,7 @@ declare const BedrockConverseBody: Schema.Struct<{
54
54
  }>, Schema.Struct<{
55
55
  readonly cachePoint: Schema.Struct<{
56
56
  readonly type: Schema.tag<"default">;
57
- 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"]>]>>;
58
58
  }>;
59
59
  }>]>>;
60
60
  }>, Schema.Struct<{
@@ -79,7 +79,7 @@ declare const BedrockConverseBody: Schema.Struct<{
79
79
  }>, Schema.Struct<{
80
80
  readonly cachePoint: Schema.Struct<{
81
81
  readonly type: Schema.tag<"default">;
82
- 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"]>]>>;
83
83
  }>;
84
84
  }>]>>;
85
85
  }>]>>;
@@ -88,7 +88,7 @@ declare const BedrockConverseBody: Schema.Struct<{
88
88
  }>, Schema.Struct<{
89
89
  readonly cachePoint: Schema.Struct<{
90
90
  readonly type: Schema.tag<"default">;
91
- 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"]>]>>;
92
92
  }>;
93
93
  }>]>>>;
94
94
  inferenceConfig: Schema.optional<Schema.Struct<{
@@ -109,7 +109,7 @@ declare const BedrockConverseBody: Schema.Struct<{
109
109
  }>, Schema.Struct<{
110
110
  readonly cachePoint: Schema.Struct<{
111
111
  readonly type: Schema.tag<"default">;
112
- 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"]>]>>;
113
113
  }>;
114
114
  }>]>>;
115
115
  readonly toolChoice: Schema.optional<Schema.Union<readonly [Schema.Struct<{
@@ -123,15 +123,62 @@ declare const BedrockConverseBody: Schema.Struct<{
123
123
  }>]>>;
124
124
  }>>;
125
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>>;
126
148
  }>;
127
149
  export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>;
128
150
  declare const Options: Schema.Struct<{
129
- 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<{
130
153
  readonly type: Schema.Literal<"enabled">;
131
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>;
132
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>>;
133
179
  }>;
134
- 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;
135
182
  /**
136
183
  * The Bedrock Converse protocol — request body construction, body schema, and
137
184
  * the streaming-event state machine.
@@ -143,7 +190,7 @@ export declare const protocol: Protocol<{
143
190
  readonly content: readonly ({
144
191
  readonly cachePoint: {
145
192
  readonly type: "default";
146
- readonly ttl?: "1h" | "5m" | undefined;
193
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
147
194
  };
148
195
  } | {
149
196
  readonly image: {
@@ -193,7 +240,7 @@ export declare const protocol: Protocol<{
193
240
  readonly content: readonly ({
194
241
  readonly cachePoint: {
195
242
  readonly type: "default";
196
- readonly ttl?: "1h" | "5m" | undefined;
243
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
197
244
  };
198
245
  } | {
199
246
  readonly text: string;
@@ -217,7 +264,7 @@ export declare const protocol: Protocol<{
217
264
  readonly system?: readonly ({
218
265
  readonly cachePoint: {
219
266
  readonly type: "default";
220
- readonly ttl?: "1h" | "5m" | undefined;
267
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
221
268
  };
222
269
  } | {
223
270
  readonly text: string;
@@ -232,7 +279,7 @@ export declare const protocol: Protocol<{
232
279
  readonly tools: readonly ({
233
280
  readonly cachePoint: {
234
281
  readonly type: "default";
235
- readonly ttl?: "1h" | "5m" | undefined;
282
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
236
283
  };
237
284
  } | {
238
285
  readonly toolSpec: {
@@ -258,6 +305,30 @@ export declare const protocol: Protocol<{
258
305
  readonly additionalModelRequestFields?: {
259
306
  readonly [x: string]: unknown;
260
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;
261
332
  }, {
262
333
  readonly [x: string]: unknown;
263
334
  readonly rawBody: string;
@@ -331,7 +402,7 @@ export declare const route: Route<{
331
402
  readonly content: readonly ({
332
403
  readonly cachePoint: {
333
404
  readonly type: "default";
334
- readonly ttl?: "1h" | "5m" | undefined;
405
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
335
406
  };
336
407
  } | {
337
408
  readonly image: {
@@ -381,7 +452,7 @@ export declare const route: Route<{
381
452
  readonly content: readonly ({
382
453
  readonly cachePoint: {
383
454
  readonly type: "default";
384
- readonly ttl?: "1h" | "5m" | undefined;
455
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
385
456
  };
386
457
  } | {
387
458
  readonly text: string;
@@ -405,7 +476,7 @@ export declare const route: Route<{
405
476
  readonly system?: readonly ({
406
477
  readonly cachePoint: {
407
478
  readonly type: "default";
408
- readonly ttl?: "1h" | "5m" | undefined;
479
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
409
480
  };
410
481
  } | {
411
482
  readonly text: string;
@@ -420,7 +491,7 @@ export declare const route: Route<{
420
491
  readonly tools: readonly ({
421
492
  readonly cachePoint: {
422
493
  readonly type: "default";
423
- readonly ttl?: "1h" | "5m" | undefined;
494
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
424
495
  };
425
496
  } | {
426
497
  readonly toolSpec: {
@@ -446,6 +517,30 @@ export declare const route: Route<{
446
517
  readonly additionalModelRequestFields?: {
447
518
  readonly [x: string]: unknown;
448
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;
449
544
  }, import("../route/transport/http.js").HttpPrepared<{
450
545
  readonly [x: string]: unknown;
451
546
  readonly rawBody: string;
@@ -10,7 +10,7 @@ import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
10
10
  import { BedrockAuth } from "./utils/bedrock-auth.js";
11
11
  import { BedrockCache } from "./utils/bedrock-cache.js";
12
12
  import { BedrockMedia } from "./utils/bedrock-media.js";
13
- import { supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
13
+ import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
14
14
  import { Lifecycle } from "./utils/lifecycle.js";
15
15
  import { MistralToolID } from "./utils/mistral-tool-id.js";
16
16
  import { ToolStream } from "./utils/tool-stream.js";
@@ -86,6 +86,11 @@ const BedrockToolChoice = Schema.Union([
86
86
  Schema.Struct({ any: Schema.Struct({}) }),
87
87
  Schema.Struct({ tool: Schema.Struct({ name: Schema.String }) }),
88
88
  ]);
89
+ // Value sets from the Converse API reference. Unknown values pass through for forward compatibility.
90
+ const ServiceTierType = ProviderShared.knownString();
91
+ const GuardrailTrace = ProviderShared.knownString();
92
+ const GuardrailStreamProcessingMode = ProviderShared.knownString();
93
+ const TextFormatType = ProviderShared.knownString();
89
94
  const BedrockBodyFields = {
90
95
  modelId: Schema.String,
91
96
  messages: Schema.Array(BedrockMessage),
@@ -101,6 +106,26 @@ const BedrockBodyFields = {
101
106
  toolChoice: Schema.optional(BedrockToolChoice),
102
107
  })),
103
108
  additionalModelRequestFields: Schema.optional(JsonObject),
109
+ serviceTier: Schema.optional(Schema.Struct({ type: ServiceTierType })),
110
+ guardrailConfig: Schema.optional(Schema.Struct({
111
+ guardrailIdentifier: Schema.String,
112
+ guardrailVersion: Schema.String,
113
+ trace: Schema.optional(GuardrailTrace),
114
+ streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
115
+ })),
116
+ outputConfig: Schema.optional(Schema.Struct({
117
+ textFormat: Schema.Struct({
118
+ type: TextFormatType,
119
+ structure: Schema.Struct({
120
+ jsonSchema: Schema.Struct({
121
+ schema: Schema.String,
122
+ name: Schema.optional(Schema.String),
123
+ description: Schema.optional(Schema.String),
124
+ }),
125
+ }),
126
+ }),
127
+ })),
128
+ requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
104
129
  };
105
130
  const BedrockConverseBody = Schema.Struct(BedrockBodyFields);
106
131
  const BedrockUsageSchema = Schema.Struct({
@@ -376,8 +401,49 @@ const isHighReasoningEffort = Schema.is(Schema.Struct({
376
401
  reasoningConfig: Schema.Struct({ maxReasoningEffort: Schema.Literal("high") }),
377
402
  }),
378
403
  }));
404
+ // Claude 4.6+ pairs effort with adaptive thinking; earlier Claude models take effort beside a manual budget.
405
+ const supportsAdaptiveThinking = (model) => {
406
+ const version = claudeVersion(model.id);
407
+ return version !== undefined && (version.major > 4 || (version.major === 4 && version.minor >= 6));
408
+ };
409
+ const effortFields = (model, effort) => {
410
+ if (model.id.includes("anthropic"))
411
+ return { output_config: { effort } };
412
+ // gpt-oss takes the flat chat-completions spelling; newer OpenAI and xAI models take the Responses one.
413
+ if (model.id.includes("openai.gpt-oss"))
414
+ return { reasoning_effort: effort };
415
+ if (model.id.includes("openai.") || model.id.includes("xai."))
416
+ return { reasoning: { effort } };
417
+ return { reasoningConfig: { type: "enabled", maxReasoningEffort: effort } };
418
+ };
379
419
  const Options = Schema.Struct({
380
- thinking: Schema.optional(Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number })),
420
+ /** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
421
+ thinking: Schema.optional(Schema.Union([
422
+ Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number }),
423
+ Schema.Struct({
424
+ type: Schema.Literal("adaptive"),
425
+ display: Schema.optional(ProviderShared.knownString()),
426
+ }),
427
+ Schema.Struct({ type: Schema.Literal("disabled") }),
428
+ ])),
429
+ /** Reasoning effort, sent in the field each model family reads. */
430
+ effort: Schema.optional(ProviderShared.knownString()),
431
+ serviceTier: Schema.optional(ServiceTierType),
432
+ /** Constrains the response text to a JSON schema. */
433
+ outputFormat: Schema.optional(Schema.Struct({
434
+ type: TextFormatType,
435
+ schema: JsonObject,
436
+ name: Schema.optional(Schema.String),
437
+ description: Schema.optional(Schema.String),
438
+ })),
439
+ guardrail: Schema.optional(Schema.Struct({
440
+ identifier: Schema.String,
441
+ version: Schema.String,
442
+ trace: Schema.optional(GuardrailTrace),
443
+ streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
444
+ })),
445
+ /** Key-value pairs for filtering invocation logs. */
446
+ requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
381
447
  });
382
448
  const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
383
449
  // Claude on Bedrock requires the thinking budget below `maxTokens`, with a minimum of 1,024.
@@ -390,7 +456,7 @@ const isThinkingDisabled = Schema.is(Schema.Struct({
390
456
  // Claude 5.1+ binds each thinking signature to the prefix above it. Ask Bedrock to drop the affected blocks instead of
391
457
  // failing when that prefix changes. `http.body` overlays this field by field, so callers can still override it.
392
458
  const applyThinkingBindingDefault = (request, thinking) => {
393
- if (isThinkingDisabled(request.http?.body))
459
+ if (thinking?.type === "disabled" || isThinkingDisabled(request.http?.body))
394
460
  return thinking;
395
461
  if (!supportsThinkingBlockBinding(request.model))
396
462
  return thinking;
@@ -404,13 +470,27 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
404
470
  const flattened = ProviderShared.flattenToolRequest(request);
405
471
  const generation = request.generation;
406
472
  const options = yield* decodeOptions(request.providerOptions ?? {});
407
- const maxTokens = isNova2(request.model) && isHighReasoningEffort(request.http?.body) ? undefined : generation?.maxTokens;
408
- const thinking = applyThinkingBindingDefault(request, options.thinking === undefined
473
+ const maxTokens = isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
409
474
  ? undefined
410
- : {
411
- type: "enabled",
412
- budget_tokens: ProviderShared.fitThinkingBudget(options.thinking.budgetTokens, maxTokens, MIN_THINKING_BUDGET),
413
- });
475
+ : generation?.maxTokens;
476
+ const thinking = applyThinkingBindingDefault(request, (() => {
477
+ if (options.thinking?.type === "enabled")
478
+ return {
479
+ type: "enabled",
480
+ budget_tokens: ProviderShared.fitThinkingBudget(options.thinking.budgetTokens, maxTokens, MIN_THINKING_BUDGET),
481
+ };
482
+ if (options.thinking !== undefined)
483
+ return options.thinking;
484
+ if (options.effort !== undefined && supportsAdaptiveThinking(request.model))
485
+ return { type: "adaptive" };
486
+ })());
487
+ const additionalModelRequestFields = {
488
+ ...(generation?.topK === undefined ? {} : { top_k: generation.topK }),
489
+ ...(thinking === undefined ? {} : { thinking }),
490
+ ...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
491
+ // Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
492
+ ...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
493
+ };
414
494
  // Bedrock-Claude shares Anthropic's 4-breakpoint cap. Spend the budget in
415
495
  // tools → system → messages order to favour the highest-impact prefixes.
416
496
  const breakpoints = BedrockCache.breakpoints(request.model);
@@ -448,16 +528,33 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
448
528
  system,
449
529
  inferenceConfig,
450
530
  toolConfig,
451
- // Converse's base inferenceConfig has no topK or thinking; Anthropic/Nova accept them
531
+ // Converse's base inferenceConfig has no topK, thinking or effort; models accept them
452
532
  // as model-specific fields, so they go through additionalModelRequestFields.
453
- additionalModelRequestFields: generation?.topK === undefined && thinking === undefined
533
+ additionalModelRequestFields: Object.keys(additionalModelRequestFields).length === 0 ? undefined : additionalModelRequestFields,
534
+ serviceTier: options.serviceTier === undefined ? undefined : { type: options.serviceTier },
535
+ guardrailConfig: options.guardrail === undefined
454
536
  ? undefined
455
537
  : {
456
- ...(generation?.topK === undefined ? {} : { top_k: generation.topK }),
457
- ...(thinking === undefined ? {} : { thinking }),
458
- // Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
459
- ...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
538
+ guardrailIdentifier: options.guardrail.identifier,
539
+ guardrailVersion: options.guardrail.version,
540
+ trace: options.guardrail.trace,
541
+ streamProcessingMode: options.guardrail.streamProcessingMode,
542
+ },
543
+ outputConfig: options.outputFormat === undefined
544
+ ? undefined
545
+ : {
546
+ textFormat: {
547
+ type: options.outputFormat.type,
548
+ structure: {
549
+ jsonSchema: {
550
+ schema: ProviderShared.encodeJson(options.outputFormat.schema),
551
+ name: options.outputFormat.name,
552
+ description: options.outputFormat.description,
553
+ },
554
+ },
555
+ },
460
556
  },
557
+ requestMetadata: options.requestMetadata,
461
558
  };
462
559
  });
463
560
  // =============================================================================
@@ -94,6 +94,7 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
94
94
  export const framing = (route) => ({
95
95
  id: "aws-event-stream",
96
96
  body: (frame) => frame.rawBody,
97
+ raw: ({ rawBody: _, ...event }) => event,
97
98
  frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
98
99
  });
99
100
  export * as BedrockEventStream from "./bedrock-event-stream.js";
@@ -1,9 +1,18 @@
1
1
  import { Schema } from "effect";
2
2
  import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
3
+ import { Media } from "../media.js";
3
4
  import { MediaProtocol } from "../route/media-protocol.js";
4
5
  import { MediaRoute } from "../route/media.js";
6
+ import { type OpenString } from "../schema/index.js";
5
7
  export declare const DEFAULT_BASE_URL = "https://api.bfl.ai";
8
+ /** Native body fields; `aspect` and `resolution` lower to `width`/`height` or `aspect_ratio` depending on the model. */
6
9
  export type BlackForestLabsImageOptions = {
10
+ readonly width?: number;
11
+ readonly height?: number;
12
+ readonly seed?: number;
13
+ readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
14
+ /** Inpainting mask for `flux-pro-1.0-fill`. */
15
+ readonly mask?: Media.Asset;
7
16
  readonly safety_tolerance?: number;
8
17
  readonly prompt_upsampling?: boolean;
9
18
  readonly disable_pup?: boolean;