@effect/ai-openai-compat 4.0.0-beta.7 → 4.0.0-beta.71

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 (38) hide show
  1. package/dist/OpenAiClient.d.ts +250 -51
  2. package/dist/OpenAiClient.d.ts.map +1 -1
  3. package/dist/OpenAiClient.js +108 -9
  4. package/dist/OpenAiClient.js.map +1 -1
  5. package/dist/OpenAiConfig.d.ts +83 -10
  6. package/dist/OpenAiConfig.d.ts.map +1 -1
  7. package/dist/OpenAiConfig.js +51 -7
  8. package/dist/OpenAiConfig.js.map +1 -1
  9. package/dist/OpenAiEmbeddingModel.d.ts +214 -0
  10. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  11. package/dist/OpenAiEmbeddingModel.js +218 -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 +326 -18
  17. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  18. package/dist/OpenAiLanguageModel.js +126 -25
  19. package/dist/OpenAiLanguageModel.js.map +1 -1
  20. package/dist/OpenAiTelemetry.d.ts +72 -22
  21. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  22. package/dist/OpenAiTelemetry.js +47 -8
  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/package.json +3 -3
  31. package/src/OpenAiClient.ts +283 -49
  32. package/src/OpenAiConfig.ts +84 -11
  33. package/src/OpenAiEmbeddingModel.ts +360 -0
  34. package/src/OpenAiError.ts +111 -35
  35. package/src/OpenAiLanguageModel.ts +409 -40
  36. package/src/OpenAiTelemetry.ts +103 -27
  37. package/src/index.ts +11 -17
  38. package/src/internal/errors.ts +4 -4
@@ -1,35 +1,72 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module provides shared configuration for clients that
3
+ * talk to OpenAI-compatible APIs. It is used to customize the HTTP client
4
+ * wiring around a provider without changing the higher-level model,
5
+ * embeddings, or tool-calling APIs that consume the client.
6
+ *
7
+ * **Common tasks**
8
+ *
9
+ * - Install a client transform with {@link withClientTransform}
10
+ * - Add provider-specific HTTP behavior, such as headers, retries, proxies, or
11
+ * instrumentation
12
+ * - Read the active configuration from the Effect context when implementing
13
+ * OpenAI-compatible integrations
14
+ *
15
+ * **Gotchas**
16
+ *
17
+ * - The transform receives and returns an `HttpClient`, so it should preserve
18
+ * the existing client behavior unless it intentionally replaces it
19
+ * - Configuration is provided through Effect context and is scoped to the
20
+ * effect that receives the service
21
+ *
22
+ * @since 4.0.0
3
23
  */
24
+ import * as Context from "effect/Context"
4
25
  import * as Effect from "effect/Effect"
5
26
  import { dual } from "effect/Function"
6
- import * as ServiceMap from "effect/ServiceMap"
7
27
  import type { HttpClient } from "effect/unstable/http/HttpClient"
8
28
 
9
29
  /**
10
- * @since 1.0.0
30
+ * Context service used to carry OpenAI-compatible client configuration for the
31
+ * current Effect scope.
32
+ *
33
+ * **When to use**
34
+ *
35
+ * Use as the context service for OpenAI-compatible client configuration when you
36
+ * need to provide or read scoped HTTP client transforms through Effect context.
37
+ *
38
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
39
+ *
11
40
  * @category services
41
+ * @since 4.0.0
12
42
  */
13
- export class OpenAiConfig extends ServiceMap.Service<
43
+ export class OpenAiConfig extends Context.Service<
14
44
  OpenAiConfig,
15
45
  OpenAiConfig.Service
16
46
  >()("@effect/ai-openai-compat/OpenAiConfig") {
17
47
  /**
18
- * @since 1.0.0
48
+ * Gets the configured OpenAI-compatible service from the current context when present.
49
+ *
50
+ * @since 4.0.0
19
51
  */
20
52
  static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined> = Effect.map(
21
- Effect.services<never>(),
53
+ Effect.context<never>(),
22
54
  (context) => context.mapUnsafe.get(OpenAiConfig.key)
23
55
  )
24
56
  }
25
57
 
26
58
  /**
27
- * @since 1.0.0
59
+ * Types associated with the `OpenAiConfig` context service.
60
+ *
61
+ * @since 4.0.0
28
62
  */
