@keln.ai/sdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +6 -0
  4. package/README.md +598 -2
  5. package/dist/api-promise.d.ts +30 -0
  6. package/dist/api-promise.js +38 -0
  7. package/dist/api-promise.js.map +1 -0
  8. package/dist/api.d.ts +130 -0
  9. package/dist/api.js +321 -0
  10. package/dist/api.js.map +1 -0
  11. package/dist/client.d.ts +27 -0
  12. package/dist/client.js +42 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/commands.d.ts +78 -0
  15. package/dist/commands.js +269 -0
  16. package/dist/commands.js.map +1 -0
  17. package/dist/errors.d.ts +93 -0
  18. package/dist/errors.js +173 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/files.d.ts +33 -0
  21. package/dist/files.js +130 -0
  22. package/dist/files.js.map +1 -0
  23. package/dist/images.d.ts +79 -0
  24. package/dist/images.js +150 -0
  25. package/dist/images.js.map +1 -0
  26. package/dist/index.d.ts +23 -0
  27. package/dist/index.js +14 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/inference.d.ts +672 -0
  30. package/dist/inference.js +244 -0
  31. package/dist/inference.js.map +1 -0
  32. package/dist/retry.d.ts +10 -0
  33. package/dist/retry.js +87 -0
  34. package/dist/retry.js.map +1 -0
  35. package/dist/sandbox.d.ts +132 -0
  36. package/dist/sandbox.js +216 -0
  37. package/dist/sandbox.js.map +1 -0
  38. package/dist/sse.d.ts +20 -0
  39. package/dist/sse.js +119 -0
  40. package/dist/sse.js.map +1 -0
  41. package/dist/streaming.d.ts +20 -0
  42. package/dist/streaming.js +77 -0
  43. package/dist/streaming.js.map +1 -0
  44. package/dist/terminals.d.ts +75 -0
  45. package/dist/terminals.js +239 -0
  46. package/dist/terminals.js.map +1 -0
  47. package/dist/types.d.ts +226 -0
  48. package/dist/types.js +6 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/uploads.d.ts +35 -0
  51. package/dist/uploads.js +154 -0
  52. package/dist/uploads.js.map +1 -0
  53. package/dist/util.d.ts +19 -0
  54. package/dist/util.js +69 -0
  55. package/dist/util.js.map +1 -0
  56. package/dist/web.d.ts +66 -0
  57. package/dist/web.js +44 -0
  58. package/dist/web.js.map +1 -0
  59. package/package.json +57 -4
  60. package/src/api-promise.ts +50 -0
  61. package/src/api.ts +415 -0
  62. package/src/client.ts +43 -0
  63. package/src/commands.ts +325 -0
  64. package/src/errors.ts +185 -0
  65. package/src/files.ts +149 -0
  66. package/src/images.ts +174 -0
  67. package/src/index.ts +114 -0
  68. package/src/inference.ts +737 -0
  69. package/src/retry.ts +77 -0
  70. package/src/sandbox.ts +281 -0
  71. package/src/sse.ts +124 -0
  72. package/src/streaming.ts +79 -0
  73. package/src/terminals.ts +269 -0
  74. package/src/types.ts +241 -0
  75. package/src/uploads.ts +177 -0
  76. package/src/util.ts +78 -0
  77. package/src/web.ts +94 -0
