@effect/ai-openai-compat 4.0.0-beta.10 → 4.0.0-beta.100

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 (41) hide show
  1. package/dist/OpenAiClient.d.ts +264 -52
  2. package/dist/OpenAiClient.d.ts.map +1 -1
  3. package/dist/OpenAiClient.js +97 -9
  4. package/dist/OpenAiClient.js.map +1 -1
  5. package/dist/OpenAiConfig.d.ts +68 -10
  6. package/dist/OpenAiConfig.d.ts.map +1 -1
  7. package/dist/OpenAiConfig.js +36 -7
  8. package/dist/OpenAiConfig.js.map +1 -1
  9. package/dist/OpenAiEmbeddingModel.d.ts +193 -0
  10. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  11. package/dist/OpenAiEmbeddingModel.js +187 -0
  12. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  13. package/dist/OpenAiError.d.ts +109 -35
  14. package/dist/OpenAiError.d.ts.map +1 -1
  15. package/dist/OpenAiError.js +14 -1
  16. package/dist/OpenAiLanguageModel.d.ts +363 -50
  17. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  18. package/dist/OpenAiLanguageModel.js +158 -33
  19. package/dist/OpenAiLanguageModel.js.map +1 -1
  20. package/dist/OpenAiTelemetry.d.ts +76 -26
  21. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  22. package/dist/OpenAiTelemetry.js +22 -10
  23. package/dist/OpenAiTelemetry.js.map +1 -1
  24. package/dist/index.d.ts +10 -17
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +10 -17
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/errors.js +4 -4
  29. package/dist/internal/errors.js.map +1 -1
  30. package/dist/internal/utilities.js +0 -6
  31. package/dist/internal/utilities.js.map +1 -1
  32. package/package.json +5 -6
  33. package/src/OpenAiClient.ts +273 -50
  34. package/src/OpenAiConfig.ts +69 -11
  35. package/src/OpenAiEmbeddingModel.ts +322 -0
  36. package/src/OpenAiError.ts +111 -35
  37. package/src/OpenAiLanguageModel.ts +468 -88
  38. package/src/OpenAiTelemetry.ts +81 -32
  39. package/src/index.ts +11 -17
  40. package/src/internal/errors.ts +4 -4
  41. package/src/internal/utilities.ts +0 -9
@@ -1,35 +1,57 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module lets a workflow temporarily customize the HTTP
3
+ * client used by OpenAI-compatible request helpers. Model, embedding, and
4
+ * tool-calling code can use this scoped configuration to add middleware,
5
+ * instrumentation, or routing without rebuilding the client layer.
6
+ *
7
+ * @since 4.0.0
3
8
  */
9
+ import * as Context from "effect/Context"
4
10
  import * as Effect from "effect/Effect"
5
11
  import { dual } from "effect/Function"
6
- import * as ServiceMap from "effect/ServiceMap"
7
12
  import type { HttpClient } from "effect/unstable/http/HttpClient"
8
13
 
9
14
  /**
10
- * @since 1.0.0
15
+ * Context service for OpenAI-compatible client configuration in the current
16
+ * Effect scope.
17
+ *
18
+ * **When to use**
19
+ *
20
+ * Use as the context service for scoped OpenAI-compatible client configuration
21
+ * and HTTP client transforms.
22
+ *
23
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
24
+ *
11
25
  * @category services
26
+ * @since 4.0.0
12
27
  */
13
- export class OpenAiConfig extends ServiceMap.Service<
28
+ export class OpenAiConfig extends Context.Service<
14
29
  OpenAiConfig,
15
30
  OpenAiConfig.Service
16
31
  >()("@effect/ai-openai-compat/OpenAiConfig") {
17
32
  /**
18
- * @since 1.0.0
33
+ * Gets the configured OpenAI-compatible service from the current context when present.
34
+ *
35
+ * @since 4.0.0
19
36
  */
20
37
  static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined> = Effect.map(
21
- Effect.services<never>(),
38
+ Effect.context<never>(),
22
39
  (context) => context.mapUnsafe.get(OpenAiConfig.key)
23
40
  )
24
41
  }
