@kreuzberg/liter-llm-node 1.4.0-rc.28 → 1.4.0-rc.30

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.
package/index.d.ts CHANGED
@@ -1,111 +1,174 @@
1
- /* auto-generated by NAPI-RS */
1
+ // This file is auto-generated by alef — DO NOT EDIT.
2
+ // alef:hash:d12bcb594ac4097c8a2d25bc4b4843fd604dc2a976a3c18c612c61f69ee6e297
3
+ // To regenerate: alef generate
4
+ // To verify freshness: alef verify --exit-code
5
+ // Issues & docs: https://github.com/kreuzberg-dev/alef
2
6
  /* eslint-disable */
7
+
8
+ export type JsonValue =
9
+ | string
10
+ | number
11
+ | boolean
12
+ | null
13
+ | JsonValue[]
14
+ | { [key: string]: JsonValue };
15
+
3
16
  /**
4
- * This type implements JavaScript's async iterable protocol.
5
- * It can be used with `for await...of` loops.
17
+ * Return all provider configs from the registry.
6
18
  *
7
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
19
+ * Useful for tooling, documentation generation, or runtime enumeration.
8
20
  */
9
- export declare class ChatStreamIterator {}
21
+ export declare function allProviders(): Array<ProviderConfig>;
10
22
 
11
23
  /**
12
- * Default client implementation backed by `reqwest`.
24
+ * Calculate the estimated cost of a completion given a model name and token
25
+ * counts.
13
26
  *
14
- * Sends requests to 140+ LLM providers with automatic provider detection
15
- * and per-request routing. The provider is resolved at construction time
16
- * from `model_hint` (or defaults to OpenAI), but individual requests can
17
- * override the provider via model name prefix (e.g. `"anthropic/claude-3-5-sonnet"`
18
- * routes to Anthropic regardless of construction-time setting).
27
+ * Returns `None` if the model is not present in the embedded pricing registry.
28
+ * Returns `Some(cost_usd)` otherwise, where the value is in US dollars.
19
29
  *
20
- * When the model prefix does not match any known provider, the construction-time
21
- * provider is used as the fallback. This enables seamless migration between
22
- * providers by changing only the model name.
30
+ * When an exact model name match is not found, progressively shorter prefixes
31
+ * are tried by stripping from the last `-` or `.` separator. For example,
32
+ * `gpt-4-0613` will match `gpt-4` if no `gpt-4-0613` entry exists.
33
+ */
34
+ export declare function completionCost(
35
+ model: string,
36
+ promptTokens: number,
37
+ completionTokens: number,
38
+ ): number | null;
39
+
40
+ /**
41
+ * Calculate the estimated cost of a completion, accounting for cached
42
+ * (cache-hit) prompt tokens billed at the provider's discounted rate.
23
43
  *
24
- * The provider is stored behind an `Arc` so it can be shared cheaply into
25
- * async closures and streaming tasks. Pre-computed auth headers and extra
26
- * headers are cached at construction to avoid redundant encoding on every request.
44
+ * `cached_tokens` is the count of prompt tokens served from the provider's
45
+ * prompt cache. It must be `<= prompt_tokens` (cached tokens are a subset of
46
+ * the prompt). The non-cached portion is billed at `input_cost_per_token`
47
+ * and the cached portion at `cache_read_input_token_cost` when the model
48
+ * has cache pricing; otherwise the entire prompt is billed at the regular
49
+ * input rate.
50
+ *
51
+ * Returns `None` if the model is not present in the embedded pricing
52
+ * registry, mirroring [`completion_cost`].
27
53
  */
28
- export declare class DefaultClient {
29
- chat(req: ChatCompletionRequest): Promise<ChatCompletionResponse>;
30
- chatStream(req: ChatCompletionRequest): Promise<ChatStreamIterator>;
31
- embed(req: EmbeddingRequest): Promise<EmbeddingResponse>;
32
- listModels(): Promise<ModelsListResponse>;
33
- imageGenerate(req: CreateImageRequest): Promise<ImagesResponse>;
34
- speech(req: CreateSpeechRequest): Promise<Buffer>;
35
- transcribe(req: CreateTranscriptionRequest): Promise<TranscriptionResponse>;
36
- moderate(req: ModerationRequest): Promise<ModerationResponse>;
37
- rerank(req: RerankRequest): Promise<RerankResponse>;
38
- search(req: SearchRequest): Promise<SearchResponse>;
39
- ocr(req: OcrRequest): Promise<OcrResponse>;
40
- createFile(req: CreateFileRequest): Promise<FileObject>;
41
- retrieveFile(fileId: string): Promise<FileObject>;
42
- deleteFile(fileId: string): Promise<DeleteResponse>;
43
- listFiles(query?: FileListQuery | undefined | null): Promise<FileListResponse>;
44
- fileContent(fileId: string): Promise<Buffer>;
45
- createBatch(req: CreateBatchRequest): Promise<BatchObject>;
46
- retrieveBatch(batchId: string): Promise<BatchObject>;
47
- listBatches(query?: BatchListQuery | undefined | null): Promise<BatchListResponse>;
48
- cancelBatch(batchId: string): Promise<BatchObject>;
49
- createResponse(req: CreateResponseRequest): Promise<ResponseObject>;
50
- retrieveResponse(responseId: string): Promise<ResponseObject>;
51
- cancelResponse(responseId: string): Promise<ResponseObject>;
52
- }
53
- export type JsDefaultClient = DefaultClient;
54
+ export declare function completionCostWithCache(
55
+ model: string,
56
+ promptTokens: number,
57
+ cachedTokens: number,
58
+ completionTokens: number,
59
+ ): number | null;
54
60
 
55
- export declare class JsLiterLlmErrorInfo {
56
- statusCode: number;
57
- isTransient: boolean;
58
- errorType: string;
59
- /** HTTP status code for this error (0 means no associated status). */
60
- statusCode(): number;
61
- /** Returns `true` if the error is transient and a retry may succeed. */
62
- isTransient(): boolean;
63
- /** Machine-readable error category string for matching and logging. */
64
- errorType(): string;
65
- }
61
+ /**
62
+ * Return the set of complex provider names.
63
+ *
64
+ * Complex providers require custom auth/routing logic beyond simple bearer
65
+ * tokens (e.g. AWS Bedrock SigV4, Vertex AI OAuth2).
66
+ *
67
+ * The returned reference points into the static registry no allocation.
68
+ */
69
+ export declare function complexProviderNames(): Array<string>;
66
70
 
67
71
  /**
68
- * Return all provider configs from the registry.
72
+ * Count tokens for a full [`ChatCompletionRequest`].
69
73
  *
70
- * Useful for tooling, documentation generation, or runtime enumeration.
74
+ * Sums tokens across all message text contents plus a per-message overhead
75
+ * of ~4 tokens (for role, separators, and formatting metadata). Tool
76
+ * definitions and multimodal content parts (images, audio, documents) are
77
+ * not counted — only textual content contributes to the token total.
78
+ * @throws Returns [`LiterLlmError::BadRequest`] if the tokenizer cannot be loaded or
79
+ * if tokenization fails for any message.
71
80
  */
72
- export declare function allProviders(): Array<ProviderConfig>;
81
+ export declare function countRequestTokens(model: string, req: ChatCompletionRequest): number;
82
+
83
+ /**
84
+ * Count tokens in a text string using the tokenizer for the given model.
85
+ *
86
+ * The tokenizer is resolved from the model name prefix (e.g. `"gpt-4o"` maps
87
+ * to the `Xenova/gpt-4o` HuggingFace tokenizer). Tokenizers are cached after
88
+ * first load.
89
+ * @throws Returns [`LiterLlmError::BadRequest`] if the tokenizer cannot be loaded
90
+ * (e.g. network failure on first use) or if tokenization itself fails.
91
+ */
92
+ export declare function countTokens(model: string, text: string): number;
93
+
94
+ /**
95
+ * Create a new LLM client with simple scalar configuration.
96
+ *
97
+ * This is the primary binding entry-point. All parameters except `api_key`
98
+ * are optional — omitting them uses the same defaults as
99
+ * [`ClientConfigBuilder`].
100
+ * @throws Returns [`LiterLlmError`] if the underlying HTTP client cannot be
101
+ * constructed, or if the resolved provider configuration is invalid.
102
+ */
103
+ export declare function createClient(
104
+ apiKey: string,
105
+ baseUrl?: string | undefined | null,
106
+ timeoutSecs?: number | undefined | null,
107
+ maxRetries?: number | undefined | null,
108
+ modelHint?: string | undefined | null,
109
+ ): DefaultClient;
110
+
111
+ /**
112
+ * Create a new LLM client from a JSON string.
113
+ *
114
+ * The JSON object accepts the same fields as `liter-llm.toml` (snake_case).
115
+ * @throws Returns [`LiterLlmError::BadRequest`] if `json` is not valid JSON or
116
+ * contains unknown fields.
117
+ */
118
+ export declare function createClientFromJson(json: string): DefaultClient;
119
+
120
+ /**
121
+ * Install the `ring` crypto provider as the rustls process default, idempotently.
122
+ *
123
+ * rustls 0.23+ removed the implicit default provider. This function installs
124
+ * `ring` once per process. Subsequent calls are no-ops. Calling it from a
125
+ * downstream Rust app that has already installed `aws-lc-rs` is safe — the
126
+ * `Err` from `install_default()` is silently ignored.
127
+ *
128
+ * Called automatically by every internal `reqwest::Client` constructor
129
+ * (auth providers, default HTTP client). Bindings and downstream consumers
130
+ * reach those constructors transitively, so no manual init is required.
131
+ *
132
+ * WASM builds are exempt — the WASM target uses the browser/Node.js fetch
133
+ * API instead of rustls, so no crypto provider is needed.
134
+ */
135
+ export declare function ensureCryptoProvider(): void;
73
136
 
74
137
  /** Assistant's response to a user message. */
75
138
  export interface AssistantMessage {
76
139
  /** The assistant's text response. Absent if tool calls are returned instead. */
77
- content?: string;
140
+ readonly content?: string;
78
141
  /** Optional name for the assistant. */
79
- name?: string;
142
+ readonly name?: string;
80
143
  /** Tool calls the model wants to execute, if any. */
81
- toolCalls?: Array<JsToolCall>;
144
+ readonly toolCalls?: Array<ToolCall>;
82
145
  /** Refusal reason, if the model declined to respond per safety policies. */
83
- refusal?: string;
146
+ readonly refusal?: string;
84
147
  /** Deprecated legacy function_call field; retained for API compatibility. */
85
- functionCall?: JsFunctionCall;
148
+ readonly functionCall?: FunctionCall;
86
149
  }