@@ -0,0 +1,672 @@
1
+ /**
2
+ * Inference on api.keln.ai: chat completions, responses, embeddings, rerank, decisions, transcriptions, speech and
3
+ * images, and the model list.
4
+ *
5
+ * Each call takes the request body its endpoint documents, and any other field of the body reaches the API unchanged.
6
+ * Every call retries by the rules in retry.ts, and returns an `ApiPromise`: await it for the answer, or call
7
+ * `withResponse()` for its headers too.
8
+ */
9
+ import { ApiPromise } from './api-promise.js';
10
+ import type { Api } from './api.js';
11
+ import type { Stream } from './streaming.js';
12
+ import { type Uploadable } from './uploads.js';
13
+ /** Per call. */
14
+ export type InferenceCallOptions = {
15
+ /** Aborting it ends the call with the signal's reason. */
16
+ signal?: AbortSignal;
17
+ /** Milliseconds the call may take in all, an upload's reading, retries and waits included. Default: no limit. */
18
+ timeout?: number;
19
+ /** Extra request headers. One the SDK also sends, in any letter case, replaces the SDK's. */
20
+ headers?: Record<string, string>;
21
+ /** Extra query parameters. */
22
+ query?: Record<string, string>;
23
+ };
24
+ /** `_request_id`: the API's id for the request (`x-keln-request-id`). */
25
+ export type WithRequestId = {
26
+ readonly _request_id?: string | undefined;
27
+ };
28
+ export type ChatMessage = {
29
+ role: string;
30
+ content?: unknown;
31
+ [field: string]: unknown;
32
+ };
33
+ /**
34
+ * How deeply the model thinks. With `none`, the model answers without thinking. The other values set how deeply it
35
+ * thinks, and `xhigh` means the same as `max`. Without this field, a model that thinks uses its deepest setting.
36
+ * `GET /v1/models` lists the levels each model supports in `reasoning.supported_efforts`.
37
+ */
38
+ export type ReasoningEffort = 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
39
+ /**
40
+ * The mode the call runs in: `lite` or `standard`. `default` and `standard_only` mean `standard`. `auto`, or no
41
+ * value, uses the mode set on the API key.
42
+ */
43
+ export type ServiceTier = 'lite' | 'standard' | 'auto' | 'default' | 'standard_only';
44
+ /** Web search on a chat completion. `{}` turns it on with the defaults. */
45
+ export type ChatWebSearchOptions = {
46
+ /** Searches per turn: at most 10, the default. */
47
+ max_uses?: number;
48
+ /**
49
+ * Keep results to `allowed_domains`, remove `blocked_domains`, or both. They apply to the pages the model reads
50
+ * too.
51
+ */
52
+ filters?: {
53
+ allowed_domains?: string[];
54
+ blocked_domains?: string[];
55
+ };
56
+ /** `false`: the model searches but reads no pages. */
57
+ fetch?: boolean;
58
+ /** `true`: the sources the model used, in `message.web_search_sources`. */
59
+ include_sources?: boolean;
60
+ [field: string]: unknown;
61
+ };
62
+ /** Code execution on a chat completion, turned on by a `code_interpreter` or `shell` tool in `tools`. */
63
+ export type CodeExecutionOptions = {
64
+ /** `true`: each run in `message.provider_specific_fields.keln_code_execution`, or in the deltas of a stream. */
65
+ include_events?: boolean;
66
+ /** Runs per response. Default 20, at most 30. */
67
+ max_tool_calls?: number;
68
+ /** Milliseconds a run may take before it is stopped. Default 120000, at most 300000. */
69
+ timeout_ms?: number;
70
+ /** Bytes of each run's output the model gets. Default 16384, at most 65536. */
71
+ max_output_length?: number;
72
+ [field: string]: unknown;
73
+ };
74
+ export type ChatCompletionCreateParams = {
75
+ model: string;
76
+ messages: ChatMessage[];
77
+ stream?: boolean | null;
78
+ reasoning_effort?: ReasoningEffort;
79
+ service_tier?: ServiceTier;
80
+ web_search_options?: ChatWebSearchOptions;
81
+ code_execution?: CodeExecutionOptions;
82
+ [field: string]: unknown;
83
+ };
84
+ export type Usage = {
85
+ prompt_tokens: number;
86
+ completion_tokens?: number;
87
+ total_tokens: number;
88
+ prompt_tokens_details?: {
89
+ cached_tokens?: number;
90
+ [field: string]: unknown;
91
+ };
92
+ completion_tokens_details?: {
93
+ reasoning_tokens?: number;
94
+ [field: string]: unknown;
95
+ };
96
+ /** What the call billed, in USD, searches and code execution included. */
97
+ cost?: number;
98
+ /** Searches the model ran, on a call with web search. */
99
+ web_search_requests?: number;
100
+ /** Seconds of code execution billed, on a call that ran code. */
101
+ code_execution_seconds?: number;
102
+ [field: string]: unknown;
103
+ };
104
+ export type ChatCompletion = WithRequestId & {
105
+ id: string;
106
+ object: 'chat.completion';
107
+ created?: number;
108
+ model: string;
109
+ choices: Array<{
110
+ index: number;
111
+ message: {
112
+ role: string;
113
+ content: string | null;
114
+ reasoning_content?: string | null;
115
+ tool_calls?: unknown[];
116
+ [field: string]: unknown;
117
+ };
118
+ finish_reason: string | null;
119
+ [field: string]: unknown;
120
+ }>;
121
+ usage?: Usage;
122
+ /** The mode that served the call: `standard` or `lite`. */
123
+ service_tier?: string;
124
+ [field: string]: unknown;
125
+ };
126
+ export type ChatCompletionChunk = {
127
+ id: string;
128
+ object: 'chat.completion.chunk';
129
+ model: string;
130
+ choices: Array<{
131
+ index: number;
132
+ delta: {
133
+ role?: string;
134
+ content?: string | null;
135
+ reasoning_content?: string | null;
136
+ tool_calls?: unknown[];
137
+ [field: string]: unknown;
138
+ };
139
+ finish_reason: string | null;
140
+ [field: string]: unknown;
141
+ }>;
142
+ usage?: Usage | null;
143
+ /** The mode that served the call, on the last chunk. */
144
+ service_tier?: string;
145
+ [field: string]: unknown;
146
+ };
147
+ export type ResponseCreateParams = {
148
+ model: string;
149
+ input?: string | unknown[];
150
+ stream?: boolean | null;
151
+ /** `effort` works as `reasoning_effort` does on a chat completion. */
152
+ reasoning?: {
153
+ effort?: ReasoningEffort;
154
+ summary?: string | null;
155
+ [field: string]: unknown;
156
+ };
157
+ service_tier?: ServiceTier;
158
+ [field: string]: unknown;
159
+ };
160
+ /** `usage` on a response. */
161
+ export type ResponseUsage = {
162
+ input_tokens: number;
163
+ output_tokens: number;
164
+ total_tokens: number;
165
+ input_tokens_details?: {
166
+ cached_tokens?: number;
167
+ [field: string]: unknown;
168
+ };
169
+ output_tokens_details?: {
170
+ reasoning_tokens?: number;
171
+ [field: string]: unknown;
172
+ };
173
+ /** Searches the model ran, on a call with web search. */
174
+ web_search_requests?: number;
175
+ /** Seconds of code execution billed, on a call that ran code. */
176
+ code_execution_seconds?: number;
177
+ [field: string]: unknown;
178
+ };
179
+ export type Response = WithRequestId & {
180
+ id: string;
181
+ object: 'response';
182
+ status: string;
183
+ output: unknown[];
184
+ usage?: ResponseUsage;
185
+ /** The mode that served the call: `standard` or `lite`. */
186
+ service_tier?: string;
187
+ [field: string]: unknown;
188
+ };
189
+ /** One event of a streamed response: `type` is `response.created`, `response.output_text.delta`, `error`, .... */
190
+ export type ResponseStreamEvent = {
191
+ type: string;
192
+ [field: string]: unknown;
193
+ };
194
+ export type EmbeddingCreateParams = {
195
+ model: string;
196
+ input: string | string[];
197
+ dimensions?: number;
198
+ /** Unset: the SDK asks for base64 and hands back numbers. Set: the answer comes as sent. */
199
+ encoding_format?: 'float' | 'base64';
200
+ user?: string;
201
+ [field: string]: unknown;
202
+ };
203
+ export type CreateEmbeddingResponse = WithRequestId & {
204
+ object: 'list';
205
+ model: string;
206
+ data: Array<{
207
+ object: 'embedding';
208
+ index: number;
209
+ embedding: number[] | string;
210
+ }>;
211
+ usage: Usage;
212
+ [field: string]: unknown;
213
+ };
214
+ export type RerankCreateParams = {
215
+ model: string;
216
+ query: string;
217
+ documents: Array<string | {
218
+ text: string;
219
+ }>;
220
+ /** Only the best `top_n`. */
221
+ top_n?: number;
222
+ /** Attach each document's text to its result. */
223
+ return_documents?: boolean;
224
+ /** What "relevant" means for your task, on a model that takes an instruction. */
225
+ instruction?: string;
226
+ [field: string]: unknown;
227
+ };
228
+ export type RerankResponse = WithRequestId & {
229
+ object: 'rerank';
230
+ model: string;
231
+ /** Best first. `index` is the document's place in `documents`. */
232
+ results: Array<{
233
+ index: number;
234
+ relevance_score: number;
235
+ document?: {
236
+ text: string;
237
+ };
238
+ }>;
239
+ usage: Usage;
240
+ [field: string]: unknown;
241
+ };
242
+ export type DecisionCreateParams = {
243
+ model: string;
244
+ /** What the questions are about: text or JSON. */
245
+ state: unknown;
246
+ /** Each name to its question: `type` `noul`, `choice` or `score`, with its `instructions`. */
247
+ questions: Record<string, {
248
+ type: string;
249
+ instructions: string;
250
+ [field: string]: unknown;
251
+ }>;
252
+ [field: string]: unknown;
253
+ };
254
+ export type DecisionResponse = WithRequestId & {
255
+ model: string;
256
+ /** Under the names `questions` used. */
257
+ answers: Record<string, {
258
+ [field: string]: unknown;
259
+ }>;
260
+ usage?: Usage;
261
+ [field: string]: unknown;
262
+ };
263
+ /** The answer formats of a transcription. `text`, `srt` and `vtt` come back as a string. */
264
+ export type AudioResponseFormat = 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt' | 'diarized_json';
265
+ export type TranscriptionCreateParams = {
266
+ /** The audio: a `File`, `Blob`, `Response` or async iterable of bytes (`fs.createReadStream(path)`); see `toFile`. */
267
+ file: Uploadable;
268
+ model: string;
269
+ response_format?: AudioResponseFormat;
270
+ language?: string;
271
+ languages?: string[];
272
+ /** Spelling hints for names and terms. */
273
+ keywords?: string[];
274
+ prompt?: string;
275
+ temperature?: number;
276
+ /** With `response_format: 'verbose_json'`. */
277
+ timestamp_granularities?: Array<'word' | 'segment'>;
278
+ chunking_strategy?: 'auto' | Record<string, unknown>;
279
+ include?: string[];
280
+ known_speaker_names?: string[];
281
+ known_speaker_references?: string[];
282
+ [field: string]: unknown;
283
+ };
284
+ /** `usage` on a transcription: the audio's length and what it billed. */
285
+ export type TranscriptionUsage = {
286
+ type: 'duration';
287
+ seconds: number;
288
+ cost?: number;
289
+ [field: string]: unknown;
290
+ };
291
+ export type Transcription = WithRequestId & {
292
+ text: string;
293
+ usage?: TranscriptionUsage;
294
+ [field: string]: unknown;
295
+ };
296
+ export type TranscriptionVerbose = WithRequestId & {
297
+ task?: string;
298
+ language: string;
299
+ duration: number;
300
+ text: string;
301
+ segments?: Array<{
302
+ id: number;
303
+ start: number;
304
+ end: number;
305
+ text: string;
306
+ speaker?: number;
307
+ [field: string]: unknown;
308
+ }>;
309
+ words?: Array<{
310
+ word: string;
311
+ start: number;
312
+ end: number;
313
+ speaker?: number;
314
+ [field: string]: unknown;
315
+ }>;
316
+ usage?: TranscriptionUsage;
317
+ [field: string]: unknown;
318
+ };
319
+ export type TranscriptionDiarized = WithRequestId & {
320
+ task?: string;
321
+ duration: number;
322
+ text: string;
323
+ segments: Array<{
324
+ type: 'transcript.text.segment';
325
+ id: string;
326
+ start: number;
327
+ end: number;
328
+ text: string;
329
+ speaker: string;
330
+ [field: string]: unknown;
331
+ }>;
332
+ usage?: TranscriptionUsage;
333
+ [field: string]: unknown;
334
+ };
335
+ /** One turn of a conversation: a stretch of text in one voice, with its own style direction. */
336
+ export type SpeechTurn = {
337
+ text: string;
338
+ voice?: string;
339
+ instructions?: string;
340
+ };
341
+ export type SpeechCreateParams = {
342
+ model: string;
343
+ /** The text, or a list of turns for a conversation (at most two voices). */
344
+ input: string | SpeechTurn[];
345
+ /** One of the model's own voices, which `GET /v1/models` lists as `supported_voices`. */
346
+ voice?: string;
347
+ /** How to say it: a style direction. */
348
+ instructions?: string;
349
+ response_format?: 'mp3' | 'opus' | 'flac' | 'wav' | 'pcm';
350
+ speed?: number;
351
+ stream_format?: 'audio';
352
+ [field: string]: unknown;
353
+ };
354
+ /** What a speech answer billed, from its headers: text tokens in, audio tokens out, USD, and the audio's seconds. */
355
+ export type SpeechUsage = {
356
+ prompt_tokens?: number;
357
+ completion_tokens?: number;
358
+ cost?: number;
359
+ seconds?: number;
360
+ };
361
+ /** A speech answer: the audio and what it cost. `arrayBuffer()` gives the audio as an `ArrayBuffer`. */
362
+ export type SpeechAudio = WithRequestId & {
363
+ readonly content: Uint8Array;
364
+ readonly contentType: string | undefined;
365
+ readonly usage: SpeechUsage;
366
+ arrayBuffer(): Promise<ArrayBuffer>;
367
+ };
368
+ /**
369
+ * An image an edit starts from: a file (a `File`, `Blob`, `Response` or stream; `toFile` makes one from bytes), a link
370
+ * (an https link or a base64 data URL), or an `{ image_url }` object.
371
+ */
372
+ export type ImageInput = Uploadable | string | {
373
+ image_url: string | {
374
+ url: string;
375
+ };
376
+ [field: string]: unknown;
377
+ };
378
+ /** The fields `keln.images.generate` and `keln.images.edit` share, Keln's `aspect_ratio` and `resolution` among them. */
379
+ type ImageRequestBase = {
380
+ model: string;
381
+ prompt: string;
382
+ /** `auto`, `WIDTHxHEIGHT`, or a resolution such as `2K`. `GET /v1/models` lists a model's sizes in `supported_parameters`. */
383
+ size?: string;
384
+ /** Keln's: one of the model's aspect ratios, such as `16:9`. */
385
+ aspect_ratio?: string;
386
+ /** Keln's: one of the model's resolutions, such as `2K`. */
387
+ resolution?: string;
388
+ background?: 'transparent' | 'opaque' | 'auto';
389
+ complexity?: 'low' | 'medium' | 'high';
390
+ frame_count?: number;
391
+ frame_duration_ms?: number;
392
+ n?: number;
393
+ output_compression?: number;
394
+ partial_images?: number;
395
+ response_format?: 'url' | 'b64_json';
396
+ safety_identifier?: string;
397
+ stream?: boolean | null;
398
+ user?: string;
399
+ };
400
+ export type ImageGenerateParams = ImageRequestBase & {
401
+ moderation?: 'low' | 'auto';
402
+ output_format?: 'png' | 'jpeg' | 'webp' | 'gif' | 'svg';
403
+ quality?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto' | 'standard' | 'hd';
404
+ style?: 'vivid' | 'natural';
405
+ svg?: Record<string, unknown>;
406
+ [field: string]: unknown;
407
+ };
408
+ export type ImageEditParams = ImageRequestBase & {
409
+ /** One image or several. Files alone go as multipart; with a link, the edit goes as JSON. */
410
+ image: ImageInput | ImageInput[];
411
+ input_fidelity?: 'high' | 'low';
412
+ markup?: Uploadable;
413
+ mask?: Uploadable;
414
+ output_format?: 'png' | 'jpeg' | 'webp' | 'gif';
415
+ quality?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto' | 'standard';
416
+ [field: string]: unknown;
417
+ };
418
+ /** `usage` on an image answer: tokens in and out, and what the call billed. */
419
+ export type ImageUsage = {
420
+ input_tokens: number;
421
+ output_tokens: number;
422
+ total_tokens: number;
423
+ /** The prompt's tokens, and the tokens of the pictures sent. */
424
+ input_tokens_details?: {
425
+ text_tokens: number;
426
+ image_tokens: number;
427
+ [field: string]: unknown;
428
+ };
429
+ /** The picture's tokens, and the model's thinking and any words it wrote beside the picture. */
430
+ output_tokens_details?: {
431
+ image_tokens: number;
432
+ text_tokens: number;
433
+ [field: string]: unknown;
434
+ };
435
+ /** What the call billed, in USD. */
436
+ cost?: number;
437
+ [field: string]: unknown;
438
+ };
439
+ /** An image answer: the picture as base64 in `data[0].b64_json`, its size, format and usage. */
440
+ export type ImagesResponse = WithRequestId & {
441
+ created: number;
442
+ data: Array<{
443
+ b64_json: string;
444
+ media_type?: string;
445
+ [field: string]: unknown;
446
+ }>;
447
+ size?: string;
448
+ output_format?: string;
449
+ background?: string;
450
+ usage?: ImageUsage;
451
+ [field: string]: unknown;
452
+ };
453
+ /** The one event of a streamed image answer: `image_generation.completed`, or `image_edit.completed` on an edit. */
454
+ export type ImageStreamEvent = {
455
+ type: 'image_generation.completed' | 'image_edit.completed' | (string & {});
456
+ b64_json: string;
457
+ media_type?: string;
458
+ created_at?: number;
459
+ size?: string;
460
+ output_format?: string;
461
+ usage?: ImageUsage;
462
+ [field: string]: unknown;
463
+ };
464
+ /** One model of `GET /v1/models`. */
465
+ export type Model = {
466
+ /** The id a request names in `model`. */
467
+ id: string;
468
+ object: 'model';
469
+ owned_by: string;
470
+ /** A constant. It is not a date: `added` is. */
471
+ created: number;
472
+ /** Unix seconds: the date the catalog lists the model under. */
473
+ added?: number;
474
+ /** The context window in tokens, prompt and output together. Absent on transcription, speech and image models. */
475
+ context_length?: number;
476
+ /** What the model takes: `['text']`, `['text', 'image']`, or `['audio']` for a transcription model. */
477
+ input_modalities: string[];
478
+ /**
479
+ * What the model returns, and so the call that serves it: `text` (chat completions and responses), `embeddings`,
480
+ * `rerank`, `decisions`, `transcription`, `speech` or `image`.
481
+ */
482
+ output_modalities: string[];
483
+ /** On a model that thinks: whether thinking can be switched off, the levels it grades, and the one it runs by default. */
484
+ reasoning?: {
485
+ mandatory: boolean;
486
+ supported_efforts?: string[];
487
+ default_effort?: string;
488
+ [field: string]: unknown;
489
+ };
490
+ /**
491
+ * USD per unit, as strings. On a chat model, per token: `prompt`, `completion`, `input_cache_read`. A transcription
492
+ * model's `prompt` is per second of audio; a speech model's `completion` per audio token; an image model adds
493
+ * `image_output`, per image token out.
494
+ */
495
+ pricing: {
496
+ prompt: string;
497
+ completion: string;
498
+ input_cache_read?: string;
499
+ image_output?: string;
500
+ [field: string]: unknown;
501
+ };
502
+ /** On a speech model: the names its `voice` takes. */
503
+ supported_voices?: string[];
504
+ /** On an image model: what a request may ask of it, each field with its values. */
505
+ supported_parameters?: Record<string, unknown>;
506
+ /** Live speed: `tps_p50` output tokens per second, `ttft_p50_ms` milliseconds to the first token, as of `as_of`. */
507
+ performance?: {
508
+ tps_p50: number;
509
+ ttft_p50_ms?: number;
510
+ as_of: number;
511
+ [field: string]: unknown;
512
+ };
513
+ [field: string]: unknown;
514
+ };
515
+ /** `GET /v1/models`: every model a request can name. */
516
+ export type ModelList = WithRequestId & {
517
+ object: 'list';
518
+ data: Model[];
519
+ [field: string]: unknown;
520
+ };
521
+ /** `keln.models.list()`: await it for the list, or loop over it with `for await` for each model. */
522
+ export declare class ModelListPromise extends ApiPromise<ModelList> implements AsyncIterable<Model> {
523
+ [Symbol.asyncIterator](): AsyncIterator<Model>;
524
+ }
525
+ /** Little-endian 32-bit floats from base64: an embedding asked for as base64, handed back as numbers. */
526
+ export declare function toFloat32Array(base64Str: string): number[];
527
+ /** `keln.chat.completions`. */
528
+ export declare class Completions {
529
+ #private;
530
+ constructor(api: Api);
531
+ /**
532
+ * A chat completion, `POST /v1/chat/completions`, with Keln's `reasoning_effort`, `service_tier`,
533
+ * `web_search_options` and `code_execution`. With `stream: true`, a `Stream` of chunks: one that ends early with
534
+ * Keln's `stream_interrupted` chunk throws `KelnApiError` with that `code`.
535
+ */
536
+ create(body: ChatCompletionCreateParams & {
537
+ stream: true;
538
+ }, options?: InferenceCallOptions): ApiPromise<Stream<ChatCompletionChunk>>;
539
+ create(body: ChatCompletionCreateParams & {
540
+ stream?: false | null;
541
+ }, options?: InferenceCallOptions): ApiPromise<ChatCompletion>;
542
+ create(body: ChatCompletionCreateParams, options?: InferenceCallOptions): ApiPromise<ChatCompletion | Stream<ChatCompletionChunk>>;
543
+ }
544
+ /** `keln.chat`. */
545
+ export declare class Chat {
546
+ readonly completions: Completions;
547
+ constructor(api: Api);
548
+ }
549
+ /** `keln.responses`. */
550
+ export declare class Responses {
551
+ #private;
552
+ constructor(api: Api);
553
+ /**
554
+ * A response, `POST /v1/responses`, with Keln's `service_tier`. With `stream: true`, a `Stream` of its events. A
555
+ * failure after the stream started arrives as an `error` event and `response.failed`, which pass through to be read.
556
+ */
557
+ create(body: ResponseCreateParams & {
558
+ stream: true;
559
+ }, options?: InferenceCallOptions): ApiPromise<Stream<ResponseStreamEvent>>;
560
+ create(body: ResponseCreateParams & {
561
+ stream?: false | null;
562
+ }, options?: InferenceCallOptions): ApiPromise<Response>;
563
+ create(body: ResponseCreateParams, options?: InferenceCallOptions): ApiPromise<Response | Stream<ResponseStreamEvent>>;
564
+ }
565
+ /** `keln.embeddings`. */
566
+ export declare class Embeddings {
567
+ #private;
568
+ constructor(api: Api);
569
+ /**
570
+ * Embeddings, `POST /v1/embeddings`. Without `encoding_format` the SDK asks for base64, a quarter of the bytes, and
571
+ * hands back numbers; with one, the answer comes as the API sent it.
572
+ */
573
+ create(body: EmbeddingCreateParams, options?: InferenceCallOptions): ApiPromise<CreateEmbeddingResponse>;
574
+ }
575
+ /** `keln.rerank`. */
576
+ export declare class Rerank {
577
+ #private;
578
+ constructor(api: Api);
579
+ /** Documents ranked against `query`, `POST /v1/rerank`. */
580
+ create(body: RerankCreateParams, options?: InferenceCallOptions): ApiPromise<RerankResponse>;
581
+ }
582
+ /** `keln.decisions`. */
583
+ export declare class Decisions {
584
+ #private;
585
+ constructor(api: Api);
586
+ /** Typed answers about one `state`, `POST /v1/decisions`. */
587
+ create(body: DecisionCreateParams, options?: InferenceCallOptions): ApiPromise<DecisionResponse>;
588
+ }
589
+ /** `keln.audio.transcriptions`. */
590
+ export declare class Transcriptions {
591
+ #private;
592
+ constructor(api: Api);
593
+ /**
594
+ * Audio to text, `POST /v1/audio/transcriptions`, sent multipart, arrays as repeated `name[]` fields. `text`, `srt`
595
+ * and `vtt` answers come back as a string, every other format as an object with `text` and `usage` (`seconds`,
596
+ * `cost`). `diarize: true` in the body puts speakers on a `verbose_json` answer, and `keyterms` adds spelling hints
597
+ * as `keywords` does. The call's `signal` and `timeout` cover reading the file into memory too.
598
+ */
599
+ create(body: TranscriptionCreateParams & {
600
+ response_format: 'text' | 'srt' | 'vtt';
601
+ }, options?: InferenceCallOptions): ApiPromise<string>;
602
+ create(body: TranscriptionCreateParams & {
603
+ response_format: 'verbose_json';
604
+ }, options?: InferenceCallOptions): ApiPromise<TranscriptionVerbose>;
605
+ create(body: TranscriptionCreateParams & {
606
+ response_format: 'diarized_json';
607
+ }, options?: InferenceCallOptions): ApiPromise<TranscriptionDiarized>;
608
+ create(body: TranscriptionCreateParams & {
609
+ response_format?: 'json';
610
+ }, options?: InferenceCallOptions): ApiPromise<Transcription>;
611
+ }
612
+ /** `keln.audio.speech`. */
613
+ export declare class Speech {
614
+ #private;
615
+ constructor(api: Api);
616
+ /**
617
+ * Text to audio, `POST /v1/audio/speech`. `input` is the text, or a list of turns for a conversation. The answer is
618
+ * the audio (MP3 unless `response_format` says otherwise) with its usage and cost, read from the answer's headers.
619
+ */
620
+ create(body: SpeechCreateParams, options?: InferenceCallOptions): ApiPromise<SpeechAudio>;
621
+ }
622
+ /** `keln.audio`. */
623
+ export declare class Audio {
624
+ readonly transcriptions: Transcriptions;
625
+ readonly speech: Speech;
626
+ constructor(api: Api);
627
+ }
628
+ /** `keln.images`. */
629
+ export declare class Images {
630
+ #private;
631
+ constructor(api: Api);
632
+ /**
633
+ * A picture from a prompt, `POST /v1/images/generations`, with Keln's `aspect_ratio` and `resolution` beside
634
+ * `size`. The picture is `data[0].b64_json`, base64, beside its `media_type`, the answer's `size` and
635
+ * `output_format`, and `usage` (tokens and `cost`). With `stream: true`, a `Stream` of one `image_generation.completed`
636
+ * event with the same fields. A request the model's filter blocks throws `BadRequestError` with the code
637
+ * `moderation_blocked`.
638
+ */
639
+ generate(body: ImageGenerateParams & {
640
+ stream: true;
641
+ }, options?: InferenceCallOptions): ApiPromise<Stream<ImageStreamEvent>>;
642
+ generate(body: ImageGenerateParams & {
643
+ stream?: false | null;
644
+ }, options?: InferenceCallOptions): ApiPromise<ImagesResponse>;
645
+ generate(body: ImageGenerateParams, options?: InferenceCallOptions): ApiPromise<ImagesResponse | Stream<ImageStreamEvent>>;
646
+ /**
647
+ * Pictures changed by a prompt, `POST /v1/images/edits`, with the same answer as `generate`. `image` is one image or
648
+ * several: files (`File`, `Blob`, `Response` or a stream) go multipart, one as `image` and several as repeated
649
+ * `image[]`. With a link (an https link or a data URL) among them, the edit goes as JSON in `images`, each file as a
650
+ * data URL. Without a `size`, `aspect_ratio` or `resolution` the model follows the shape of the picture. With
651
+ * `stream: true`, a `Stream` of one `image_edit.completed` event. The call's `signal` and `timeout` cover reading the
652
+ * files into memory too.
653
+ */
654
+ edit(body: ImageEditParams & {
655
+ stream: true;
656
+ }, options?: InferenceCallOptions): ApiPromise<Stream<ImageStreamEvent>>;
657
+ edit(body: ImageEditParams & {
658
+ stream?: false | null;
659
+ }, options?: InferenceCallOptions): ApiPromise<ImagesResponse>;
660
+ edit(body: ImageEditParams, options?: InferenceCallOptions): ApiPromise<ImagesResponse | Stream<ImageStreamEvent>>;
661
+ }
662
+ /** `keln.models`. */
663
+ export declare class Models {
664
+ #private;
665
+ constructor(api: Api);
666
+ /**
667
+ * Every model a request can name, `GET /v1/models`: its context window, prices, what it takes and returns, and for
668
+ * some models their voices, sizes or thinking levels. Await it for the list, or loop over it with `for await`.
669
+ */
670
+ list(options?: InferenceCallOptions): ModelListPromise;
671
+ }
672
+ export {};