25
42
 
26
43
  /**
27
- * @since 1.0.0
44
+ * Types associated with the `OpenAiConfig` context service.
45
+ *
46
+ * @since 4.0.0
28
47
  */
29
48
  export declare namespace OpenAiConfig {
30
49
  /**
31
- * @since 1.0.
50
+ * Configuration consumed by OpenAI-compatible clients when they build or
51
+ * resolve the underlying HTTP client.
52
+ *
32
53
  * @category models
54
+ * @since 4.0.0
33
55
  */
34
56
  export interface Service {
35
57
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +59,54 @@ export declare namespace OpenAiConfig {
37
59
  }
38
60
 
39
61
  /**
40
- * @since 1.0.0
62
+ * Provides an HTTP client transform for the supplied effect.
63
+ *
64
+ * **When to use**
65
+ *
66
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
67
+ * headers, retries, instrumentation, or proxy routing.
68
+ *
69
+ * **Details**
70
+ *
71
+ * OpenAI-compatible provider services read the transform from the
72
+ * `OpenAiConfig` context.
73
+ *
41
74
  * @category configuration
75
+ * @since 4.0.0
42
76
  */
43
77
  export const withClientTransform: {
44
78
  /**
45
- * @since 1.0.0
79
+ * Provides an HTTP client transform for the supplied effect.
80
+ *
81
+ * **When to use**
82
+ *
83
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
84
+ * headers, retries, instrumentation, or proxy routing.
85
+ *
86
+ * **Details**
87
+ *
88
+ * OpenAI-compatible provider services read the transform from the
89
+ * `OpenAiConfig` context.
90
+ *
46
91
  * @category configuration
92
+ * @since 4.0.0
47
93
  */
48
94
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
95
  /**
50
- * @since 1.0.0
96
+ * Provides an HTTP client transform for the supplied effect.
97
+ *
98
+ * **When to use**
99
+ *
100
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
101
+ * headers, retries, instrumentation, or proxy routing.
102
+ *
103
+ * **Details**
104
+ *
105
+ * OpenAI-compatible provider services read the transform from the
106
+ * `OpenAiConfig` context.
107
+ *
51
108
  * @category configuration
109
+ * @since 4.0.0
52
110
  */
53
111
  <A, E, R>(
54
112
  self: Effect.Effect<A, E, R>,
@@ -0,0 +1,322 @@
1
+ /**
2
+ * The `OpenAiEmbeddingModel` module adapts OpenAI-compatible embeddings
3
+ * endpoints to Effect's embedding model service. It sends embedding requests
4
+ * through {@link OpenAiClient}, exposes constructors for layers and `AiModel`
5
+ * values, supports scoped request configuration overrides, and checks that the
6
+ * provider returns one numeric vector for each requested input.
7
+ *
8
+ * @since 4.0.0
9
+ */
10
+ import * as Context from "effect/Context"
11
+ import * as Effect from "effect/Effect"
12
+ import { dual } from "effect/Function"
13
+ import * as Layer from "effect/Layer"
14
+ import type { Simplify } from "effect/Types"
15
+ import * as AiError from "effect/unstable/ai/AiError"
16
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel"
17
+ import * as AiModel from "effect/unstable/ai/Model"
18
+ import type { CreateEmbedding200, CreateEmbeddingRequestJson } from "./OpenAiClient.ts"
19
+ import { OpenAiClient } from "./OpenAiClient.ts"
20
+
21
+ /**
22
+ * A model identifier accepted by an OpenAI-compatible embeddings endpoint.
23
+ *
24
+ * @category models
25
+ * @since 4.0.0
26
+ */
27
+ export type Model = string
28
+
29
+ type ConfigOptions = Simplify<Partial<Omit<CreateEmbeddingRequestJson, "input">>>
30
+ type ModelConfig = Omit<ConfigOptions, "model"> & { readonly [x: string]: unknown }
31
+
32
+ /**
33
+ * Context service for OpenAI embedding model configuration.
34
+ *
35
+ * **When to use**
36
+ *
37
+ * Use when you need to provide shared default request options for
38
+ * OpenAI-compatible embedding operations through the Effect context, such as
39
+ * `dimensions`, `encoding_format`, or `user`.
40
+ *
41
+ * **Details**
42
+ *
43
+ * The service stores the embedding request payload without `input`. Requests
44
+ * combine the selected model, layer or constructor config, and scoped context
45
+ * config, with scoped context config taking precedence.
46
+ *
47
+ * @see {@link withConfigOverride} for scoping embedding request overrides
48
+ *
49
+ * @category context
50
+ * @since 4.0.0
51
+ */
52
+ export class Config extends Context.Service<
53
+ Config,
54
+ ConfigOptions & { readonly [x: string]: unknown }
55
+ >()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
56
+
57
+ /**
58
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
59
+ *
60
+ * **When to use**
61
+ *
62
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
63
+ * service to an Effect program.
64
+ *
65
+ * @see {@link layer} for providing only the embedding model service
66
+ * @see {@link withConfigOverride} for scoped request configuration overrides
67
+ *
68
+ * @category constructors
69
+ * @since 4.0.0
70
+ */
71
+ export const model = (
72
+ model: string,
73
+ options: Omit<ConfigOptions, "model" | "dimensions"> & {
74
+ readonly dimensions: number
75
+ readonly [x: string]: unknown
76
+ }
77
+ ): AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient> =>
78
+ AiModel.make(
79
+ "openai",
80
+ model,
81
+ Layer.merge(
82
+ layer({
83
+ model,
84
+ config: options
85
+ }),
86
+ Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)
87
+ )
88
+ )
89
+
90
+ /**
91
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
92
+ *
93
+ * **When to use**
94
+ *
95
+ * Use when you need to build or provide an `EmbeddingModel` service directly
96
+ * from an existing `OpenAiClient`.
97
+ *
98
+ * **Details**
99
+ *
100
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
101
+ * Request config is merged as the selected model, constructor config, then
102
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
103
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
104
+ *
105
+ * **Gotchas**
106
+ *
107
+ * Provider responses must contain one numeric vector for every requested input
108
+ * with unique, in-range `index` values; otherwise embedding operations fail with
109
+ * `AiError.InvalidOutputError`.
110
+ *
111
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
112
+ * @see {@link layer} for providing the service as a `Layer`
113
+ * @see {@link withConfigOverride} for scoping embedding request overrides
114
+ *
115
+ * @category constructors
116
+ * @since 4.0.0
117
+ */
118
+ export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
119
+ readonly model: string
120
+ readonly config?: ModelConfig | undefined
121
+ }): Effect.fn.Return<EmbeddingModel.Service, never, OpenAiClient> {
122
+ const client = yield* OpenAiClient
123
+
124
+ const makeConfig = Effect.gen(function*() {
125
+ const services = yield* Effect.context<never>()
126
+ return { model, ...providerConfig, ...services.mapUnsafe.get(Config.key) }
127
+ })
128
+
129
+ return yield* EmbeddingModel.make({
130
+ embedMany: Effect.fnUntraced(function*({ inputs }) {
131
+ const config = yield* makeConfig
132
+ const response = yield* client.createEmbedding({ ...config, input: inputs })
133
+ return yield* mapProviderResponse(inputs.length, response)
134
+ })
135
+ })
136
+ })
137
+
138
+ /**
139
+ * Creates a layer for an OpenAI-compatible embedding model service.
140
+ *
141
+ * **When to use**
142
+ *
143
+ * Use when composing application layers and you want an OpenAI-compatible
144
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
145
+ * supplying `OpenAiClient` from another layer.
146
+ *
147
+ * @see {@link make} for constructing the embedding model service effectfully
148
+ * @see {@link model} for creating an `AiModel` with configured dimensions
149
+ *
150
+ * @category layers
151
+ * @since 4.0.0
152
+ */
153
+ export const layer = (options: {
154
+ readonly model: string
155
+ readonly config?: ModelConfig | undefined
156
+ }): Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient> =>
157
+ Layer.effect(EmbeddingModel.EmbeddingModel, make(options))
158
+
159
+ /**
160
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
161
+ *
162
+ * **When to use**
163
+ *
164
+ * Use to apply embedding request options to one effect without changing the
165
+ * model's default configuration.
166
+ *
167
+ * **Details**
168
+ *
169
+ * The overrides are merged with any existing `Config` service for the duration
170
+ * of the supplied effect. Fields in `overrides` take precedence over existing
171
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
172
+ * and `withConfigOverride(effect, overrides)`.
173
+ *
174
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
175
+ *
176
+ * @category configuration
177
+ * @since 4.0.0
178
+ */
179
+ export const withConfigOverride: {
180
+ /**
181
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
182
+ *
183
+ * **When to use**
184
+ *
185
+ * Use to apply embedding request options to one effect without changing the
186
+ * model's default configuration.
187
+ *
188
+ * **Details**
189
+ *
190
+ * The overrides are merged with any existing `Config` service for the duration
191
+ * of the supplied effect. Fields in `overrides` take precedence over existing
192
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
193
+ * and `withConfigOverride(effect, overrides)`.
194
+ *
195
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
196
+ *
197
+ * @category configuration
198
+ * @since 4.0.0
199
+ */
200
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
201
+ /**
202
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
203
+ *
204
+ * **When to use**
205
+ *
206
+ * Use to apply embedding request options to one effect without changing the
207
+ * model's default configuration.
208
+ *
209
+ * **Details**
210
+ *
211
+ * The overrides are merged with any existing `Config` service for the duration
212
+ * of the supplied effect. Fields in `overrides` take precedence over existing
213
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
214
+ * and `withConfigOverride(effect, overrides)`.
215
+ *
216
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
217
+ *
218
+ * @category configuration
219
+ * @since 4.0.0
220
+ */
221
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
222
+ } = dual<
223
+ /**
224
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
225
+ *
226
+ * **When to use**
227
+ *
228
+ * Use to apply embedding request options to one effect without changing the
229
+ * model's default configuration.
230
+ *
231
+ * **Details**
232
+ *
233
+ * The overrides are merged with any existing `Config` service for the duration
234
+ * of the supplied effect. Fields in `overrides` take precedence over existing
235
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
236
+ * and `withConfigOverride(effect, overrides)`.
237
+ *
238
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
239
+ *
240
+ * @category configuration
241
+ * @since 4.0.0
242
+ */
243
+ (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
244
+ /**
245
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
246
+ *
247
+ * **When to use**
248
+ *
249
+ * Use to apply embedding request options to one effect without changing the
250
+ * model's default configuration.
251
+ *
252
+ * **Details**
253
+ *
254
+ * The overrides are merged with any existing `Config` service for the duration
255
+ * of the supplied effect. Fields in `overrides` take precedence over existing
256
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
257
+ * and `withConfigOverride(effect, overrides)`.
258
+ *
259
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
260
+ *
261
+ * @category configuration
262
+ * @since 4.0.0
263
+ */
264
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
265
+ >(2, (self, overrides) =>
266
+ Effect.flatMap(
267
+ Effect.serviceOption(Config),
268
+ (config) =>
269
+ Effect.provideService(self, Config, {
270
+ ...(config._tag === "Some" ? config.value : {}),
271
+ ...overrides
272
+ })
273
+ ))
274
+
275
+ const mapProviderResponse = (
276
+ inputLength: number,
277
+ response: CreateEmbedding200
278
+ ): Effect.Effect<EmbeddingModel.ProviderResponse, AiError.AiError> => {
279
+ if (response.data.length !== inputLength) {
280
+ return Effect.fail(
281
+ invalidOutput(`Provider returned ${response.data.length} embeddings but expected ${inputLength}`)
282
+ )
283
+ }
284
+
285
+ const results = new Array<Array<number>>(inputLength)
286
+ const seen = new Set<number>()
287
+
288
+ for (const entry of response.data) {
289
+ if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
290
+ return Effect.fail(invalidOutput(`Provider returned invalid embedding index: ${entry.index}`))
291
+ }
292
+ if (seen.has(entry.index)) {
293
+ return Effect.fail(invalidOutput(`Provider returned duplicate embedding index: ${entry.index}`))
294
+ }
295
+ if (!Array.isArray(entry.embedding)) {
296
+ return Effect.fail(invalidOutput(`Provider returned non-vector embedding at index ${entry.index}`))
297
+ }
298
+
299
+ seen.add(entry.index)
300
+ results[entry.index] = [...entry.embedding]
301
+ }
302
+
303
+ if (seen.size !== inputLength) {
304
+ return Effect.fail(
305
+ invalidOutput(`Provider returned embeddings for ${seen.size} inputs but expected ${inputLength}`)
306
+ )
307
+ }
308
+
309
+ return Effect.succeed({
310
+ results,
311
+ usage: {
312
+ inputTokens: response.usage?.prompt_tokens
313
+ }
314
+ })
315
+ }
316
+
317
+ const invalidOutput = (description: string): AiError.AiError =>
318
+ AiError.make({
319
+ module: "OpenAiEmbeddingModel",
320
+ method: "embedMany",
321
+ reason: new AiError.InvalidOutputError({ description })
322
+ })
@@ -1,12 +1,25 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiError` module defines OpenAI-specific metadata that can be
3
+ * attached to the shared `AiError` error types used by the AI packages. It is
4
+ * primarily used by OpenAI-compatible clients to preserve provider details
5
+ * such as error codes, error types, request IDs, and rate limit headers while
6
+ * still exposing errors through the provider-neutral Effect AI error model.
7
+ *
8
+ * Use this module when mapping OpenAI API failures into `AiError` values and
9
+ * when consumers need enough structured metadata to debug failed requests,
10
+ * inspect quota or rate limit responses, or correlate an error with OpenAI
11
+ * support. The exported types are metadata shapes only; the module augmentation
12
+ * makes those shapes available on the corresponding shared AI error metadata
13
+ * interfaces without defining new runtime error classes.
14
+ *
15
+ * @since 4.0.0
3
16
  */
4
17
 
5
18
  /**
6
19
  * OpenAI-specific error metadata fields.
7
20
  *
8
- * @since 1.0.0
9
21
  * @category models
22
+ * @since 4.0.0
10
23
  */
11
24
  export type OpenAiErrorMetadata = {
12
25
  /**
@@ -26,11 +39,13 @@ export type OpenAiErrorMetadata = {
26
39
  /**
27
40
  * OpenAI-specific rate limit metadata fields.
28
41
  *
42
+ * **Details**
43
+ *
29
44
  * Extends base error metadata with rate limit specific information from
30
45
  * OpenAI's rate limit headers.
31
46
  *
32
- * @since 1.0.0
33
47
  * @category models
48
+ * @since 4.0.0
34
49
  */
35
50
  export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
36
51
  /**
@@ -52,51 +67,112 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
52
67
  }
53
68
 
54
69
  declare module "effect/unstable/ai/AiError" {
55
- export interface RateLimitError {
56
- readonly metadata: {
57
- readonly openai?: OpenAiRateLimitMetadata | null
58
- }
70
+ /**
71
+ * Metadata attached to rate limit errors returned by OpenAI-compatible APIs.
72
+ *
73
+ * @category models
74
+ * @since 4.0.0
75
+ */
76
+ export interface RateLimitErrorMetadata {
77
+ readonly openai?: OpenAiRateLimitMetadata | null
59
78
  }
60
79
 
61
- export interface QuotaExhaustedError {
62
- readonly metadata: {
63
- readonly openai?: OpenAiErrorMetadata | null
64
- }
80
+ /**
81
+ * Metadata attached when an OpenAI-compatible provider reports that quota or
82
+ * billing limits have been exhausted.
83
+ *
84
+ * @category models
85
+ * @since 4.0.0
86
+ */
87
+ export interface QuotaExhaustedErrorMetadata {
88
+ readonly openai?: OpenAiErrorMetadata | null
65
89
  }
66
90
 
67
- export interface AuthenticationError {
68
- readonly metadata: {
69
- readonly openai?: OpenAiErrorMetadata | null
70
- }
91
+ /**
92
+ * Metadata attached to authentication failures from OpenAI-compatible APIs,
93
+ * such as invalid, missing, or unauthorized API credentials.
94
+ *
95
+ * @category models
96
+ * @since 4.0.0
97
+ */
98
+ export interface AuthenticationErrorMetadata {
99
+ readonly openai?: OpenAiErrorMetadata | null
71
100
  }
72
101
 
73
- export interface ContentPolicyError {
74
- readonly metadata: {
75
- readonly openai?: OpenAiErrorMetadata | null
76
- }
102
+ /**
103
+ * Metadata attached when an OpenAI-compatible provider rejects content because
104
+ * it violates a safety or usage policy.
105
+ *
106
+ * @category models
107
+ * @since 4.0.0
108
+ */
109
+ export interface ContentPolicyErrorMetadata {
110
+ readonly openai?: OpenAiErrorMetadata | null
77
111
  }
78
112
 
79
- export interface InvalidRequestError {
80
- readonly metadata: {
81
- readonly openai?: OpenAiErrorMetadata | null
82
- }
113
+ /**
114
+ * Metadata attached to malformed or unsupported requests rejected by an
115
+ * OpenAI-compatible API before model execution.
116
+ *
117
+ * @category models
118
+ * @since 4.0.0
119
+ */
120
+ export interface InvalidRequestErrorMetadata {
121
+ readonly openai?: OpenAiErrorMetadata | null
83
122
  }
84
123
 
85
- export interface InternalProviderError {
86
- readonly metadata: {
87
- readonly openai?: OpenAiErrorMetadata | null
88
- }
124
+ /**
125
+ * Metadata attached to unexpected server-side failures reported by an
126
+ * OpenAI-compatible provider.
127
+ *
128
+ * @category models
129
+ * @since 4.0.0
130
+ */
131
+ export interface InternalProviderErrorMetadata {
132
+ readonly openai?: OpenAiErrorMetadata | null
89
133
  }
90
134
 
91
- export interface InvalidOutputError {
92
- readonly metadata: {
93
- readonly openai?: OpenAiErrorMetadata | null
94
- }
135
+ /**
136
+ * Metadata attached when an OpenAI-compatible response cannot be converted
137
+ * into the expected AI package output shape.
138
+ *
139
+ * @category models
140
+ * @since 4.0.0
141
+ */
142
+ export interface InvalidOutputErrorMetadata {
143
+ readonly openai?: OpenAiErrorMetadata | null
144
+ }
145
+
146
+ /**
147
+ * Metadata attached when an OpenAI-compatible structured output response does
148
+ * not satisfy the requested schema or parsing constraints.
149
+ *
150
+ * @category models
151
+ * @since 4.0.0
152
+ */
153
+ export interface StructuredOutputErrorMetadata {
154
+ readonly openai?: OpenAiErrorMetadata | null
95
155
  }
96
156
 
97
- export interface UnknownError {
98
- readonly metadata: {
99
- readonly openai?: OpenAiErrorMetadata | null
100
- }
157
+ /**
158
+ * Metadata attached when an OpenAI-compatible provider cannot support the
159
+ * schema supplied for structured output or tool definitions.
160
+ *
161
+ * @category models
162
+ * @since 4.0.0
163
+ */
164
+ export interface UnsupportedSchemaErrorMetadata {
165
+ readonly openai?: OpenAiErrorMetadata | null
166
+ }
167
+
168
+ /**
169
+ * Metadata attached when an OpenAI-compatible error response cannot be mapped
170
+ * to a more specific shared AI error category.
171
+ *
172
+ * @category models
173
+ * @since 4.0.0
174
+ */
175
+ export interface UnknownErrorMetadata {
176
+ readonly openai?: OpenAiErrorMetadata | null
101
177
  }
102
178
  }