29
63
  export declare namespace OpenAiConfig {
30
64
  /**
31
- * @since 1.0.
65
+ * Configuration consumed by OpenAI-compatible clients when they build or
66
+ * resolve the underlying HTTP client.
67
+ *
32
68
  * @category models
69
+ * @since 4.0.0
33
70
  */
34
71
  export interface Service {
35
72
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +74,54 @@ export declare namespace OpenAiConfig {
37
74
  }
38
75
 
39
76
  /**
40
- * @since 1.0.0
77
+ * Provides an HTTP client transform for the supplied effect.
78
+ *
79
+ * **When to use**
80
+ *
81
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
82
+ * headers, retries, instrumentation, or proxy routing.
83
+ *
84
+ * **Details**
85
+ *
86
+ * OpenAI-compatible provider services read the transform from the
87
+ * `OpenAiConfig` context.
88
+ *
41
89
  * @category configuration
90
+ * @since 4.0.0
42
91
  */
43
92
  export const withClientTransform: {
44
93
  /**
45
- * @since 1.0.0
94
+ * Provides an HTTP client transform for the supplied effect.
95
+ *
96
+ * **When to use**
97
+ *
98
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
99
+ * headers, retries, instrumentation, or proxy routing.
100
+ *
101
+ * **Details**
102
+ *
103
+ * OpenAI-compatible provider services read the transform from the
104
+ * `OpenAiConfig` context.
105
+ *
46
106
  * @category configuration
107
+ * @since 4.0.0
47
108
  */
48
109
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
110
  /**
50
- * @since 1.0.0
111
+ * Provides an HTTP client transform for the supplied effect.
112
+ *
113
+ * **When to use**
114
+ *
115
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
116
+ * headers, retries, instrumentation, or proxy routing.
117
+ *
118
+ * **Details**
119
+ *
120
+ * OpenAI-compatible provider services read the transform from the
121
+ * `OpenAiConfig` context.
122
+ *
51
123
  * @category configuration
124
+ * @since 4.0.0
52
125
  */
53
126
  <A, E, R>(
54
127
  self: Effect.Effect<A, E, R>,
@@ -0,0 +1,360 @@
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, and supports scoped request configuration overrides.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * - {@link make} builds the `EmbeddingModel` service when an
10
+ * {@link OpenAiClient} is already available.
11
+ * - {@link layer} provides that service as a `Layer`.
12
+ * - {@link model} creates an `AiModel` and also provides the configured vector
13
+ * dimensions service expected by embedding consumers.
14
+ * - {@link Config} and {@link withConfigOverride} merge default request options
15
+ * with scoped overrides for individual operations.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Use {@link model} when application code wants a named `AiModel` with known
20
+ * dimensions.
21
+ * - Use {@link layer} when composing services around an existing
22
+ * {@link OpenAiClient} layer.
23
+ * - Use {@link withConfigOverride} to set per-operation options such as `user`,
24
+ * `dimensions`, or provider-specific request fields.
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * - {@link Model} is `string` because OpenAI-compatible providers use their
29
+ * own embedding model identifiers.
30
+ * - {@link model} requires explicit dimensions because compatible providers do
31
+ * not expose a shared way to infer vector width.
32
+ * - Provider responses must contain one numeric vector per input with unique,
33
+ * in-range indexes; base64 embeddings or malformed indexes fail with
34
+ * `InvalidOutputError`.
35
+ *
36
+ * @since 4.0.0
37
+ */
38
+ import * as Context from "effect/Context"
39
+ import * as Effect from "effect/Effect"
40
+ import { dual } from "effect/Function"
41
+ import * as Layer from "effect/Layer"
42
+ import type { Simplify } from "effect/Types"
43
+ import * as AiError from "effect/unstable/ai/AiError"
44
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel"
45
+ import * as AiModel from "effect/unstable/ai/Model"
46
+ import type { CreateEmbedding200, CreateEmbeddingRequestJson } from "./OpenAiClient.ts"
47
+ import { OpenAiClient } from "./OpenAiClient.ts"
48
+
49
+ /**
50
+ * A model identifier accepted by an OpenAI-compatible embeddings endpoint.
51
+ *
52
+ * @category models
53
+ * @since 4.0.0
54
+ */
55
+ export type Model = string
56
+
57
+ /**
58
+ * Service definition for OpenAI embedding model configuration.
59
+ *
60
+ * **When to use**
61
+ *
62
+ * Use when you need to provide shared default request options for
63
+ * OpenAI-compatible embedding operations through the Effect context, such as
64
+ * `dimensions`, `encoding_format`, or `user`.
65
+ *
66
+ * **Details**
67
+ *
68
+ * The service stores the embedding request payload without `input`. Requests
69
+ * combine the selected model, layer or constructor config, and scoped context
70
+ * config, with scoped context config taking precedence.
71
+ *
72
+ * @see {@link withConfigOverride} for scoping embedding request overrides
73
+ *
74
+ * @category context
75
+ * @since 4.0.0
76
+ */
77
+ export class Config extends Context.Service<
78
+ Config,
79
+ Simplify<
80
+ & Partial<
81
+ Omit<
82
+ CreateEmbeddingRequestJson,
83
+ "input"
84
+ >
85
+ >
86
+ & {
87
+ readonly [x: string]: unknown
88
+ }
89
+ >
90
+ >()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
91
+
92
+ /**
93
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
94
+ *
95
+ * **When to use**
96
+ *
97
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
98
+ * service to an Effect program.
99
+ *
100
+ * @see {@link layer} for providing only the embedding model service
101
+ * @see {@link withConfigOverride} for scoped request configuration overrides
102
+ *
103
+ * @category constructors
104
+ * @since 4.0.0
105
+ */
106
+ export const model = (
107
+ model: string,
108
+ options: {
109
+ readonly dimensions: number
110
+ readonly config?: Omit<typeof Config.Service, "model" | "dimensions">
111
+ }
112
+ ): AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient> =>
113
+ AiModel.make(
114
+ "openai",
115
+ model,
116
+ Layer.merge(
117
+ layer({
118
+ model,
119
+ config: {
120
+ ...options.config,
121
+ dimensions: options.dimensions
122
+ }
123
+ }),
124
+ Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)
125
+ )
126
+ )
127
+
128
+ /**
129
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
130
+ *
131
+ * **When to use**
132
+ *
133
+ * Use when you need to build or provide an `EmbeddingModel` service directly
134
+ * from an existing `OpenAiClient`.
135
+ *
136
+ * **Details**
137
+ *
138
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
139
+ * Request config is merged as the selected model, constructor config, then
140
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
141
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
142
+ *
143
+ * **Gotchas**
144
+ *
145
+ * Provider responses must contain one numeric vector for every requested input
146
+ * with unique, in-range `index` values; otherwise embedding operations fail with
147
+ * `AiError.InvalidOutputError`.
148
+ *
149
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
150
+ * @see {@link layer} for providing the service as a `Layer`
151
+ * @see {@link withConfigOverride} for scoping embedding request overrides
152
+ *
153
+ * @category constructors
154
+ * @since 4.0.0
155
+ */
156
+ export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
157
+ readonly model: string
158
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined
159
+ }): Effect.fn.Return<EmbeddingModel.Service, never, OpenAiClient> {
160
+ const client = yield* OpenAiClient
161
+
162
+ const makeConfig = Effect.gen(function*() {
163
+ const services = yield* Effect.context<never>()
164
+ return { model, ...providerConfig, ...services.mapUnsafe.get(Config.key) }
165
+ })
166
+
167
+ return yield* EmbeddingModel.make({
168
+ embedMany: Effect.fnUntraced(function*({ inputs }) {
169
+ const config = yield* makeConfig
170
+ const response = yield* client.createEmbedding({ ...config, input: inputs })
171
+ return yield* mapProviderResponse(inputs.length, response)
172
+ })
173
+ })
174
+ })
175
+
176
+ /**
177
+ * Creates a layer for an OpenAI-compatible embedding model service.
178
+ *
179
+ * **When to use**
180
+ *
181
+ * Use when composing application layers and you want an OpenAI-compatible
182
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
183
+ * supplying `OpenAiClient` from another layer.
184
+ *
185
+ * @see {@link make} for constructing the embedding model service effectfully
186
+ * @see {@link model} for creating an `AiModel` with configured dimensions
187
+ *
188
+ * @category layers
189
+ * @since 4.0.0
190
+ */
191
+ export const layer = (options: {
192
+ readonly model: string
193
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined
194
+ }): Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient> =>
195
+ Layer.effect(EmbeddingModel.EmbeddingModel, make(options))
196
+
197
+ /**
198
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
199
+ *
200
+ * **When to use**
201
+ *
202
+ * Use to apply embedding request options to one effect without changing the
203
+ * model's default configuration.
204
+ *
205
+ * **Details**
206
+ *
207
+ * The overrides are merged with any existing `Config` service for the duration
208
+ * of the supplied effect. Fields in `overrides` take precedence over existing
209
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
210
+ * and `withConfigOverride(effect, overrides)`.
211
+ *
212
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
213
+ *
214
+ * @category configuration
215
+ * @since 4.0.0
216
+ */
217
+ export const withConfigOverride: {
218
+ /**
219
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
220
+ *
221
+ * **When to use**
222
+ *
223
+ * Use to apply embedding request options to one effect without changing the
224
+ * model's default configuration.
225
+ *
226
+ * **Details**
227
+ *
228
+ * The overrides are merged with any existing `Config` service for the duration
229
+ * of the supplied effect. Fields in `overrides` take precedence over existing
230
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
231
+ * and `withConfigOverride(effect, overrides)`.
232
+ *
233
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
234
+ *
235
+ * @category configuration
236
+ * @since 4.0.0
237
+ */
238
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
239
+ /**
240
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
241
+ *
242
+ * **When to use**
243
+ *
244
+ * Use to apply embedding request options to one effect without changing the
245
+ * model's default configuration.
246
+ *
247
+ * **Details**
248
+ *
249
+ * The overrides are merged with any existing `Config` service for the duration
250
+ * of the supplied effect. Fields in `overrides` take precedence over existing
251
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
252
+ * and `withConfigOverride(effect, overrides)`.
253
+ *
254
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
255
+ *
256
+ * @category configuration
257
+ * @since 4.0.0
258
+ */
259
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
260
+ } = dual<
261
+ /**
262
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
263
+ *
264
+ * **When to use**
265
+ *
266
+ * Use to apply embedding request options to one effect without changing the
267
+ * model's default configuration.
268
+ *
269
+ * **Details**
270
+ *
271
+ * The overrides are merged with any existing `Config` service for the duration
272
+ * of the supplied effect. Fields in `overrides` take precedence over existing
273
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
274
+ * and `withConfigOverride(effect, overrides)`.
275
+ *
276
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
277
+ *
278
+ * @category configuration
279
+ * @since 4.0.0
280
+ */
281
+ (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
282
+ /**
283
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
284
+ *
285
+ * **When to use**
286
+ *
287
+ * Use to apply embedding request options to one effect without changing the
288
+ * model's default configuration.
289
+ *
290
+ * **Details**
291
+ *
292
+ * The overrides are merged with any existing `Config` service for the duration
293
+ * of the supplied effect. Fields in `overrides` take precedence over existing
294
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
295
+ * and `withConfigOverride(effect, overrides)`.
296
+ *
297
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
298
+ *
299
+ * @category configuration
300
+ * @since 4.0.0
301
+ */
302
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
303
+ >(2, (self, overrides) =>
304
+ Effect.flatMap(
305
+ Effect.serviceOption(Config),
306
+ (config) =>
307
+ Effect.provideService(self, Config, {
308
+ ...(config._tag === "Some" ? config.value : {}),
309
+ ...overrides
310
+ })
311
+ ))
312
+
313
+ const mapProviderResponse = (
314
+ inputLength: number,
315
+ response: CreateEmbedding200
316
+ ): Effect.Effect<EmbeddingModel.ProviderResponse, AiError.AiError> => {
317
+ if (response.data.length !== inputLength) {
318
+ return Effect.fail(
319
+ invalidOutput(`Provider returned ${response.data.length} embeddings but expected ${inputLength}`)
320
+ )
321
+ }
322
+
323
+ const results = new Array<Array<number>>(inputLength)
324
+ const seen = new Set<number>()
325
+
326
+ for (const entry of response.data) {
327
+ if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
328
+ return Effect.fail(invalidOutput(`Provider returned invalid embedding index: ${entry.index}`))
329
+ }
330
+ if (seen.has(entry.index)) {
331
+ return Effect.fail(invalidOutput(`Provider returned duplicate embedding index: ${entry.index}`))
332
+ }
333
+ if (!Array.isArray(entry.embedding)) {
334
+ return Effect.fail(invalidOutput(`Provider returned non-vector embedding at index ${entry.index}`))
335
+ }
336
+
337
+ seen.add(entry.index)
338
+ results[entry.index] = [...entry.embedding]
339
+ }
340
+
341
+ if (seen.size !== inputLength) {
342
+ return Effect.fail(
343
+ invalidOutput(`Provider returned embeddings for ${seen.size} inputs but expected ${inputLength}`)
344
+ )
345
+ }
346
+
347
+ return Effect.succeed({
348
+ results,
349
+ usage: {
350
+ inputTokens: response.usage?.prompt_tokens
351
+ }
352
+ })
353
+ }
354
+
355
+ const invalidOutput = (description: string): AiError.AiError =>
356
+ AiError.make({
357
+ module: "OpenAiEmbeddingModel",
358
+ method: "embedMany",
359
+ reason: new AiError.InvalidOutputError({ description })
360
+ })
@@ -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
  }