@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
@@ -1,11 +1,13 @@
1
- import { Effect, Schema, Stream } from "effect";
1
+ import { Effect, Schema, SchemaGetter, Stream } from "effect";
2
2
  import { ImageFinishEvent, ImageModel, ImageOutputEvent, ImagePartialEvent, } from "../image.js";
3
3
  import { Media } from "../media.js";
4
+ import { classifyProviderFailure } from "../provider-error.js";
4
5
  import { Framing } from "../route/framing.js";
5
6
  import { MediaProtocol } from "../route/media-protocol.js";
6
7
  import { MediaRoute } from "../route/media.js";
7
- import { mergeJsonRecords } from "../schema/index.js";
8
- import { ProviderShared } from "./shared.js";
8
+ import { AIError, mergeJsonRecords, ProviderID, tokenUsage } from "../schema/index.js";
9
+ import { optionalNull, ProviderShared } from "./shared.js";
10
+ import { ImageSizing } from "./utils/image-sizing.js";
9
11
  import { MediaInput } from "./utils/media-input.js";
10
12
  const route = MediaProtocol.identity({ id: "openai-images", name: "OpenAI Images", provider: "openai" });
11
13
  export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
@@ -29,13 +31,28 @@ const Settings = {
29
31
  background: Schema.optional(Schema.String),
30
32
  };
31
33
  const OpenAIImageResponse = Schema.Struct({
32
- data: Schema.Array(Schema.Struct({ b64_json: Schema.String })),
34
+ // `response_format` picks `b64_json` or `url`; DALL·E and many compatible hosts default to `url`.
35
+ data: Schema.Array(Schema.Struct({ b64_json: optionalNull(Schema.String), url: optionalNull(Schema.String) })),
33
36
  ...Settings,
34
37
  usage: Schema.optional(Usage),
35
38
  });
36
39
  // ---------------------------------------------------------------------------
37
40
  // 3. Streaming event schema
38
41
  // ---------------------------------------------------------------------------
42
+ const EVENT_TYPES = new Set([
43
+ "image_generation.partial_image",
44
+ "image_edit.partial_image",
45
+ "image_generation.completed",
46
+ "image_edit.completed",
47
+ "error",
48
+ ]);
49
+ /** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
50
+ const UnknownEvent = Schema.Struct({
51
+ type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
52
+ }).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
53
+ decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
54
+ encode: SchemaGetter.forbidden(() => "Unknown OpenAI Images stream events are decode-only"),
55
+ }));
39
56
  const StreamEvent = Schema.Union([
40
57
  Schema.Struct({
41
58
  type: Schema.Literals(["image_generation.partial_image", "image_edit.partial_image"]),
@@ -51,6 +68,11 @@ const StreamEvent = Schema.Union([
51
68
  output_format: Schema.String,
52
69
  usage: Schema.optional(Usage),
53
70
  }),
71
+ Schema.Struct({
72
+ type: Schema.Literal("error"),
73
+ error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
74
+ }),
75
+ UnknownEvent,
54
76
  ]);
55
77
  const decodeEvent = route.decodeFrame(StreamEvent);
56
78
  const decodeDocument = Schema.decodeUnknownEffect(Schema.fromJsonString(OpenAIImageResponse));
@@ -62,8 +84,38 @@ const RESERVED_FORM_FIELDS = new Set(["model", "prompt", "image", "image[]", "im
62
84
  const nativeOptions = (options) => {
63
85
  if (!options)
64
86
  return undefined;
65
- const { outputCompression, partialImages: _, ...native } = options;
66
- return { output_compression: outputCompression, ...native };
87
+ const { outputCompression, outputFormat, partialImages: _, mask: __, ...native } = options;
88
+ return { output_compression: outputCompression, output_format: outputFormat, ...native };
89
+ };
90
+ /**
91
+ * `gpt-image-1`, `chatgpt-image` and DALL·E take a fixed list, `gpt-image-2` and later any size within limits. Other
92
+ * models are gateway-hosted (`bfl/flux-2-pro`); the gateway passes `size` through to them as is.
93
+ */
94
+ const sizes = (model) => {
95
+ const id = model.slice(model.lastIndexOf("/") + 1);
96
+ if (id.startsWith("dall-e-2"))
97
+ return [256, 512, 1024].map((edge) => ({ width: edge, height: edge }));
98
+ if (id.startsWith("dall-e-3"))
99
+ return [
100
+ { width: 1024, height: 1024 },
101
+ { width: 1792, height: 1024 },
102
+ { width: 1024, height: 1792 },
103
+ ];
104
+ if (/^(gpt-image-1|chatgpt-image)/.test(id))
105
+ return [
106
+ { width: 1024, height: 1024 },
107
+ { width: 1536, height: 1024 },
108
+ { width: 1024, height: 1536 },
109
+ ];
110
+ if (id.startsWith("gpt-image-"))
111
+ return { multiple: 16, maxEdge: 3840, minPixels: 655_360, maxPixels: 8_294_400, maxRatio: 3 };
112
+ return { multiple: 16 };
113
+ };
114
+ const size = (request) => {
115
+ if (!ImageSizing.isRequested(request))
116
+ return undefined;
117
+ const options = sizes(request.model.id);
118
+ return "multiple" in options ? ImageSizing.fit(request, options) : ImageSizing.nearest(request, options);
67
119
  };