87
150
 
88
151
  /** Audio content part for speech-capable models. */
89
152
  export interface AudioContent {
90
153
  /** Base64-encoded audio data. */
91
- data?: string;
154
+ readonly data?: string;
92
155
  /** Audio format (e.g., "wav", "mp3", "ogg"). */
93
- format?: string;
156
+ readonly format?: string;
94
157
  }
95
158
 
96
159
  /** Auth configuration block. */
97
160
  export interface AuthConfig {
98
161
  /** Auth scheme classification. */
99
- type: JsAuthType;
162
+ readonly authType: AuthType;
100
163
  /**
101
164
  * Name of the environment variable that holds the API key (e.g. `"OPENAI_API_KEY"`).
102
165
  * Holds the variable name, never the secret value.
103
166
  */
104
- envVar?: string;
167
+ readonly envVar?: string;
105
168
  }
106
169
 
107
170
  /** How the API key is sent in the HTTP request. */
108
- export declare const enum AuthHeaderFormat {
171
+ export declare enum AuthHeaderFormat {
109
172
  /** Bearer token: `Authorization: Bearer <key>` */
110
173
  Bearer = "Bearer",
111
174
  /** Custom header: e.g., `X-Api-Key: <key>` */
@@ -115,7 +178,7 @@ export declare const enum AuthHeaderFormat {
115
178
  }
116
179
 
117
180
  /** Auth scheme used by a provider. */
118
- export declare const enum AuthType {
181
+ export declare enum AuthType {
119
182
  /** Standard `Authorization: Bearer <key>` header. */
120
183
  Bearer = "bearer",
121
184
  /** `x-api-key: <key>` header (also handles `"header"` and `"x-api-key"` aliases). */
@@ -129,69 +192,69 @@ export declare const enum AuthType {
129
192
  /** Query parameters for listing batches. */
130
193
  export interface BatchListQuery {
131
194
  /** Maximum number of results to return. Defaults to 20. */
132
- limit?: number;
195
+ readonly limit?: number;
133
196
  /** Pagination cursor: return results after this batch ID. */
134
- after?: string;
197
+ readonly after?: string;
135
198
  }
136
199
 
137
200
  /** Response from listing batches. */
138
201
  export interface BatchListResponse {
139
202
  /** Object type (always `"list"`). */
140
- object?: string;
203
+ readonly object?: string;
141
204
  /** List of batch objects. */
142
- data?: Array<BatchObject>;
205
+ readonly data?: Array<BatchObject>;
143
206
  /** Whether more results are available. */
144
- hasMore?: boolean;
207
+ readonly hasMore?: boolean;
145
208
  /** First batch ID in the result set (for pagination). */
146
- firstId?: string;
209
+ readonly firstId?: string;
147
210
  /** Last batch ID in the result set (for pagination). */
148
- lastId?: string;
211
+ readonly lastId?: string;
149
212
  }
150
213
 
151
214
  /** A batch job object. */
152
215
  export interface BatchObject {
153
216
  /** Unique batch ID. */
154
- id?: string;
217
+ readonly id?: string;
155
218
  /** Object type (always `"batch"`). */
156
- object?: string;
219
+ readonly object?: string;
157
220
  /** API endpoint (e.g., `"/v1/chat/completions"`). */
158
- endpoint?: string;
221
+ readonly endpoint?: string;
159
222
  /** ID of the input file. */
160
- inputFileId?: string;
223
+ readonly inputFileId?: string;
161
224
  /** Completion window (e.g., `"24h"`). */
162
- completionWindow?: string;
225
+ readonly completionWindow?: string;
163
226
  /** Current job status. */
164
- status?: JsBatchStatus;
227
+ readonly status?: BatchStatus;
165
228
  /** ID of the output file (present when completed). */
166
- outputFileId?: string;
229
+ readonly outputFileId?: string;
167
230
  /** ID of the error file (present if some requests failed). */
168
- errorFileId?: string;
231
+ readonly errorFileId?: string;
169
232
  /** Unix timestamp of batch creation. */
170
- createdAt?: number;
233
+ readonly createdAt?: number;
171
234
  /** Unix timestamp of completion (if completed). */
172
- completedAt?: number;
235
+ readonly completedAt?: number;
173
236
  /** Unix timestamp of failure (if failed). */
174
- failedAt?: number;
237
+ readonly failedAt?: number;
175
238
  /** Unix timestamp of expiration (if expired). */
176
- expiredAt?: number;
239
+ readonly expiredAt?: number;
177
240
  /** Request processing counts. */
178
- requestCounts?: JsBatchRequestCounts;
241
+ readonly requestCounts?: BatchRequestCounts;
179
242
  /** Metadata attached to the batch. */
180
- metadata?: any;
243
+ readonly metadata?: JsonValue;
181
244
  }
182
245
 
183
246
  /** Request processing counts for a batch. */
184
247
  export interface BatchRequestCounts {
185
248
  /** Total requests in the batch. */
186
- total?: number;
249
+ readonly total?: number;
187
250
  /** Completed requests. */
188
- completed?: number;
251
+ readonly completed?: number;
189
252
  /** Failed requests. */
190
- failed?: number;
253
+ readonly failed?: number;
191
254
  }
192
255
 
193
256
  /** Status of a batch job. */
194
- export declare const enum BatchStatus {
257
+ export declare enum BatchStatus {
195
258
  /** Validating the input file. */
196
259
  Validating = "validating",
197
260
  /** Job failed. */
@@ -213,444 +276,370 @@ export declare const enum BatchStatus {
213
276
  /** Configuration for budget enforcement. */
214
277
  export interface BudgetConfig {
215
278
  /** Maximum total spend across all models, in USD. `None` means unlimited. */
216
- globalLimit?: number;
279
+ readonly globalLimit?: number;
217
280
  /**
218
281
  * Per-model spending limits in USD. Models not listed here are only
219
282
  * constrained by `global_limit`.
220
283
  */
221
- modelLimits?: Record<string, number>;
284
+ readonly modelLimits?: Record<string, number>;
222
285
  /** Whether to reject requests or merely warn when a limit is exceeded. */
223
- enforcement?: JsEnforcement;
286
+ readonly enforcement?: Enforcement;
224
287
  }
225
288
 
226
- export declare function budgetConfigDefault(): BudgetConfig;
227
-
228
289
  /** Storage backend for the response cache. */
229
- export interface CacheBackend {
230
- type: string;
231
- scheme?: string;
232
- config?: Record<string, string>;
233
- }
290
+ export type CacheBackend =
291
+ | { type: "memory" }
292
+ | { type: "open_dal"; scheme: string; config: Record<string, string> };
234
293
 
235
294
  /** Configuration for the response cache. */
236
295
  export interface CacheConfig {
237
296
  /** Maximum number of cached entries. */
238
- maxEntries?: number;
297
+ readonly maxEntries?: number;
239
298
  /** Time-to-live for each cached entry. */
240
- ttl?: number;
299
+ readonly ttl?: number;
241
300
  /** Storage backend to use. */
242
- backend?: JsCacheBackend;
301
+ readonly backend?: CacheBackend;
243
302
  }
244
303
 
245
- export declare function cacheConfigDefault(): CacheConfig;
246
-
247
304
  /** A streamed chunk of a chat completion response. */
248
305
  export interface ChatCompletionChunk {
249
306
  /** Unique identifier for this stream. */
250
- id?: string;
307
+ readonly id?: string;
251
308
  /**
252
309
  * Always `"chat.completion.chunk"` from OpenAI-compatible APIs. Stored
253
310
  * as a plain `String` so non-standard provider values do not fail parsing.
254
311
  */
255
- object?: string;
312
+ readonly object?: string;
256
313
  /** Unix timestamp of chunk creation. */
257
- created?: number;
314
+ readonly created?: number;
258
315
  /** Model used to generate the chunk. */
259
- model?: string;
316
+ readonly model?: string;
260
317
  /** Streaming choices (delta updates). */
261
- choices?: Array<JsStreamChoice>;
318
+ readonly choices?: Array<StreamChoice>;
262
319
  /** Token usage (typically only in the final chunk). */
263
- usage?: Usage;
320
+ readonly usage?: Usage;
264
321
  /** Fingerprint of the system configuration (OpenAI-specific). */
265
- systemFingerprint?: string;
322
+ readonly systemFingerprint?: string;
266
323
  /** Service tier used (OpenAI-specific). */
267
- serviceTier?: string;
324
+ readonly serviceTier?: string;
268
325
  }
269
326
 
270
327
  /** Chat completion request (compatible with OpenAI and similar APIs). */
271
328
  export interface ChatCompletionRequest {
272
329
  /** Model ID (e.g., `"gpt-4o-mini"`, `"claude-3-5-sonnet"`). */
273
- model?: string;
330
+ readonly model?: string;
274
331
  /** Conversation history from oldest to newest. */
275
- messages?: Array<JsMessage>;
332
+ readonly messages?: Array<Message>;
276
333
  /** Sampling temperature in `[0.0, 2.0]`. Higher increases randomness. Defaults to 1.0. */
277
- temperature?: number;
334
+ readonly temperature?: number;
278
335
  /** Nucleus sampling parameter in `[0.0, 1.0]`. Lower is more focused. */
279
- topP?: number;
336
+ readonly topP?: number;
280
337
  /** Number of chat completions to generate. Defaults to 1. */
281
- n?: number;
338
+ readonly n?: number;
282
339
  /**
283
340
  * Whether to stream the response.
284
341
  *
285
342
  * Managed by the client layer — do not set directly.
286
343
  */
287
- stream?: boolean;
344
+ readonly stream?: boolean;
288
345
  /** Stop sequence(s) that halt token generation. */
289
- stop?: JsStopSequence;
346
+ readonly stop?: StopSequence;
290
347
  /** Max output tokens. Different from max_completion_tokens in some providers. */
291
- maxTokens?: number;
348
+ readonly maxTokens?: number;
292
349
  /** Presence penalty in `[-2.0, 2.0]`. Positive discourages repeated topics. */
293
- presencePenalty?: number;
350
+ readonly presencePenalty?: number;
294
351
  /** Frequency penalty in `[-2.0, 2.0]`. Positive discourages repeated tokens. */
295
- frequencyPenalty?: number;
352
+ readonly frequencyPenalty?: number;
296
353
  /**
297
354
  * Token bias map. Uses `BTreeMap` (sorted keys) for deterministic
298
355
  * serialization order — important when hashing or signing requests.
299
356
  */
300
- logitBias?: Record<string, number>;
357
+ readonly logitBias?: Record<string, number>;
301
358
  /** User identifier for request tracking and abuse detection. */
302
- user?: string;
359
+ readonly user?: string;
303
360
  /** Tools the model can invoke. */
304
- tools?: Array<ChatCompletionTool>;
361
+ readonly tools?: Array<ChatCompletionTool>;
305
362
  /** Tool usage mode (auto, required, none, or specific tool). */
306
- toolChoice?: JsToolChoice;
363
+ readonly toolChoice?: ToolChoice;
307
364
  /** Whether the model can call multiple tools in parallel. Defaults to true. */
308
- parallelToolCalls?: boolean;
365
+ readonly parallelToolCalls?: boolean;
309
366
  /** Output format constraint (text, JSON, JSON schema). */
310
- responseFormat?: JsResponseFormat;
367
+ readonly responseFormat?: ResponseFormat;
311
368
  /** Streaming options (e.g., include_usage). */
312
- streamOptions?: JsStreamOptions;
369
+ readonly streamOptions?: StreamOptions;
313
370
  /** Random seed for reproducible outputs. Provider support varies. */
314
- seed?: number;
371
+ readonly seed?: number;
315
372
  /** Reasoning effort level (low, medium, high) for extended-thinking models. */
316
- reasoningEffort?: JsReasoningEffort;
373
+ readonly reasoningEffort?: ReasoningEffort;
317
374
  /**
318
375
  * Provider-specific extra parameters merged into the request body.
319
376
  * Use for guardrails, safety settings, grounding config, etc.
320
377
  */
321
- extraBody?: any;
378
+ readonly extraBody?: JsonValue;
322
379
  }
323
380
 
324
381
  /** Chat completion response from the API. */
325
382
  export interface ChatCompletionResponse {
326
383
  /** Unique identifier for this response. */
327
- id?: string;
384
+ readonly id?: string;
328
385
  /**
329
386
  * Always `"chat.completion"` from OpenAI-compatible APIs. Stored as a
330
387
  * plain `String` so non-standard provider values do not break deserialization.
331
388
  */
332
- object?: string;
389
+ readonly object?: string;
333
390
  /** Unix timestamp of response creation. */
334
- created?: number;
391
+ readonly created?: number;
335
392
  /** Model used to generate the response. */
336
- model?: string;
393
+ readonly model?: string;
337
394
  /** List of completion choices. */
338
- choices?: Array<JsChoice>;
395
+ readonly choices?: Array<Choice>;
339
396
  /** Token usage statistics. */
340
- usage?: Usage;
397
+ readonly usage?: Usage;
341
398
  /** Fingerprint of the system configuration (OpenAI-specific). */
342
- systemFingerprint?: string;
399
+ readonly systemFingerprint?: string;
343
400
  /** Service tier used (OpenAI-specific). */
344
- serviceTier?: string;
401
+ readonly serviceTier?: string;
345
402
  }
346
403
 
347
404
  /** A tool the model can invoke (currently, all tools are functions). */
348
405
  export interface ChatCompletionTool {
349
406
  /** Tool type (always "function" in OpenAI spec). */
350
- type: JsToolType;
407
+ readonly toolType: ToolType;
351
408
  /** Function definition with name, description, and JSON schema parameters. */
352
- function: JsFunctionDefinition;
409
+ readonly function: FunctionDefinition;
353
410
  }
354
411
 
355
- export declare function chatStream(
356
- engine: DefaultClient,
357
- req: ChatCompletionRequest,
358
- ): Promise<ChatStreamIterator>;
359
-
360
412
  /** A single completion choice. */
361
413
  export interface Choice {
362
414
  /** Index of this choice in the choices array. */
363
- index?: number;
415
+ readonly index?: number;
364
416
  /** The assistant's message response. */
365
- message?: AssistantMessage;
417
+ readonly message?: AssistantMessage;
366
418
  /** Why the model stopped generating (stop, length, tool_calls, content_filter, etc.). */
367
- finishReason?: JsFinishReason;
419
+ readonly finishReason?: FinishReason;
368
420
  }
369
421
 
370
- /**
371
- * Calculate the estimated cost of a completion given a model name and token
372
- * counts.
373
- *
374
- * Returns `None` if the model is not present in the embedded pricing registry.
375
- * Returns `Some(cost_usd)` otherwise, where the value is in US dollars.
376
- *
377
- * When an exact model name match is not found, progressively shorter prefixes
378
- * are tried by stripping from the last `-` or `.` separator. For example,
379
- * `gpt-4-0613` will match `gpt-4` if no `gpt-4-0613` entry exists.
380
- *
381
- * # Example
382
- */
383
- export declare function completionCost(
384
- model: string,
385
- promptTokens: number,
386
- completionTokens: number,
387
- ): number | null;
388
-
389
- /**
390
- * Calculate the estimated cost of a completion, accounting for cached
391
- * (cache-hit) prompt tokens billed at the provider's discounted rate.
392
- *
393
- * `cached_tokens` is the count of prompt tokens served from the provider's
394
- * prompt cache. It must be `<= prompt_tokens` (cached tokens are a subset of
395
- * the prompt). The non-cached portion is billed at `input_cost_per_token`
396
- * and the cached portion at `cache_read_input_token_cost` when the model
397
- * has cache pricing; otherwise the entire prompt is billed at the regular
398
- * input rate.
399
- *
400
- * Returns `None` if the model is not present in the embedded pricing
401
- * registry, mirroring `completion_cost`.
402
- */
403
- export declare function completionCostWithCache(
404
- model: string,
405
- promptTokens: number,
406
- cachedTokens: number,
407
- completionTokens: number,
408
- ): number | null;
409
-
410
- /**
411
- * Return the set of complex provider names.
412
- *
413
- * Complex providers require custom auth/routing logic beyond simple bearer
414
- * tokens (e.g. AWS Bedrock SigV4, Vertex AI OAuth2).
415
- *
416
- * The returned reference points into the static registry — no allocation.
417
- */
418
- export declare function complexProviderNames(): Array<string>;
419
-
420
422
  /** A single content part in a user message — text, image, document, or audio. */
421
- export interface ContentPart {
422
- type: string;
423
- text?: string;
424
- imageUrl?: ImageUrl;
425
- document?: DocumentContent;
426
- inputAudio?: AudioContent;
427
- }
428
-
429
- /**
430
- * Count tokens for a full `ChatCompletionRequest`.
431
- *
432
- * Sums tokens across all message text contents plus a per-message overhead
433
- * of ~4 tokens (for role, separators, and formatting metadata). Tool
434
- * definitions and multimodal content parts (images, audio, documents) are
435
- * not counted — only textual content contributes to the token total.
436
- *
437
- * # Errors
438
- *
439
- * Returns `LiterLlmError.BadRequest` if the tokenizer cannot be loaded or
440
- * if tokenization fails for any message.
441
- */
442
- export declare function countRequestTokens(
443
- model: string,
444
- req?: ChatCompletionRequest | undefined | null,
445
- ): number;
446
-
447
- /**
448
- * Count tokens in a text string using the tokenizer for the given model.
449
- *
450
- * The tokenizer is resolved from the model name prefix (e.g. `"gpt-4o"` maps
451
- * to the `Xenova/gpt-4o` HuggingFace tokenizer). Tokenizers are cached after
452
- * first load.
453
- *
454
- * # Errors
455
- *
456
- * Returns `LiterLlmError.BadRequest` if the tokenizer cannot be loaded
457
- * (e.g. network failure on first use) or if tokenization itself fails.
458
- */
459
- export declare function countTokens(model: string, text: string): number;
423
+ export type ContentPart =
424
+ | { type: "text"; text: string }
425
+ | { type: "image_url"; imageUrl: ImageUrl }
426
+ | { type: "document"; document: DocumentContent }
427
+ | { type: "input_audio"; inputAudio: AudioContent };
460
428
 
461
429
  /** Request to create a batch job. */
462
430
  export interface CreateBatchRequest {
463
431
  /** ID of the uploaded input file (JSONL format). */
464
- inputFileId?: string;
432
+ readonly inputFileId?: string;
465
433
  /** API endpoint (e.g., `"/v1/chat/completions"`). */
466
- endpoint?: string;
434
+ readonly endpoint?: string;
467
435
  /** Completion window (e.g., `"24h"`). */
468
- completionWindow?: string;
436
+ readonly completionWindow?: string;
469
437
  /** Optional metadata to attach to the batch. */
470
- metadata?: any;
438
+ readonly metadata?: JsonValue;
471
439
  }
472
440
 
473
- /**
474
- * Create a new LLM client with simple scalar configuration.
475
- *
476
- * This is the primary binding entry-point. All parameters except `api_key`
477
- * are optional — omitting them uses the same defaults as
478
- * `ClientConfigBuilder`.
479
- *
480
- * # Errors
481
- *
482
- * Returns `LiterLlmError` if the underlying HTTP client cannot be
483
- * constructed, or if the resolved provider configuration is invalid.
484
- */
485
- export declare function createClient(
486
- apiKey: string,
487
- baseUrl?: string | undefined | null,
488
- timeoutSecs?: number | undefined | null,
489
- maxRetries?: number | undefined | null,
490
- modelHint?: string | undefined | null,
491
- ): DefaultClient;
492
-
493
- /**
494
- * Create a new LLM client from a JSON string.
495
- *
496
- * The JSON object accepts the same fields as `liter-llm.toml` (snake_case).
497
- *
498
- * # Errors
499
- *
500
- * Returns `LiterLlmError.BadRequest` if `json` is not valid JSON or
501
- * contains unknown fields.
502
- */
503
- export declare function createClientFromJson(json: string): DefaultClient;
504
-
505
441
  /** Request to upload a file. */
506
442
  export interface CreateFileRequest {
507
443
  /** Base64-encoded file data. */
508
- file?: string;
444
+ readonly file?: string;
509
445
  /** Purpose for the file. */
510
- purpose?: JsFilePurpose;
446
+ readonly purpose?: FilePurpose;
511
447
  /** Optional filename to associate with the upload. */
512
- filename?: string;
448
+ readonly filename?: string;
513
449
  }
514
450
 
515
451
  /** Request to create images from a text prompt. */
516
452
  export interface CreateImageRequest {
517
453
  /** Text description of the image to generate. */
518
- prompt?: string;
454
+ readonly prompt?: string;
519
455
  /** Model ID (e.g., `"dall-e-3"`). Optional; API may use default if unset. */
520
- model?: string;
456
+ readonly model?: string;
521
457
  /** Number of images to generate. Defaults to 1. */
522
- n?: number;
458
+ readonly n?: number;
523
459
  /** Image size (e.g., `"1024x1024"`, `"1792x1024"`). */
524
- size?: string;
460
+ readonly size?: string;
525
461
  /** Image quality: `"standard"` or `"hd"`. */
526
- quality?: string;
462
+ readonly quality?: string;
527
463
  /** Style: `"natural"` or `"vivid"` (DALL-E 3 only). */
528
- style?: string;
464
+ readonly style?: string;
529
465
  /** Response format: `"url"` or `"b64_json"`. */
530
- responseFormat?: string;
466
+ readonly responseFormat?: string;
531
467
  /** User identifier for request tracking. */
532
- user?: string;
468
+ readonly user?: string;
533
469
  }
534
470
 
535
471
  /** Request to create a structured response. */
536
472
  export interface CreateResponseRequest {
537
473
  /** Model ID. */
538
- model?: string;
474
+ readonly model?: string;
539
475
  /** Input data to process (e.g., a document to extract from). */
540
- input?: any;
476
+ readonly input?: JsonValue;
541
477
  /** Instructions for processing the input. */
542
- instructions?: string;
478
+ readonly instructions?: string;
543
479
  /** Available tools the model can use. */
544
- tools?: Array<JsResponseTool>;
480
+ readonly tools?: Array<ResponseTool>;
545
481
  /** Sampling temperature in `[0.0, 2.0]`. Defaults to 1.0. */
546
- temperature?: number;
482
+ readonly temperature?: number;
547
483
  /** Maximum output tokens. */
548
- maxOutputTokens?: number;
484
+ readonly maxOutputTokens?: number;
549
485
  /** Optional metadata. */
550
- metadata?: any;
486
+ readonly metadata?: JsonValue;
551
487
  }
552
488
 
553
489
  /** Request to generate speech audio from text. */
554
490
  export interface CreateSpeechRequest {
555
491
  /** Model ID (e.g., `"tts-1"`, `"tts-1-hd"`). */
556
- model?: string;
492
+ readonly model?: string;
557
493
  /** Text to synthesize into speech. */
558
- input?: string;
494
+ readonly input?: string;
559
495
  /** Voice name (e.g., `"alloy"`, `"echo"`, `"fable"`, `"onyx"`, `"nova"`, `"shimmer"`). */
560
- voice?: string;
496
+ readonly voice?: string;
561
497
  /** Audio format (e.g., `"mp3"`, `"opus"`, `"aac"`, `"flac"`, `"wav"`, `"pcm"`). */
562
- responseFormat?: string;
498
+ readonly responseFormat?: string;
563
499
  /** Playback speed in `[0.25, 4.0]`. Defaults to 1.0. */
564
- speed?: number;
500
+ readonly speed?: number;
565
501
  }
566
502
 
567
503
  /** Request to transcribe audio into text. */
568
504
  export interface CreateTranscriptionRequest {
569
505
  /** Model ID (e.g., `"whisper-1"`). */
570
- model?: string;
506
+ readonly model?: string;
571
507
  /** Base64-encoded audio file data. */
572
- file?: string;
508
+ readonly file?: string;
573
509
  /** Language ISO-639-1 code (e.g., `"en"`, `"fr"`, `"de"`). Optional; model auto-detects. */
574
- language?: string;
510
+ readonly language?: string;
575
511
  /** Optional text to guide the model (improves accuracy for domain-specific terms). */
576
- prompt?: string;
512
+ readonly prompt?: string;
577
513
  /** Output format (e.g., `"json"`, `"text"`, `"vtt"`, `"srt"`, `"verbose_json"`). */
578
- responseFormat?: string;
514
+ readonly responseFormat?: string;
579
515
  /** Sampling temperature in `[0.0, 1.0]`. Higher increases variability. Defaults to 0. */
580
- temperature?: number;
516
+ readonly temperature?: number;
581
517
  }
582
518
 
583
519
  /** Configuration for registering a custom LLM provider at runtime. */
584
520
  export interface CustomProviderConfig {
585
521
  /** Unique name for this provider (e.g., "my-provider"). */
586
- name: string;
522
+ readonly name: string;
587
523
  /** Base URL for the provider's API (e.g., "https://api.my-provider.com/v1"). */
588
- baseUrl: string;
524
+ readonly baseUrl: string;
589
525
  /** Authentication header format. */
590
- authHeader: JsAuthHeaderFormat;
526
+ readonly authHeader: AuthHeaderFormat;
591
527
  /** Model name prefixes that route to this provider (e.g., ["my-"]). */
592
- modelPrefixes: Array<string>;
528
+ readonly modelPrefixes: Array<string>;
529
+ }
530
+
531
+ /**
532
+ * Default client implementation backed by `reqwest`.
533
+ *
534
+ * Sends requests to 140+ LLM providers with automatic provider detection
535
+ * and per-request routing. The provider is resolved at construction time
536
+ * from `model_hint` (or defaults to OpenAI), but individual requests can
537
+ * override the provider via model name prefix (e.g. `"anthropic/claude-3-5-sonnet"`
538
+ * routes to Anthropic regardless of construction-time setting).
539
+ *
540
+ * When the model prefix does not match any known provider, the construction-time
541
+ * provider is used as the fallback. This enables seamless migration between
542
+ * providers by changing only the model name.
543
+ *
544
+ * The provider is stored behind an [`Arc`] so it can be shared cheaply into
545
+ * async closures and streaming tasks. Pre-computed auth headers and extra
546
+ * headers are cached at construction to avoid redundant encoding on every request.
547
+ */
548
+ export declare class DefaultClient {
549
+ chat(req: ChatCompletionRequest): Promise<ChatCompletionResponse>;
550
+ chatStream(
551
+ req: ChatCompletionRequest,
552
+ ): Promise<AsyncGenerator<ChatCompletionChunk, void, undefined>>;
553
+ embed(req: EmbeddingRequest): Promise<EmbeddingResponse>;
554
+ listModels(): Promise<ModelsListResponse>;
555
+ imageGenerate(req: CreateImageRequest): Promise<ImagesResponse>;
556
+ speech(req: CreateSpeechRequest): Promise<Uint8Array>;
557
+ transcribe(req: CreateTranscriptionRequest): Promise<TranscriptionResponse>;
558
+ moderate(req: ModerationRequest): Promise<ModerationResponse>;
559
+ rerank(req: RerankRequest): Promise<RerankResponse>;
560
+ search(req: SearchRequest): Promise<SearchResponse>;
561
+ ocr(req: OcrRequest): Promise<OcrResponse>;
562
+ createFile(req: CreateFileRequest): Promise<FileObject>;
563
+ retrieveFile(fileId: string): Promise<FileObject>;
564
+ deleteFile(fileId: string): Promise<DeleteResponse>;
565
+ listFiles(query?: FileListQuery | undefined | null): Promise<FileListResponse>;
566
+ fileContent(fileId: string): Promise<Uint8Array>;
567
+ createBatch(req: CreateBatchRequest): Promise<BatchObject>;
568
+ retrieveBatch(batchId: string): Promise<BatchObject>;
569
+ listBatches(query?: BatchListQuery | undefined | null): Promise<BatchListResponse>;
570
+ cancelBatch(batchId: string): Promise<BatchObject>;
571
+ createResponse(req: CreateResponseRequest): Promise<ResponseObject>;
572
+ retrieveResponse(responseId: string): Promise<ResponseObject>;
573
+ cancelResponse(responseId: string): Promise<ResponseObject>;
593
574
  }
594
575
 
595
576
  /** Response from a delete operation. */
596
577
  export interface DeleteResponse {
597
578
  /** ID of the deleted resource. */
598
- id?: string;
579
+ readonly id?: string;
599
580
  /** Object type. */
600
- object?: string;
581
+ readonly object?: string;
601
582
  /** Confirmation that the resource was deleted. */
602
- deleted?: boolean;
583
+ readonly deleted?: boolean;
603
584
  }
604
585
 
605
586
  /** Developer message (system-like message for Claude models). */
606
587
  export interface DeveloperMessage {
607
588
  /** Developer-specific instructions or context. */
608
- content?: string;
589
+ readonly content?: string;
609
590
  /** Optional name for the developer message source. */
610
- name?: string;
591
+ readonly name?: string;
611
592
  }
612
593
 
613
594
  /** PDF/document content part for vision-capable models. */
614
595
  export interface DocumentContent {
615
596
  /** Base64-encoded document data or URL. */
616
- data?: string;
597
+ readonly data?: string;
617
598
  /** MIME type (e.g., "application/pdf", "text/csv"). */
618
- mediaType?: string;
599
+ readonly mediaType?: string;
619
600
  }
620
601
 
621
602
  /** The format in which the embedding vectors are returned. */
622
- export declare const enum EmbeddingFormat {
603
+ export declare enum EmbeddingFormat {
623
604
  /** 32-bit floating-point numbers (default). */
624
605
  Float = "float",
625
606
  /** Base64-encoded string representation of the floats. */
626
607
  Base64 = "base64",
627
608
  }
628
609
 
610
+ /** Text or texts to embed. */
611
+ export declare enum EmbeddingInput {
612
+ /** Single text string. */
613
+ Single = "Single",
614
+ /** Multiple text strings (batch embedding). */
615
+ Multiple = "Multiple",
616
+ }
617
+
629
618
  /** A single embedding vector. */
630
619
  export interface EmbeddingObject {
631
620
  /**
632
621
  * Always `"embedding"` from OpenAI-compatible APIs. Stored as a plain
633
622
  * `String` so non-standard provider values do not break deserialization.
634
623
  */
635
- object: string;
624
+ readonly object: string;
636
625
  /** The embedding vector. */
637
- embedding: Array<number>;
626
+ readonly embedding: Array<number>;
638
627
  /** Index in the batch (corresponds to input order). */
639
- index: number;
628
+ readonly index: number;
640
629
  }
641
630
 
642
631
  /** Embedding request. */
643
632
  export interface EmbeddingRequest {
644
633
  /** Model ID (e.g., `"text-embedding-3-small"`). */
645
- model?: string;
634
+ readonly model?: string;
646
635
  /** Text or texts to embed. */
647
- input?: JsEmbeddingInput;
636
+ readonly input?: EmbeddingInput;
648
637
  /** Output format: float (native) or base64. */
649
- encodingFormat?: JsEmbeddingFormat;
638
+ readonly encodingFormat?: EmbeddingFormat;
650
639
  /** Requested embedding dimensions (if supported by the model). */
651
- dimensions?: number;
640
+ readonly dimensions?: number;
652
641
  /** User identifier for request tracking. */
653
- user?: string;
642
+ readonly user?: string;
654
643
  }
655
644
 
656
645
  /** Embedding response. */
@@ -659,86 +648,69 @@ export interface EmbeddingResponse {
659
648
  * Always `"list"` from OpenAI-compatible APIs. Stored as a plain
660
649
  * `String` so non-standard provider values do not break deserialization.
661
650
  */
662
- object: string;
651
+ readonly object: string;
663
652
  /** List of embeddings. */
664
- data: Array<JsEmbeddingObject>;
653
+ readonly data: Array<EmbeddingObject>;
665
654
  /** Model used to generate embeddings. */
666
- model: string;
655
+ readonly model: string;
667
656
  /** Token usage (input tokens only; embeddings have zero output tokens). */
668
- usage?: Usage;
657
+ readonly usage?: Usage;
669
658
  }
670
659
 
671
660
  /** How budget limits are enforced. */
672
- export declare const enum Enforcement {
661
+ export declare enum Enforcement {
673
662
  /**
674
663
  * Reject requests that would exceed the budget with
675
- * `LiterLlmError.BudgetExceeded`.
664
+ * [`LiterLlmError::BudgetExceeded`].
676
665
  */
677
666
  Hard = "Hard",
678
667
  /**
679
- * Allow requests through but emit a `tracing.warn!` when the budget is
668
+ * Allow requests through but emit a `tracing::warn!` when the budget is
680
669
  * exceeded.
681
670
  */
682
671
  Soft = "Soft",
683
672
  }
684
673
 
685
- /**
686
- * Install the `ring` crypto provider as the rustls process default, idempotently.
687
- *
688
- * rustls 0.23+ removed the implicit default provider. This function installs
689
- * `ring` once per process. Subsequent calls are no-ops. Calling it from a
690
- * downstream Rust app that has already installed `aws-lc-rs` is safe — the
691
- * `Err` from `install_default()` is silently ignored.
692
- *
693
- * Called automatically by every internal `reqwest.Client` constructor
694
- * (auth providers, default HTTP client). Bindings and downstream consumers
695
- * reach those constructors transitively, so no manual init is required.
696
- *
697
- * WASM builds are exempt — the WASM target uses the browser/Node.js fetch
698
- * API instead of rustls, so no crypto provider is needed.
699
- */
700
- export declare function ensureCryptoProvider(): void;
701
-
702
674
  /** Query parameters for listing files. */
703
675
  export interface FileListQuery {
704
676
  /** Filter by file purpose (e.g., `"batch"`, `"fine-tune"`). */
705
- purpose?: string;
677
+ readonly purpose?: string;
706
678
  /** Maximum number of results to return. Defaults to 20. */
707
- limit?: number;
679
+ readonly limit?: number;
708
680
  /** Pagination cursor: return results after this file ID. */
709
- after?: string;
681
+ readonly after?: string;
710
682
  }
711
683
 
712
684
  /** Response from listing files. */
713
685
  export interface FileListResponse {
714
686
  /** Object type (always `"list"`). */
715
- object?: string;
687
+ readonly object?: string;
716
688
  /** List of file objects. */
717
- data?: Array<FileObject>;
689
+ readonly data?: Array<FileObject>;
718
690
  /** Whether more results are available. */
719
- hasMore?: boolean;
691
+ readonly hasMore?: boolean;
720
692
  }
721
693
 
722
694
  /** An uploaded file object. */
723
695
  export interface FileObject {
724
696
  /** Unique file ID. */
725
- id?: string;
697
+ readonly id?: string;
726
698
  /** Object type (always `"file"`). */
727
- object?: string;
699
+ readonly object?: string;
728
700
  /** File size in bytes. */
729
- bytes?: number;
701
+ readonly bytes?: number;
730
702
  /** Unix timestamp of file creation. */
731
- createdAt?: number;
703
+ readonly createdAt?: number;
732
704
  /** Filename. */
733
- filename?: string;
705
+ readonly filename?: string;
734
706
  /** File purpose. */
735
- purpose?: string;
707
+ readonly purpose?: string;
736
708
  /** Processing status (e.g., `"uploaded"`, `"processed"`). */
737
- status?: string;
709
+ readonly status?: string;
738
710
  }
739
711
 
740
712
  /** Purpose of an uploaded file. */
741
- export declare const enum FilePurpose {
713
+ export declare enum FilePurpose {
742
714
  /** File for use with Assistants API. */
743
715
  Assistants = "assistants",
744
716
  /** File for batch processing. */
@@ -750,7 +722,7 @@ export declare const enum FilePurpose {
750
722
  }
751
723
 
752
724
  /** Why a choice stopped generating tokens. */
753
- export declare const enum FinishReason {
725
+ export declare enum FinishReason {
754
726
  Stop = "stop",
755
727
  Length = "length",
756
728
  ToolCalls = "tool_calls",
@@ -772,41 +744,41 @@ export declare const enum FinishReason {
772
744
  /** Function call details. */
773
745
  export interface FunctionCall {
774
746
  /** Function name. */
775
- name: string;
747
+ readonly name: string;
776
748
  /** Arguments as a JSON string (parse with serde_json::from_str). */
777
- arguments: string;
749
+ readonly arguments: string;
778
750
  }
779
751
 
780
752
  /** Function definition exposed to the model. */
781
753
  export interface FunctionDefinition {
782
754
  /** Name of the function. Required and must be alphanumeric + underscores. */
783
- name: string;
755
+ readonly name: string;
784
756
  /** Human-readable description explaining what the function does. */
785
- description?: string;
757
+ readonly description?: string;
786
758
  /** JSON Schema defining the function's parameters. */
787
- parameters?: any;
759
+ readonly parameters?: JsonValue;
788
760
  /** If true, enforce strict JSON schema validation for arguments. */
789
- strict?: boolean;
761
+ readonly strict?: boolean;
790
762
  }
791
763
 
792
764
  /** Deprecated legacy function-role message body. */
793
765
  export interface FunctionMessage {
794
- content?: string;
795
- name?: string;
766
+ readonly content?: string;
767
+ readonly name?: string;
796
768
  }
797
769
 
798
770
  /** A single generated image, returned as either a URL or base64 data. */
799
771
  export interface Image {
800
772
  /** Image URL (if response_format was "url"). */
801
- url?: string;
773
+ readonly url?: string;
802
774
  /** Base64-encoded image data (if response_format was "b64_json"). */
803
- b64Json?: string;
775
+ readonly b64Json?: string;
804
776
  /** The final prompt used to generate the image (DALL-E 3). */
805
- revisedPrompt?: string;
777
+ readonly revisedPrompt?: string;
806
778
  }
807
779
 
808
780
  /** Image detail level controlling token cost and processing. */
809
- export declare const enum ImageDetail {
781
+ export declare enum ImageDetail {
810
782
  /** Low detail: scales image to 512x512, uses fewer tokens. */
811
783
  Low = "low",
812
784
  /** High detail: processes up to 2x2 grid of tiles, higher token cost. */
@@ -818,55 +790,53 @@ export declare const enum ImageDetail {
818
790
  /** Response containing generated images. */
819
791
  export interface ImagesResponse {
820
792
  /** Unix timestamp of image creation. */
821
- created?: number;
793
+ readonly created?: number;
822
794
  /** List of generated images. */
823
- data?: Array<JsImage>;
795
+ readonly data?: Array<Image>;
824
796
  }
825
797
 
826
798
  /** An image URL reference with optional detail level for processing. */
827
799
  export interface ImageUrl {
828
800
  /** URL of the image (data URI or HTTP/HTTPS URL). */
829
- url?: string;
801
+ readonly url?: string;
830
802
  /** Detail level: low (512x512), high (2x2 tiles), or auto (model-selected). */
831
- detail?: JsImageDetail;
803
+ readonly detail?: ImageDetail;
832
804
  }
833
805
 
834
806
  /** JSON Schema specification for constrained output. */
835
807
  export interface JsonSchemaFormat {
836
808
  /** Name of the schema (must be unique in the request). */
837
- name?: string;
809
+ readonly name?: string;
838
810
  /** Description of what the schema represents. */
839
- description?: string;
811
+ readonly description?: string;
840
812
  /** JSON Schema object defining the output structure. */
841
- schema?: any;
813
+ readonly schema?: JsonValue;
842
814
  /** If true, enforce strict schema validation. */
843
- strict?: boolean;
815
+ readonly strict?: boolean;
844
816
  }
845
817
 
846
818
  /** A chat message in a conversation. */
847
- export interface Message {
848
- role: string;
849
- system?: SystemMessage;
850
- user?: UserMessage;
851
- assistant?: AssistantMessage;
852
- tool?: ToolMessage;
853
- developer?: DeveloperMessage;
854
- function?: FunctionMessage;
855
- }
819
+ export type Message =
820
+ | { role: "system"; 0: SystemMessage }
821
+ | { role: "user"; 0: UserMessage }
822
+ | { role: "assistant"; 0: AssistantMessage }
823
+ | { role: "tool"; 0: ToolMessage }
824
+ | { role: "developer"; 0: DeveloperMessage }
825
+ | { role: "function"; 0: FunctionMessage };
856
826
 
857
827
  /** A model available from the API. */
858
828
  export interface ModelObject {
859
829
  /** Model ID (e.g., `"gpt-4o"`, `"claude-3-5-sonnet"`). */
860
- id?: string;
830
+ readonly id?: string;
861
831
  /**
862
832
  * Always `"model"` from OpenAI-compatible APIs. Stored as a plain
863
833
  * `String` so non-standard provider values do not break deserialization.
864
834
  */
865
- object?: string;
835
+ readonly object?: string;
866
836
  /** Unix timestamp of model creation (or release date). */
867
- created?: number;
837
+ readonly created?: number;
868
838
  /** Organization or entity that owns the model. */
869
- ownedBy?: string;
839
+ readonly ownedBy?: string;
870
840
  }
871
841
 
872
842
  /** Response listing available models. */
@@ -875,178 +845,183 @@ export interface ModelsListResponse {
875
845
  * Always `"list"` from OpenAI-compatible APIs. Stored as a plain
876
846
  * `String` so non-standard provider values do not break deserialization.
877
847
  */
878
- object?: string;
848
+ readonly object?: string;
879
849
  /** List of available models. */
880
- data?: Array<JsModelObject>;
850
+ readonly data?: Array<ModelObject>;
881
851
  }
882
852
 
883
853
  /** Boolean flags for each moderation category. */
884
854
  export interface ModerationCategories {
885
855
  /** Sexual content. */
886
- sexual?: boolean;
856
+ readonly sexual?: boolean;
887
857
  /** Hate speech. */
888
- hate?: boolean;
858
+ readonly hate?: boolean;
889
859
  /** Harassment. */
890
- harassment?: boolean;
860
+ readonly harassment?: boolean;
891
861
  /** Self-harm content. */
892
- "self-harm"?: boolean;
862
+ readonly selfHarm?: boolean;
893
863
  /** Sexual content involving minors. */
894
- "sexual/minors"?: boolean;
864
+ readonly sexualMinors?: boolean;
895
865
  /** Hate speech that threatens violence. */
896
- "hate/threatening"?: boolean;
866
+ readonly hateThreatening?: boolean;
897
867
  /** Graphic violence. */
898
- "violence/graphic"?: boolean;
868
+ readonly violenceGraphic?: boolean;
899
869
  /** Intent to self-harm. */
900
- "self-harm/intent"?: boolean;
870
+ readonly selfHarmIntent?: boolean;
901
871
  /** Instructions for self-harm. */
902
- "self-harm/instructions"?: boolean;
872
+ readonly selfHarmInstructions?: boolean;
903
873
  /** Harassment that threatens violence. */
904
- "harassment/threatening"?: boolean;
874
+ readonly harassmentThreatening?: boolean;
905
875
  /** Non-graphic violence. */
906
- violence?: boolean;
876
+ readonly violence?: boolean;
907
877
  }
908
878
 
909
879
  /** Confidence scores for each moderation category. */
910
880
  export interface ModerationCategoryScores {
911
881
  /** Sexual content score. */
912
- sexual?: number;
882
+ readonly sexual?: number;
913
883
  /** Hate speech score. */
914
- hate?: number;
884
+ readonly hate?: number;
915
885
  /** Harassment score. */
916
- harassment?: number;
886
+ readonly harassment?: number;
917
887
  /** Self-harm content score. */
918
- "self-harm"?: number;
888
+ readonly selfHarm?: number;
919
889
  /** Sexual content involving minors score. */
920
- "sexual/minors"?: number;
890
+ readonly sexualMinors?: number;
921
891
  /** Hate speech that threatens violence score. */
922
- "hate/threatening"?: number;
892
+ readonly hateThreatening?: number;
923
893
  /** Graphic violence score. */
924
- "violence/graphic"?: number;
894
+ readonly violenceGraphic?: number;
925
895
  /** Intent to self-harm score. */
926
- "self-harm/intent"?: number;
896
+ readonly selfHarmIntent?: number;
927
897
  /** Instructions for self-harm score. */
928
- "self-harm/instructions"?: number;
898
+ readonly selfHarmInstructions?: number;
929
899
  /** Harassment that threatens violence score. */
930
- "harassment/threatening"?: number;
900
+ readonly harassmentThreatening?: number;
931
901
  /** Non-graphic violence score. */
932
- violence?: number;
902
+ readonly violence?: number;
903
+ }
904
+
905
+ /** Input to the moderation endpoint — a single string or multiple strings. */
906
+ export declare enum ModerationInput {
907
+ /** Single text string. */
908
+ Single = "Single",
909
+ /** Multiple text strings (batch moderation). */
910
+ Multiple = "Multiple",
933
911
  }
934
912
 
935
913
  /** Request to classify content for policy violations. */
936
914
  export interface ModerationRequest {
937
915
  /** Text or texts to check. */
938
- input?: JsModerationInput;
916
+ readonly input?: ModerationInput;
939
917
  /** Model ID (e.g., `"text-moderation-latest"`). Optional; API uses default if unset. */
940
- model?: string;
918
+ readonly model?: string;
941
919
  }
942
920
 
943
921
  /** Response from the moderation endpoint. */
944
922
  export interface ModerationResponse {
945
923
  /** Unique identifier for this moderation request. */
946
- id: string;
924
+ readonly id: string;
947
925
  /** Model used for classification. */
948
- model: string;
926
+ readonly model: string;
949
927
  /** Results for each input string. */
950
- results: Array<JsModerationResult>;
928
+ readonly results: Array<ModerationResult>;
951
929
  }
952
930
 
953
931
  /** A single moderation classification result. */
954
932
  export interface ModerationResult {
955
933
  /** True if any category was flagged. */
956
- flagged: boolean;
934
+ readonly flagged: boolean;
957
935
  /** Boolean flags for each moderation category. */
958
- categories: JsModerationCategories;
936
+ readonly categories: ModerationCategories;
959
937
  /** Confidence scores for each category. */
960
- categoryScores: JsModerationCategoryScores;
938
+ readonly categoryScores: ModerationCategoryScores;
961
939
  }
962
940
 
963
941
  /** Document input for OCR — either a URL or inline base64 data. */
964
- export interface OcrDocument {
965
- type: string;
966
- url?: string;
967
- data?: string;
968
- mediaType?: string;
969
- }
942
+ export type OcrDocument =
943
+ | { type: "document_url"; url: string }
944
+ | { type: "base64"; data: string; mediaType: string };
970
945
 
971
946
  /** An image extracted from an OCR page. */
972
947
  export interface OcrImage {
973
948
  /** Unique image identifier within the document. */
974
- id: string;
949
+ readonly id: string;
975
950
  /** Base64-encoded image data (if `include_image_base64` was true). */
976
- imageBase64?: string;
951
+ readonly imageBase64?: string;
977
952
  }
978
953
 
979
954
  /** A single page of OCR output. */
980
955
  export interface OcrPage {
981
956
  /** Page index (0-based). */
982
- index: number;
957
+ readonly index: number;
983
958
  /** Extracted page content as Markdown. */
984
- markdown: string;
959
+ readonly markdown: string;
985
960
  /** Embedded images extracted from the page (if `include_image_base64` was true). */
986
- images?: Array<JsOcrImage>;
961
+ readonly images?: Array<OcrImage>;
987
962
  /** Page dimensions in pixels, if available. */
988
- dimensions?: JsPageDimensions;
963
+ readonly dimensions?: PageDimensions;
989
964
  }
990
965
 
991
966
  /** An OCR request. */
992
967
  export interface OcrRequest {
993
968
  /** The model/provider to use (e.g. `"mistral/mistral-ocr-latest"`). */
994
- model?: string;
969
+ readonly model?: string;
995
970
  /** The document to process (URL or base64). */
996
- document?: JsOcrDocument;
971
+ readonly document?: OcrDocument;
997
972
  /** Specific pages to process (1-indexed). `None` means all pages. */
998
- pages?: Array<number>;
973
+ readonly pages?: Array<number>;
999
974
  /** Whether to include base64-encoded images of each processed page. */
1000
- includeImageBase64?: boolean;
975
+ readonly includeImageBase64?: boolean;
1001
976
  }
1002
977
 
1003
978
  /** An OCR response. */
1004
979
  export interface OcrResponse {
1005
980
  /** Extracted pages in order. */
1006
- pages: Array<JsOcrPage>;
981
+ readonly pages: Array<OcrPage>;
1007
982
  /** Model/provider used for OCR. */
1008
- model: string;
983
+ readonly model: string;
1009
984
  /** Token usage, if reported by the provider. */
1010
- usage?: Usage;
985
+ readonly usage?: Usage;
1011
986
  }
1012
987
 
1013
988
  /** Page dimensions in pixels. */
1014
989
  export interface PageDimensions {
1015
990
  /** Width in pixels. */
1016
- width: number;
991
+ readonly width: number;
1017
992
  /** Height in pixels. */
1018
- height: number;
993
+ readonly height: number;
1019
994
  }
1020
995
 
1021
996
  /**
1022
997
  * Breakdown of tokens used in the prompt portion of a request.
1023
998
  *
1024
- * `cached_tokens` is included in `Usage.prompt_tokens` — it is *not* an
999
+ * `cached_tokens` is included in `Usage::prompt_tokens` — it is *not* an
1025
1000
  * additional charge on top of the prompt token count. When pricing supports
1026
1001
  * a `cache_read_input_token_cost`, the cached portion is billed at the
1027
1002
  * discounted rate and the remainder at the regular input rate.
1028
1003
  */
1029
1004
  export interface PromptTokensDetails {
1030
1005
  /** Cached tokens present in the prompt. Defaults to 0 when absent. */
1031
- cachedTokens?: number;
1006
+ readonly cachedTokens?: number;
1032
1007
  /** Audio input tokens present in the prompt. Defaults to 0 when absent. */
1033
- audioTokens?: number;
1008
+ readonly audioTokens?: number;
1034
1009
  }
1035
1010
 
1036
1011
  /** Static configuration for a single provider entry in providers.json. */
1037
1012
  export interface ProviderConfig {
1038
1013
  /** Provider identifier (matches the entry key in providers.json). */
1039
- name: string;
1014
+ readonly name: string;
1040
1015
  /** Human-readable provider name shown in UIs. */
1041
- displayName?: string;
1016
+ readonly displayName?: string;
1042
1017
  /** Base URL used as the default for this provider's HTTP client. */
1043
- baseUrl?: string;
1018
+ readonly baseUrl?: string;
1044
1019
  /** Authentication scheme metadata (auth type + env var holding the key). */
1045
- auth?: JsAuthConfig;
1020
+ readonly auth?: AuthConfig;
1046
1021
  /** Supported endpoint kinds (e.g. `chat`, `embeddings`). */
1047
- endpoints?: Array<string>;
1022
+ readonly endpoints?: Array<string>;
1048
1023
  /** Model-name prefixes claimed by this provider (e.g. `["gpt-", "o1-"]`). */
1049
- modelPrefixes?: Array<string>;
1024
+ readonly modelPrefixes?: Array<string>;
1050
1025
  /**
1051
1026
  * Parameter key renaming for this provider.
1052
1027
  *
@@ -1054,251 +1029,260 @@ export interface ProviderConfig {
1054
1029
  * to the name this provider expects (e.g. `"max_tokens"`). Applied
1055
1030
  * automatically by [`ConfigDrivenProvider::transform_request`].
1056
1031
  */
1057
- paramMappings?: Record<string, string>;
1032
+ readonly paramMappings?: Record<string, string>;
1058
1033
  }
1059
1034
 
1060
1035
  /** Configuration for per-model rate limits. */
1061
1036
  export interface RateLimitConfig {
1062
1037
  /** Maximum requests per window. `None` means unlimited. */
1063
- rpm?: number;
1038
+ readonly rpm?: number;
1064
1039
  /** Maximum tokens per window. `None` means unlimited. */
1065
- tpm?: number;
1040
+ readonly tpm?: number;
1066
1041
  /** Fixed window duration (defaults to 60 s). */
1067
- window?: number;
1042
+ readonly window?: number;
1068
1043
  }
1069
1044
 
1070
- export declare function rateLimitConfigDefault(): RateLimitConfig;
1071
-
1072
1045
  /** Controls how much reasoning effort the model should use. */
1073
- export declare const enum ReasoningEffort {
1046
+ export declare enum ReasoningEffort {
1074
1047
  Low = "low",
1075
1048
  Medium = "medium",
1076
1049
  High = "high",
1077
1050
  }
1078
1051
 
1079
- /**
1080
- * Register a custom provider in the global runtime registry.
1081
- *
1082
- * The provider will be checked **before** all built-in providers during model
1083
- * detection. If a provider with the same `name` already exists it is replaced.
1084
- *
1085
- * # Errors
1086
- *
1087
- * Returns an error if the config is invalid (empty name, empty base_url, or
1088
- * no model prefixes).
1089
- */
1090
- export declare function registerCustomProvider(config: CustomProviderConfig): void;
1052
+ /** A document to be reranked — either a plain string or an object with a text field. */
1053
+ export declare enum RerankDocument {
1054
+ /** Plain text document content. */
1055
+ Text = "Text",
1056
+ /** Document with explicit text field (may include metadata). */
1057
+ Object = "Object",
1058
+ }
1091
1059
 
1092
1060
  /** Request to rerank documents by relevance to a query. */
1093
1061
  export interface RerankRequest {
1094
1062
  /** Model ID (e.g., `"cohere/rerank-english-v3.0"`). */
1095
- model?: string;
1063
+ readonly model?: string;
1096
1064
  /** The search query. */
1097
- query?: string;
1065
+ readonly query?: string;
1098
1066
  /** Documents to rerank. */
1099
- documents?: Array<JsRerankDocument>;
1067
+ readonly documents?: Array<RerankDocument>;
1100
1068
  /** Return only the top N results. Optional. */
1101
- topN?: number;
1069
+ readonly topN?: number;
1102
1070
  /** Include the document content in results. Defaults to false. */
1103
- returnDocuments?: boolean;
1071
+ readonly returnDocuments?: boolean;
1104
1072
  }
1105
1073
 
1106
1074
  /** Response from the rerank endpoint. */
1107
1075
  export interface RerankResponse {
1108
1076
  /** Unique identifier for this rerank request. */
1109
- id?: string;
1077
+ readonly id?: string;
1110
1078
  /** Reranked documents in order of relevance. */
1111
- results: Array<JsRerankResult>;
1079
+ readonly results: Array<RerankResult>;
1112
1080
  /** Optional metadata about the reranking operation. */
1113
- meta?: any;
1081
+ readonly meta?: JsonValue;
1114
1082
  }
1115
1083
 
1116
1084
  /** A single reranked document with its relevance score. */
1117
1085
  export interface RerankResult {
1118
1086
  /** Original document index in the input list. */
1119
- index: number;
1087
+ readonly index: number;
1120
1088
  /** Relevance score in `[0, 1]`. Higher indicates more relevant. */
1121
- relevanceScore: number;
1089
+ readonly relevanceScore: number;
1122
1090
  /** Original document content (if `return_documents` was true). */
1123
- document?: JsRerankResultDocument;
1091
+ readonly document?: RerankResultDocument;
1124
1092
  }
1125
1093
 
1126
1094
  /** The text content of a reranked document, returned when `return_documents` is true. */
1127
1095
  export interface RerankResultDocument {
1128
1096
  /** Document text. */
1129
- text: string;
1097
+ readonly text: string;
1130
1098
  }
1131
1099
 
1132
1100
  /** Response format constraint. */
1133
- export interface ResponseFormat {
1134
- type: string;
1135
- jsonSchema?: JsonSchemaFormat;
1136
- }
1101
+ export type ResponseFormat =
1102
+ | { type: "text" }
1103
+ | { type: "json_object" }
1104
+ | { type: "json_schema"; jsonSchema: JsonSchemaFormat };
1137
1105
 
1138
1106
  /** Response from a structured response request. */
1139
1107
  export interface ResponseObject {
1140
1108
  /** Unique response ID. */
1141
- id?: string;
1109
+ readonly id?: string;
1142
1110
  /** Object type (e.g., `"response"`). */
1143
- object?: string;
1111
+ readonly object?: string;
1144
1112
  /** Unix timestamp of response creation. */
1145
- createdAt?: number;
1113
+ readonly createdAt?: number;
1146
1114
  /** Model used to generate the response. */
1147
- model?: string;
1115
+ readonly model?: string;
1148
1116
  /** Status (e.g., `"succeeded"`, `"failed"`). */
1149
- status?: string;
1117
+ readonly status?: string;
1150
1118
  /** Output items from the response. */
1151
- output?: Array<JsResponseOutputItem>;
1119
+ readonly output?: Array<ResponseOutputItem>;
1152
1120
  /** Token usage. */
1153
- usage?: JsResponseUsage;
1121
+ readonly usage?: ResponseUsage;
1154
1122
  /** Error details (if status is "failed"). */
1155
- error?: any;
1123
+ readonly error?: JsonValue;
1156
1124
  }
1157
1125
 
1158
1126
  /** A single output item from the response. */
1159
1127
  export interface ResponseOutputItem {
1160
1128
  /** Output type (e.g., `"text"`, `"object"`, `"error"`). */
1161
- type?: string;
1129
+ readonly itemType?: string;
1162
1130
  /** Output content (flattened into the object). */
1163
- content?: any;
1131
+ readonly content?: JsonValue;
1164
1132
  }
1165
1133
 
1166
1134
  /** A tool available for the response request. */
1167
1135
  export interface ResponseTool {
1168
1136
  /** Tool type (e.g., "extractor", "search"). */
1169
- type?: string;
1137
+ readonly toolType?: string;
1170
1138
  /** Tool configuration (flattened into the object). */
1171
- config?: any;
1139
+ readonly config?: JsonValue;
1172
1140
  }
1173
1141
 
1174
1142
  /** Token usage for a response. */
1175
1143
  export interface ResponseUsage {
1176
1144
  /** Input tokens used. */
1177
- inputTokens?: number;
1145
+ readonly inputTokens?: number;
1178
1146
  /** Output tokens used. */
1179
- outputTokens?: number;
1147
+ readonly outputTokens?: number;
1180
1148
  /** Total tokens used. */
1181
- totalTokens?: number;
1149
+ readonly totalTokens?: number;
1182
1150
  }
1183
1151
 
1184
1152
  /** A search request. */
1185
1153
  export interface SearchRequest {
1186
1154
  /** The model/provider to use (e.g. `"brave/web-search"`, `"tavily/search"`). */
1187
- model?: string;
1155
+ readonly model?: string;
1188
1156
  /** The search query string. */
1189
- query?: string;
1157
+ readonly query?: string;
1190
1158
  /** Maximum number of results to return. */
1191
- maxResults?: number;
1159
+ readonly maxResults?: number;
1192
1160
  /** Domain filter — restrict results to specific domains. */
1193
- searchDomainFilter?: Array<string>;
1161
+ readonly searchDomainFilter?: Array<string>;
1194
1162
  /** Country code for localized results (ISO 3166-1 alpha-2, e.g., `"US"`, `"FR"`). */
1195
- country?: string;
1163
+ readonly country?: string;
1196
1164
  }
1197
1165
 
1198
1166
  /** A search response. */
1199
1167
  export interface SearchResponse {
1200
1168
  /** List of search results. */
1201
- results: Array<JsSearchResult>;
1169
+ readonly results: Array<SearchResult>;
1202
1170
  /** Model/provider that performed the search. */
1203
- model: string;
1171
+ readonly model: string;
1204
1172
  }
1205
1173
 
1206
1174
  /** An individual search result. */
1207
1175
  export interface SearchResult {
1208
1176
  /** Result title. */
1209
- title: string;
1177
+ readonly title: string;
1210
1178
  /** Result URL. */
1211
- url: string;
1179
+ readonly url: string;
1212
1180
  /** Text snippet or excerpt from the page. */
1213
- snippet: string;
1181
+ readonly snippet: string;
1214
1182
  /** Publication or last-updated date, if available. */
1215
- date?: string;
1183
+ readonly date?: string;
1216
1184
  }
1217
1185
 
1218
1186
  /** Name of the specific function to invoke. */
1219
1187
  export interface SpecificFunction {
1220
1188
  /** Function name. */
1221
- name?: string;
1189
+ readonly name?: string;
1222
1190
  }
1223
1191
 
1224
1192
  /** Directive to call a specific tool. */
1225
1193
  export interface SpecificToolChoice {
1226
1194
  /** Tool type (always "function"). */
1227
- type?: JsToolType;
1195
+ readonly choiceType?: ToolType;
1228
1196
  /** The specific function to invoke. */
1229
- function?: JsSpecificFunction;
1197
+ readonly function?: SpecificFunction;
1198
+ }
1199
+
1200
+ /** Stop sequence(s) that cause the model to stop generating. */
1201
+ export declare enum StopSequence {
1202
+ /** Single stop sequence. */
1203
+ Single = "Single",
1204
+ /** Multiple stop sequences. */
1205
+ Multiple = "Multiple",
1230
1206
  }
1231
1207
 
1232
1208
  /** A streaming choice with incremental delta. */
1233
1209
  export interface StreamChoice {
1234
1210
  /** Index of this choice in the choices array. */
1235
- index?: number;
1211
+ readonly index?: number;
1236
1212
  /** Incremental update to the message (content, tool calls, etc.). */
1237
- delta?: JsStreamDelta;
1213
+ readonly delta?: StreamDelta;
1238
1214
  /** Why the stream ended (present only in final chunk). */
1239
- finishReason?: JsFinishReason;
1215
+ readonly finishReason?: FinishReason;
1240
1216
  }
1241
1217
 
1242
1218
  /** Incremental delta in a stream chunk. */
1243
1219
  export interface StreamDelta {
1244
1220
  /** Role (typically present only in the first chunk). */
1245
- role?: string;
1221
+ readonly role?: string;
1246
1222
  /** Partial content chunk (e.g., a few words of the response). */
1247
- content?: string;
1223
+ readonly content?: string;
1248
1224
  /** Partial tool calls being streamed. */
1249
- toolCalls?: Array<JsStreamToolCall>;
1225
+ readonly toolCalls?: Array<StreamToolCall>;
1250
1226
  /** Deprecated legacy function_call delta; retained for API compatibility. */
1251
- functionCall?: JsStreamFunctionCall;
1227
+ readonly functionCall?: StreamFunctionCall;
1252
1228
  /** Partial refusal message. */
1253
- refusal?: string;
1229
+ readonly refusal?: string;
1254
1230
  }
1255
1231
 
1256
1232
  /** Partial function call details in a stream. */
1257
1233
  export interface StreamFunctionCall {
1258
1234
  /** Function name (typically in the first chunk). */
1259
- name?: string;
1235
+ readonly name?: string;
1260
1236
  /** Partial JSON arguments chunk. */
1261
- arguments?: string;
1237
+ readonly arguments?: string;
1262
1238
  }
1263
1239
 
1264
1240
  /** Options for streaming responses. */
1265
1241
  export interface StreamOptions {
1266
1242
  /** If true, include token usage in the final stream chunk. */
1267
- includeUsage?: boolean;
1243
+ readonly includeUsage?: boolean;
1268
1244
  }
1269
1245
 
1270
1246
  /** A streaming tool call being built incrementally. */
1271
1247
  export interface StreamToolCall {
1272
1248
  /** Index of this tool call in the tool_calls array. */
1273
- index?: number;
1249
+ readonly index?: number;
1274
1250
  /** Tool call ID (typically in the first chunk for this call). */
1275
- id?: string;
1251
+ readonly id?: string;
1276
1252
  /** Tool type (typically "function"). */
1277
- type?: JsToolType;
1253
+ readonly callType?: ToolType;
1278
1254
  /** Partial function name and arguments. */
1279
- function?: JsStreamFunctionCall;
1255
+ readonly function?: StreamFunctionCall;
1280
1256
  }
1281
1257
 
1282
1258
  /** System message guiding model behavior for the entire conversation. */
1283
1259
  export interface SystemMessage {
1284
1260
  /** Instructions or context that apply throughout the conversation. */
1285
- content?: string;
1261
+ readonly content?: string;
1286
1262
  /** Optional name for the system message source. */
1287
- name?: string;
1263
+ readonly name?: string;
1288
1264
  }
1289
1265
 
1290
1266
  /** A tool call the model wants to execute. */
1291
1267
  export interface ToolCall {
1292
1268
  /** Unique ID for this call, used to reference in tool result messages. */
1293
- id: string;
1269
+ readonly id: string;
1294
1270
  /** Tool type (always "function"). */
1295
- type: JsToolType;
1271
+ readonly callType: ToolType;
1296
1272
  /** Function name and arguments. */
1297
- function: JsFunctionCall;
1273
+ readonly function: FunctionCall;
1274
+ }
1275
+
1276
+ /** Tool usage mode or a specific tool to call. */
1277
+ export declare enum ToolChoice {
1278
+ /** Predefined mode: auto, required, or none. */
1279
+ Mode = "Mode",
1280
+ /** Force a specific tool to be called. */
1281
+ Specific = "Specific",
1298
1282
  }
1299
1283
 
1300
1284
  /** Tool choice mode. */
1301
- export declare const enum ToolChoiceMode {
1285
+ export declare enum ToolChoiceMode {
1302
1286
  /** Model may or may not call tools; default behavior. */
1303
1287
  Auto = "auto",
1304
1288
  /** Model must call at least one tool. */
@@ -1310,11 +1294,11 @@ export declare const enum ToolChoiceMode {
1310
1294
  /** Tool execution result returned to the model. */
1311
1295
  export interface ToolMessage {
1312
1296
  /** Result of the tool execution. */
1313
- content?: string;
1297
+ readonly content?: string;
1314
1298
  /** ID of the tool call this result responds to. */
1315
- toolCallId?: string;
1299
+ readonly toolCallId?: string;
1316
1300
  /** Optional tool/function name. */
1317
- name?: string;
1301
+ readonly name?: string;
1318
1302
  }
1319
1303
 
1320
1304
  /**
@@ -1324,66 +1308,92 @@ export interface ToolMessage {
1324
1308
  * that constraint at the type level and rejects any other value on
1325
1309
  * deserialization.
1326
1310
  */
1327
- export declare const enum ToolType {
1311
+ export declare enum ToolType {
1328
1312
  Function = "function",
1329
1313
  }
1330
1314
 
1331
1315
  /** Response from a transcription request. */
1332
1316
  export interface TranscriptionResponse {
1333
1317
  /** The transcribed text. */
1334
- text?: string;
1318
+ readonly text?: string;
1335
1319
  /** Detected language (ISO-639-1 code). */
1336
- language?: string;
1320
+ readonly language?: string;
1337
1321
  /** Total audio duration in seconds. */
1338
- duration?: number;
1322
+ readonly duration?: number;
1339
1323
  /** Detailed segment-level transcription (if response_format is "verbose_json"). */
1340
- segments?: Array<JsTranscriptionSegment>;
1324
+ readonly segments?: Array<TranscriptionSegment>;
1341
1325
  }
1342
1326
 
1343
1327
  /** A segment of transcribed audio with timing information. */
1344
1328
  export interface TranscriptionSegment {
1345
1329
  /** Segment index (0-based). */
1346
- id?: number;
1330
+ readonly id?: number;
1347
1331
  /** Start time in seconds. */
1348
- start?: number;
1332
+ readonly start?: number;
1349
1333
  /** End time in seconds. */
1350
- end?: number;
1334
+ readonly end?: number;
1351
1335
  /** Transcribed text for this segment. */
1352
- text?: string;
1336
+ readonly text?: string;
1353
1337
  }
1354
1338
 
1355
- /**
1356
- * Remove a previously registered custom provider by name.
1357
- *
1358
- * Returns `true` if a provider with the given name was found and removed,
1359
- * `false` if no such provider existed.
1360
- *
1361
- * # Errors
1362
- *
1363
- * Returns an error only if the internal lock is poisoned.
1364
- */
1365
- export declare function unregisterCustomProvider(name: string): boolean;
1366
-
1367
1339
  /** Token-usage accounting returned by the provider on each completion / embedding call. */
1368
1340
  export interface Usage {
1369
1341
  /** Prompt tokens used. Defaults to 0 when absent (some providers omit this). */
1370
- promptTokens?: number;
1342
+ readonly promptTokens?: number;
1371
1343
  /** Completion tokens used. Defaults to 0 when absent (e.g. embedding responses). */
1372
- completionTokens?: number;
1344
+ readonly completionTokens?: number;
1373
1345
  /** Total tokens used. Defaults to 0 when absent (some providers omit this). */
1374
- totalTokens?: number;
1346
+ readonly totalTokens?: number;
1375
1347
  /**
1376
1348
  * Breakdown of tokens used in the prompt, including cached tokens served
1377
1349
  * at the provider's discounted cache-read rate. Absent when the provider
1378
1350
  * does not return prompt-token details.
1379
1351
  */
1380
- promptTokensDetails?: JsPromptTokensDetails;
1352
+ readonly promptTokensDetails?: PromptTokensDetails;
1353
+ }
1354
+
1355
+ /** User message content as either plain text or a list of multimodal parts. */
1356
+ export declare enum UserContent {
1357
+ /** Plain text content. */
1358
+ Text = "Text",
1359
+ /** Array of content parts (text, images, documents, audio). */
1360
+ Parts = "Parts",
1381
1361
  }
1382
1362
 
1383
1363
  /** User message in the conversation. */
1384
1364
  export interface UserMessage {
1385
1365
  /** Message content as plain text or array of content parts (text, images, documents, audio). */
1386
- content?: JsUserContent;
1366
+ readonly content?: UserContent;
1387
1367
  /** Optional name for the user. */
1388
- name?: string;
1368
+ readonly name?: string;
1369
+ }
1370
+
1371
+ /**
1372
+ * Register a custom provider in the global runtime registry.
1373
+ *
1374
+ * The provider will be checked **before** all built-in providers during model
1375
+ * detection. If a provider with the same `name` already exists it is replaced.
1376
+ * @throws Returns an error if the config is invalid (empty name, empty base_url, or
1377
+ * no model prefixes).
1378
+ */
1379
+ export declare function registerCustomProvider(config: CustomProviderConfig): void;
1380
+
1381
+ /**
1382
+ * Remove a previously registered custom provider by name.
1383
+ *
1384
+ * Returns `true` if a provider with the given name was found and removed,
1385
+ * `false` if no such provider existed.
1386
+ * @throws Returns an error only if the internal lock is poisoned.
1387
+ */
1388
+ export declare function unregisterCustomProvider(name: string): boolean;
1389
+
1390
+ export declare class ChatStreamIterator {
1391
+ next(value?: undefined): Promise<IteratorResult<ChatCompletionChunk, void>>;
1392
+ [Symbol.asyncIterator](): AsyncGenerator<ChatCompletionChunk, void, undefined>;
1393
+ }
1394
+
1395
+ export declare class LiterLlmErrorInfo {
1396
+ statusCode(): number;
1397
+ isTransient(): boolean;
1398
+ errorType(): string;
1389
1399
  }