68
120
  const streamOptions = (request) => {
69
121
  if (request.mode !== "stream")
@@ -74,13 +126,20 @@ const streamOptions = (request) => {
74
126
  };
75
127
  const isEdit = (request) => (request.images?.length ?? 0) > 0;
76
128
  const isInline = (asset) => asset.source.type === "bytes" || asset.source.type === "base64";
77
- const reference = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
129
+ const reference = (asset, provider) => ProviderShared.mediaReference(asset, provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
78
130
  const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
79
131
  const images = request.images ?? [];
80
- const mask = request.mask;
132
+ const mask = request.providerOptions?.mask;
81
133
  if (mask !== undefined && images.length === 0)
82
134
  return yield* ProviderShared.invalidRequest("An OpenAI image mask requires at least one input image");
83
- const fields = mergeJsonRecords({ n: request.n, size: request.size, output_format: request.format, ...(yield* streamOptions(request)) }, nativeOptions(request.providerOptions), request.http?.body);
135
+ if (request.providerOptions?.size !== undefined && ImageSizing.isRequested(request))
136
+ return yield* ProviderShared.invalidRequest("OpenAI providerOptions.size replaces aspect and resolution; set one or the other");
137
+ const chosen = size(request);
138
+ const fields = mergeJsonRecords({
139
+ n: request.n,
140
+ size: chosen === undefined ? undefined : `${chosen.width}x${chosen.height}`,
141
+ ...(yield* streamOptions(request)),
142
+ }, nativeOptions(request.providerOptions), request.http?.body);
84
143
  // Owned bytes go through multipart edits; remote URLs and file IDs use the JSON edits body instead.
85
144
  if (images.length > 0 && images.every(isInline) && (mask === undefined || isInline(mask))) {
86
145
  const form = new FormData();
@@ -91,8 +150,8 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
91
150
  form.append("mask", MediaInput.blob(yield* MediaInput.inlineBytes(route.id, mask), mask.mediaType), "mask");
92
151
  return MediaProtocol.multipart(form);
93
152
  }
94
- const references = yield* Effect.forEach(images, reference);
95
- const maskReference = mask === undefined ? undefined : yield* reference(mask);
153
+ const references = yield* Effect.forEach(images, (image) => reference(image, request.model.provider));
154
+ const maskReference = mask === undefined ? undefined : yield* reference(mask, request.model.provider);
96
155
  return MediaProtocol.json(mergeJsonRecords({
97
156
  model: request.model.id,
98
157
  prompt: request.prompt,
@@ -103,21 +162,14 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
103
162
  // ---------------------------------------------------------------------------
104
163
  // 6. Stream parsing
105
164
  // ---------------------------------------------------------------------------
106
- const requestedFormat = (body) => {
107
- if (body.type === "binary")
108
- return undefined;
109
- const value = body.type === "json" ? body.value.output_format : body.value.get("output_format");
110
- return typeof value === "string" ? value : undefined;
111
- };
112
- const usage = (value) => value === undefined
165
+ const usage = (value, provider) => value === undefined
113
166
  ? undefined
114
- : {
115
- type: "tokens",
167
+ : tokenUsage({
116
168
  input: value.input_tokens,
117
169
  output: value.output_tokens,
118
170
  total: value.total_tokens,
119
- details: { openai: value },
120
- };
171
+ details: { [provider]: value },
172
+ });
121
173
  /** `size` echoes the rendered `WIDTHxHEIGHT`; `auto` or any other value leaves the dimensions unknown. */
122
174
  const info = (format, size) => {
123
175
  const match = size?.match(/^(\d+)x(\d+)$/);
@@ -128,6 +180,15 @@ const eventImage = (frame, label, data, format, size) => MediaInput.decodedAsset
128
180
  });
129
181
  const onEvent = Effect.fnUntraced(function* (state, frame) {
130
182
  const event = yield* decodeEvent(frame);
183
+ if (event.type === "unknown")
184
+ return [state, []];
185
+ if (event.type === "error")
186
+ return yield* new AIError({
187
+ reason: classifyProviderFailure({
188
+ message: `${route.name} stream failed: ${event.error?.message ?? "unknown error"}`,
189
+ rawBody: frame,
190
+ }),
191
+ });
131
192
  const format = event.output_format;
132
193
  if ("partial_image_index" in event) {
133
194
  const image = yield* eventImage(frame, `${route.name} partial image`, event.b64_json, format, event.size);
@@ -141,7 +202,7 @@ const onEvent = Effect.fnUntraced(function* (state, frame) {
141
202
  size: event.size,
142
203
  quality: event.quality,
143
204
  background: event.background,
144
- usage: usage(event.usage),
205
+ usage: event.usage,
145
206
  },
146
207
  [ImageOutputEvent.make({ index: state.completed, image })],
147
208
  ];
@@ -149,8 +210,10 @@ const onEvent = Effect.fnUntraced(function* (state, frame) {
149
210
  const onDocument = Effect.fnUntraced(function* (frame) {
150
211
  const invalid = (message, cause) => route.frameError(message, frame.document, cause);
151
212
  const decoded = yield* decodeDocument(frame.document).pipe(Effect.mapError((cause) => invalid(`${route.name} returned an invalid response`, cause)));
152
- const format = decoded.output_format ?? frame.requested ?? "png";
153
- const images = yield* Effect.forEach(decoded.data, (item, index) => MediaInput.decodedAsset(invalid, `${route.name} result ${index}`, item.b64_json, `image/${format}`, {
213
+ // Compatible hosts may omit `output_format` and ignore the requested one, so the bytes decide unreported types.
214
+ const format = decoded.output_format;
215
+ const mediaType = format === undefined ? undefined : `image/${format}`;
216
+ const images = yield* Effect.forEach(decoded.data, (item, index) => MediaInput.imageOutput(invalid, `${route.name} result ${index}`, item, mediaType, {
154
217
  info: info(format, decoded.size),
155
218
  }));
156
219
  if (images.length === 0)
@@ -161,19 +224,20 @@ const onDocument = Effect.fnUntraced(function* (frame) {
161
224
  size: decoded.size,
162
225
  quality: decoded.quality,
163
226
  background: decoded.background,
164
- usage: usage(decoded.usage),
227
+ usage: decoded.usage,
165
228
  };
166
229
  return [state, images.map((image, index) => ImageOutputEvent.make({ index, image }))];
167
230
  });
168
231
  const step = (state, frame) => (typeof frame === "string" ? onEvent(state, frame) : onDocument(frame));
169
- const finish = (state) => {
232
+ const finish = (state, context) => {
170
233
  if (state.completed === 0)
171
234
  return Effect.fail(route.incomplete());
235
+ const provider = context.request.model.provider;
172
236
  return Effect.succeed([
173
237
  ImageFinishEvent.make({
174
- usage: state.usage,
238
+ usage: usage(state.usage, provider),
175
239
  providerMetadata: {
176
- openai: {
240
+ [provider]: {
177
241
  outputFormat: state.format,
178
242
  size: state.size,
179
243
  quality: state.quality,
@@ -187,18 +251,20 @@ const finish = (state) => {
187
251
  // 7. Protocol and route
188
252
  // ---------------------------------------------------------------------------
189
253
  export const protocol = MediaProtocol.stream(route, {
190
- unsupported: ["aspectRatio", "seed"],
191
254
  body: { from: fromRequest },
192
255
  frames: (bytes, context) => context.request.mode === "stream"
193
256
  ? Framing.sse.frame(bytes)
194
- : Framing.document
195
- .frame(bytes)
196
- .pipe(Stream.map((document) => ({ document, requested: requestedFormat(context.body) }))),
257
+ : Framing.document.frame(bytes).pipe(Stream.map((document) => ({ document }))),
197
258
  initial: () => ({ completed: 0 }),
198
259
  step,
199
260
  finish,
200
261
  });
201
- export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH) }, input);
262
+ /** `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. */
263
+ export const model = (input) => ImageModel.fromRoute({
264
+ protocol: input.provider === undefined ? protocol : { ...protocol, provider: ProviderID.make(input.provider) },
265
+ baseURL: DEFAULT_BASE_URL,
266
+ path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH),
267
+ }, input);
202
268
  export const OpenAIImages = {
203
269
  protocol,
204
270
  model,
@@ -11,6 +11,10 @@ export declare const ContextManagement: Schema.$Array<Schema.Struct<{
11
11
  readonly compactThreshold: Schema.optional<Schema.Int>;
12
12
  }>>;
13
13
  export type ContextManagement = typeof ContextManagement.Type;
14
+ export declare const ReasoningMode: Schema.declare<import("../schema/options.js").OpenString<"pro" | "standard">, import("../schema/options.js").OpenString<"pro" | "standard">>;
15
+ export type ReasoningMode = typeof ReasoningMode.Type;
16
+ export declare const ReasoningContext: Schema.declare<import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn">, import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn">>;
17
+ export type ReasoningContext = typeof ReasoningContext.Type;
14
18
  declare const OpenAIResponsesBody: Schema.Struct<{
15
19
  readonly model: Schema.String;
16
20
  readonly input: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
@@ -46,6 +50,9 @@ declare const OpenAIResponsesBody: Schema.Struct<{
46
50
  readonly detail: Schema.optional<Schema.String>;
47
51
  readonly file_data: Schema.optional<Schema.String>;
48
52
  readonly file_url: Schema.optional<Schema.String>;
53
+ }>, Schema.Struct<{
54
+ readonly type: Schema.tag<"input_video">;
55
+ readonly video_url: Schema.String;
49
56
  }>]>]>>;
50
57
  readonly id: Schema.optional<Schema.String>;
51
58
  readonly status: Schema.optional<Schema.String>;
@@ -137,10 +144,6 @@ declare const OpenAIResponsesBody: Schema.Struct<{
137
144
  readonly service_tier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority">, import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority">>>;
138
145
  readonly prompt_cache_key: Schema.optional<Schema.String>;
139
146
  readonly include: Schema.optional<Schema.$Array<Schema.declare<import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">, import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">>>>;
140
- readonly reasoning: Schema.optional<Schema.Struct<{
141
- readonly effort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
142
- readonly summary: Schema.optional<Schema.Literals<readonly ["auto", "concise", "detailed"]>>;
143
- }>>;
144
147
  readonly text: Schema.optional<Schema.Struct<{
145
148
  readonly verbosity: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "medium">, import("../schema/options.js").OpenString<"high" | "low" | "medium">>>;
146
149
  }>>;
@@ -151,6 +154,10 @@ declare const OpenAIResponsesBody: Schema.Struct<{
151
154
  readonly top_p: Schema.optional<Schema.Number>;
152
155
  readonly presence_penalty: Schema.optional<Schema.Number>;
153
156
  readonly frequency_penalty: Schema.optional<Schema.Number>;
157
+ readonly prompt_cache_retention: Schema.optional<Schema.String>;
158
+ readonly prompt_cache_options: Schema.optional<Schema.Struct<{
159
+ readonly ttl: Schema.optional<Schema.String>;
160
+ }>>;
154
161
  readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
155
162
  readonly type: Schema.tag<"function">;
156
163
  readonly name: Schema.String;
@@ -192,6 +199,12 @@ declare const OpenAIResponsesBody: Schema.Struct<{
192
199
  }>]>, Schema.Struct<{
193
200
  readonly type: Schema.tag<"image_generation">;
194
201
  }>]>>;
202
+ readonly reasoning: Schema.optional<Schema.Struct<{
203
+ readonly effort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
204
+ readonly summary: Schema.optional<Schema.Literals<readonly ["auto", "concise", "detailed"]>>;
205
+ readonly mode: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"pro" | "standard">, import("../schema/options.js").OpenString<"pro" | "standard">>>;
206
+ readonly context: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn">, import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn">>>;
207
+ }>>;
195
208
  readonly context_management: Schema.optional<Schema.$Array<Schema.Struct<{
196
209
  readonly type: Schema.Literal<"compaction">;
197
210
  readonly compact_threshold: Schema.optional<Schema.Int>;
@@ -256,6 +269,9 @@ export declare const protocol: Protocol<{
256
269
  readonly content: readonly ({
257
270
  readonly type: "input_text";
258
271
  readonly text: string;
272
+ } | {
273
+ readonly type: "input_video";
274
+ readonly video_url: string;
259
275
  } | {
260
276
  readonly type: "input_image";
261
277
  readonly image_url: string;
@@ -342,10 +358,6 @@ export declare const protocol: Protocol<{
342
358
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
343
359
  readonly prompt_cache_key?: string | undefined;
344
360
  readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
345
- readonly reasoning?: {
346
- readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
347
- readonly summary?: "auto" | "concise" | "detailed" | undefined;
348
- } | undefined;
349
361
  readonly text?: {
350
362
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
351
363
  } | undefined;
@@ -356,6 +368,10 @@ export declare const protocol: Protocol<{
356
368
  readonly top_p?: number | undefined;
357
369
  readonly presence_penalty?: number | undefined;
358
370
  readonly frequency_penalty?: number | undefined;
371
+ readonly prompt_cache_retention?: string | undefined;
372
+ readonly prompt_cache_options?: {
373
+ readonly ttl?: string | undefined;
374
+ } | undefined;
359
375
  readonly tools?: readonly ({
360
376
  readonly type: "namespace";
361
377
  readonly name: string;
@@ -401,6 +417,12 @@ export declare const protocol: Protocol<{
401
417
  } | {
402
418
  readonly type: "image_generation";
403
419
  } | undefined;
420
+ readonly reasoning?: {
421
+ readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
422
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
423
+ readonly mode?: import("../schema/options.js").OpenString<"pro" | "standard"> | undefined;
424
+ readonly context?: import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn"> | undefined;
425
+ } | undefined;
404
426
  readonly context_management?: readonly {
405
427
  readonly type: "compaction";
406
428
  readonly compact_threshold?: number | undefined;
@@ -518,6 +540,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
518
540
  readonly content: readonly ({
519
541
  readonly type: "input_text";
520
542
  readonly text: string;
543
+ } | {
544
+ readonly type: "input_video";
545
+ readonly video_url: string;
521
546
  } | {
522
547
  readonly type: "input_image";
523
548
  readonly image_url: string;
@@ -604,10 +629,6 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
604
629
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
605
630
  readonly prompt_cache_key?: string | undefined;
606
631
  readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
607
- readonly reasoning?: {
608
- readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
609
- readonly summary?: "auto" | "concise" | "detailed" | undefined;
610
- } | undefined;
611
632
  readonly text?: {
612
633
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
613
634
  } | undefined;
@@ -618,6 +639,10 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
618
639
  readonly top_p?: number | undefined;
619
640
  readonly presence_penalty?: number | undefined;
620
641
  readonly frequency_penalty?: number | undefined;
642
+ readonly prompt_cache_retention?: string | undefined;
643
+ readonly prompt_cache_options?: {
644
+ readonly ttl?: string | undefined;
645
+ } | undefined;
621
646
  readonly tools?: readonly ({
622
647
  readonly type: "namespace";
623
648
  readonly name: string;
@@ -663,6 +688,12 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
663
688
  } | {
664
689
  readonly type: "image_generation";
665
690
  } | undefined;
691
+ readonly reasoning?: {
692
+ readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
693
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
694
+ readonly mode?: import("../schema/options.js").OpenString<"pro" | "standard"> | undefined;
695
+ readonly context?: import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn"> | undefined;
696
+ } | undefined;
666
697
  readonly context_management?: readonly {
667
698
  readonly type: "compaction";
668
699
  readonly compact_threshold?: number | undefined;
@@ -722,6 +753,9 @@ export declare const channelTransport: (options: import("./open-responses-channe
722
753
  readonly content: readonly ({
723
754
  readonly type: "input_text";
724
755
  readonly text: string;
756
+ } | {
757
+ readonly type: "input_video";
758
+ readonly video_url: string;
725
759
  } | {
726
760
  readonly type: "input_image";
727
761
  readonly image_url: string;
@@ -808,10 +842,6 @@ export declare const channelTransport: (options: import("./open-responses-channe
808
842
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
809
843
  readonly prompt_cache_key?: string | undefined;
810
844
  readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
811
- readonly reasoning?: {
812
- readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
813
- readonly summary?: "auto" | "concise" | "detailed" | undefined;
814
- } | undefined;
815
845
  readonly text?: {
816
846
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
817
847
  } | undefined;
@@ -822,6 +852,10 @@ export declare const channelTransport: (options: import("./open-responses-channe
822
852
  readonly top_p?: number | undefined;
823
853
  readonly presence_penalty?: number | undefined;
824
854
  readonly frequency_penalty?: number | undefined;
855
+ readonly prompt_cache_retention?: string | undefined;
856
+ readonly prompt_cache_options?: {
857
+ readonly ttl?: string | undefined;
858
+ } | undefined;
825
859
  readonly tools?: readonly ({
826
860
  readonly type: "namespace";
827
861
  readonly name: string;
@@ -867,6 +901,12 @@ export declare const channelTransport: (options: import("./open-responses-channe
867
901
  } | {
868
902
  readonly type: "image_generation";
869
903
  } | undefined;
904
+ readonly reasoning?: {
905
+ readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
906
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
907
+ readonly mode?: import("../schema/options.js").OpenString<"pro" | "standard"> | undefined;
908
+ readonly context?: import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn"> | undefined;
909
+ } | undefined;
870
910
  readonly context_management?: readonly {
871
911
  readonly type: "compaction";
872
912
  readonly compact_threshold?: number | undefined;
@@ -926,6 +966,9 @@ export declare const transport: import("../route/transport/index.js").Transport<
926
966
  readonly content: readonly ({
927
967
  readonly type: "input_text";
928
968
  readonly text: string;
969
+ } | {
970
+ readonly type: "input_video";
971
+ readonly video_url: string;
929
972
  } | {
930
973
  readonly type: "input_image";
931
974
  readonly image_url: string;
@@ -1012,10 +1055,6 @@ export declare const transport: import("../route/transport/index.js").Transport<
1012
1055
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
1013
1056
  readonly prompt_cache_key?: string | undefined;
1014
1057
  readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
1015
- readonly reasoning?: {
1016
- readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
1017
- readonly summary?: "auto" | "concise" | "detailed" | undefined;
1018
- } | undefined;
1019
1058
  readonly text?: {
1020
1059
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
1021
1060
  } | undefined;
@@ -1026,6 +1065,10 @@ export declare const transport: import("../route/transport/index.js").Transport<
1026
1065
  readonly top_p?: number | undefined;
1027
1066
  readonly presence_penalty?: number | undefined;
1028
1067
  readonly frequency_penalty?: number | undefined;
1068
+ readonly prompt_cache_retention?: string | undefined;
1069
+ readonly prompt_cache_options?: {
1070
+ readonly ttl?: string | undefined;
1071
+ } | undefined;
1029
1072
  readonly tools?: readonly ({
1030
1073
  readonly type: "namespace";
1031
1074
  readonly name: string;
@@ -1071,6 +1114,12 @@ export declare const transport: import("../route/transport/index.js").Transport<
1071
1114
  } | {
1072
1115
  readonly type: "image_generation";
1073
1116
  } | undefined;
1117
+ readonly reasoning?: {
1118
+ readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
1119
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
1120
+ readonly mode?: import("../schema/options.js").OpenString<"pro" | "standard"> | undefined;
1121
+ readonly context?: import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn"> | undefined;
1122
+ } | undefined;
1074
1123
  readonly context_management?: readonly {
1075
1124
  readonly type: "compaction";
1076
1125
  readonly compact_threshold?: number | undefined;
@@ -1130,6 +1179,9 @@ export declare const route: Route<{
1130
1179
  readonly content: readonly ({
1131
1180
  readonly type: "input_text";
1132
1181
  readonly text: string;
1182
+ } | {
1183
+ readonly type: "input_video";
1184
+ readonly video_url: string;
1133
1185
  } | {
1134
1186
  readonly type: "input_image";
1135
1187
  readonly image_url: string;
@@ -1216,10 +1268,6 @@ export declare const route: Route<{
1216
1268
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
1217
1269
  readonly prompt_cache_key?: string | undefined;
1218
1270
  readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
1219
- readonly reasoning?: {
1220
- readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
1221
- readonly summary?: "auto" | "concise" | "detailed" | undefined;
1222
- } | undefined;
1223
1271
  readonly text?: {
1224
1272
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
1225
1273
  } | undefined;
@@ -1230,6 +1278,10 @@ export declare const route: Route<{
1230
1278
  readonly top_p?: number | undefined;
1231
1279
  readonly presence_penalty?: number | undefined;
1232
1280
  readonly frequency_penalty?: number | undefined;
1281
+ readonly prompt_cache_retention?: string | undefined;
1282
+ readonly prompt_cache_options?: {
1283
+ readonly ttl?: string | undefined;
1284
+ } | undefined;
1233
1285
  readonly tools?: readonly ({
1234
1286
  readonly type: "namespace";
1235
1287
  readonly name: string;
@@ -1275,6 +1327,12 @@ export declare const route: Route<{
1275
1327
  } | {
1276
1328
  readonly type: "image_generation";
1277
1329
  } | undefined;
1330
+ readonly reasoning?: {
1331
+ readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
1332
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
1333
+ readonly mode?: import("../schema/options.js").OpenString<"pro" | "standard"> | undefined;
1334
+ readonly context?: import("../schema/options.js").OpenString<"all_turns" | "auto" | "current_turn"> | undefined;
1335
+ } | undefined;
1278
1336
  readonly context_management?: readonly {
1279
1337
  readonly type: "compaction";
1280
1338
  readonly compact_threshold?: number | undefined;
@@ -7,14 +7,16 @@ import { Endpoint } from "../route/endpoint.js";
7
7
  import { Protocol } from "../route/protocol.js";
8
8
  import { HttpTransport } from "../route/transport/index.js";
9
9
  import { LLMRequest } from "../schema/index.js";
10
+ import { requestTTL } from "../cache-policy.js";
10
11
  import { resolveEffortUpdates } from "../effort-updates.js";
11
12
  import { OpenResponses } from "./open-responses.js";
12
13
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
13
- import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
14
+ import { JsonObject, lenient, optionalArray, optionalNull, ProviderShared } from "./shared.js";
14
15
  import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
15
16
  import { OpenResponsesChannel } from "./open-responses-channel.js";
16
17
  import { ResponsesCompaction } from "./utils/responses-compaction.js";
17
18
  import { ResponsesCheckpoint } from "./utils/responses-checkpoint.js";
19
+ import * as Cache from "./utils/cache.js";
18
20
  const ADAPTER = "openai-responses";
19
21
  const NAME = "OpenAI Responses";
20
22
  const WEBSOCKET_PROTOCOL_HEADER = "responses_websockets=2026-02-06";
@@ -25,6 +27,12 @@ export const ContextManagement = Schema.Array(Schema.Struct({
25
27
  type: Schema.Literal("compaction"),
26
28
  compactThreshold: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
27
29
  }));
30
+ export const ReasoningMode = ProviderShared.knownString();
31
+ export const ReasoningContext = ProviderShared.knownString();
32
+ const ReasoningOptions = Schema.Struct({
33
+ reasoningMode: lenient(ReasoningMode),
34
+ reasoningContext: lenient(ReasoningContext),
35
+ });
28
36
  const OpenAIResponsesImageGenerationTool = Schema.Struct({
29
37
  type: Schema.tag("image_generation"),
30
38
  action: Schema.optional(Schema.Literals(["auto", "generate", "edit"])),
@@ -84,8 +92,16 @@ const OpenAIResponsesToolChoice = Schema.Union([
84
92
  ]);
85
93
  const OpenAIResponsesCoreFields = {
86
94
  ...OpenResponses.coreFields,
95
+ prompt_cache_retention: Schema.optional(Schema.String),
96
+ prompt_cache_options: Schema.optional(Schema.Struct({ ttl: Schema.optional(Schema.String) })),
87
97
  tools: optionalArray(OpenAIResponsesTools),
88
98
  tool_choice: Schema.optional(OpenAIResponsesToolChoice),
99
+ reasoning: Schema.optional(Schema.Struct({
100
+ effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
101
+ summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"])),
102
+ mode: Schema.optional(ReasoningMode),
103
+ context: Schema.optional(ReasoningContext),
104
+ })),
89
105
  context_management: Schema.optional(Schema.Array(Schema.Struct({
90
106
  type: Schema.Literal("compaction"),
91
107
  compact_threshold: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
@@ -111,6 +127,8 @@ const adapter = {
111
127
  const supportsEffortUpdates = (request) => {
112
128
  if (request.providerOptions?.contextManagement !== undefined)
113
129
  return false;
130
+ if (request.providerOptions?.reasoningMode === "pro")
131
+ return false;
114
132
  if (Schema.is(Schema.Struct({ mode: Schema.Literal("pro") }))(request.http?.body?.reasoning))
115
133
  return false;
116
134
  const override = request.model.compatibility?.supportsEffortUpdates;
@@ -162,10 +180,22 @@ const lowerToolChoice = (toolChoice, tools) => ProviderShared.matchToolChoice(NA
162
180
  const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request) {
163
181
  const management = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Schema.UndefinedOr(ContextManagement)))(request.providerOptions?.contextManagement);
164
182
  const options = OpenResponsesOptions.resolve(request);
183
+ const reasoning = Schema.decodeUnknownSync(ReasoningOptions)(request.providerOptions ?? {});
165
184
  const updates = resolveEffortUpdates(request, options.reasoningEffort);
185
+ const generation = OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort });
166
186
  return {
167
187
  ...(yield* OpenResponses.lowerConversation(updates.request, adapter)),
168
- ...OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort }),
188
+ ...generation,
189
+ ...Cache.openAIRequestTTL(requestTTL(request)),
190
+ ...(generation.reasoning || reasoning.reasoningMode || reasoning.reasoningContext
191
+ ? {
192
+ reasoning: {
193
+ ...generation.reasoning,
194
+ mode: reasoning.reasoningMode,
195
+ context: reasoning.reasoningContext,
196
+ },
197
+ }
198
+ : {}),
169
199
  context_management: management?.map((edit) => ({ type: edit.type, compact_threshold: edit.compactThreshold })),
170
200
  tools: request.tools.length === 0 ? undefined : yield* lowerTools(request),
171
201
  tool_choice: request.tools.length === 0
@@ -57,15 +57,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
57
57
  readonly [x: string]: unknown;
58
58
  } | undefined;
59
59
  } | undefined;
60
- readonly notices?: readonly {
61
- readonly type: "filtered" | "moderated" | "other";
62
- readonly message: string;
63
- readonly providerMetadata?: {
64
- readonly [x: string]: {
65
- readonly [x: string]: unknown;
66
- };
67
- } | undefined;
68
- }[] | undefined;
69
60
  readonly providerMetadata?: {
70
61
  readonly [x: string]: {
71
62
  readonly [x: string]: unknown;
@@ -116,15 +107,6 @@ export declare const OpenAISpeech: {
116
107
  readonly [x: string]: unknown;
117
108
  } | undefined;
118
109
  } | undefined;
119
- readonly notices?: readonly {
120
- readonly type: "filtered" | "moderated" | "other";
121
- readonly message: string;
122
- readonly providerMetadata?: {
123
- readonly [x: string]: {
124
- readonly [x: string]: unknown;
125
- };
126
- } | undefined;
127
- }[] | undefined;
128
110
  readonly providerMetadata?: {
129
111
  readonly [x: string]: {
130
112
  readonly [x: string]: unknown;