flexinference 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ Adds the **Messages** caller format (`client.messages.create`), the fourth format
6
+ alongside Responses, chat completions, and Interactions. It takes and returns the
7
+ Anthropic Messages shape and works for any model via the canonical Responses path,
8
+ posting to `/messages`. `max_tokens` is required (Anthropic requires it) and
9
+ `start_within` is required (same rule as the other formats); `service_tier` is a
10
+ compile-time error (the router owns the tier). New `messageText(obj)` helper pulls the
11
+ assistant text out of the response `content[]` blocks, where `outputText` and
12
+ `interactionText` return "". Also adds first-class Anthropic (`claude-*`) upstream
13
+ support behind the existing formats.
14
+
15
+ ## 1.1.0
16
+
17
+ Adds the **Interactions** caller format (`client.interactions.create`), the third format
18
+ alongside Responses and chat completions. It works for both OpenAI and Gemini models and
19
+ posts to `/interactions`. `start_within` is required (same rule as the other formats) and
20
+ `service_tier` is a compile-time error (the router owns the tier). New `interactionText(obj)`
21
+ helper pulls the assistant text out of the `steps[]` shape, where `outputText` returns "".
22
+
3
23
  ## 1.0.1
4
24
 
5
25
  Gemini now supports **image input** and **web search** (send a Responses `web_search`
package/dist/index.d.ts CHANGED
@@ -17,6 +17,16 @@ type RawChatRequest = Schemas["CreateChatCompletionRequest"];
17
17
  export type ChatCompletionCreateParams = WithStartWithin<Partial<RawChatRequest> & Required<Pick<RawChatRequest, "model" | "messages">>>;
18
18
  export type ChatCompletion = Schemas["CreateChatCompletionResponse"];
19
19
  export type ChatCompletionChunk = Schemas["CreateChatCompletionStreamResponse"];
20
+ export type InteractionCreateParams = WithStartWithin<Schemas["InteractionCreateParams"]> & {
21
+ service_tier?: never;
22
+ };
23
+ export type InteractionObject = Schemas["InteractionObject"];
24
+ export type InteractionStreamEvent = Schemas["InteractionStreamEvent"];
25
+ export type MessageCreateParams = WithStartWithin<Schemas["MessageCreateParams"]> & {
26
+ service_tier?: never;
27
+ };
28
+ export type MessageObject = Schemas["MessageObject"];
29
+ export type MessageStreamEvent = Schemas["MessageStreamEvent"];
20
30
  /**
21
31
  * Concatenate the assistant's text from a non-streamed response. Works on a Responses
22
32
  * object (walks `output[].content[]` for `output_text` parts) and on a chat completion
@@ -27,6 +37,23 @@ export type ChatCompletionChunk = Schemas["CreateChatCompletionStreamResponse"];
27
37
  * their `output_text.delta` events instead.
28
38
  */
29
39
  export declare function outputText(response: ResponseObject | ChatCompletion): string;
40
+ /**
41
+ * Concatenate the assistant's text from a non-streamed Interactions response. The text
42
+ * lives in `steps[]` of type `model_output`, each a `content[]` of `{type:"text",text}`
43
+ * parts (a different shape from Responses/chat, so `outputText` returns "" on it). Returns
44
+ * "" when there is no text (e.g. a function-call-only interaction). Read-only: nothing is
45
+ * reshaped. Streamed interactions are not objects; collect their `step.delta` text events.
46
+ */
47
+ export declare function interactionText(interaction: InteractionObject): string;
48
+ /**
49
+ * Concatenate the assistant's text from a non-streamed Messages response. The text lives
50
+ * in `content[]` as `{type:"text",text}` blocks (thinking and tool_use blocks are
51
+ * skipped) - the Anthropic Messages shape, a different layout from Responses/chat and
52
+ * Interactions, so `outputText` and `interactionText` return "" on it. Returns "" when
53
+ * there is no text (e.g. a tool_use-only response). Read-only: nothing is reshaped.
54
+ * Streamed messages are not objects; collect their `content_block_delta` text events.
55
+ */
56
+ export declare function messageText(message: MessageObject): string;
30
57
  export interface FlexErrorBody {
31
58
  error: {
32
59
  message: string;
@@ -65,6 +92,8 @@ type Post = (path: string, body: unknown, signal: AbortSignal | undefined) => Pr
65
92
  export declare class FlexInference {
66
93
  readonly responses: Responses;
67
94
  readonly chat: Chat;
95
+ readonly interactions: Interactions;
96
+ readonly messages: Messages;
68
97
  private readonly apiKey;
69
98
  private readonly baseURL;
70
99
  private readonly fetchImpl;
@@ -96,4 +125,24 @@ declare class ChatCompletions {
96
125
  stream: true;
97
126
  }, options?: RequestOptions): Promise<AsyncIterable<ChatCompletionChunk>>;
98
127
  }
128
+ declare class Interactions {
129
+ private readonly post;
130
+ constructor(post: Post);
131
+ create(body: InteractionCreateParams & {
132
+ stream?: false | null;
133
+ }, options?: RequestOptions): Promise<InteractionObject>;
134
+ create(body: InteractionCreateParams & {
135
+ stream: true;
136
+ }, options?: RequestOptions): Promise<AsyncIterable<InteractionStreamEvent>>;
137
+ }
138
+ declare class Messages {
139
+ private readonly post;
140
+ constructor(post: Post);
141
+ create(body: MessageCreateParams & {
142
+ stream?: false | null;
143
+ }, options?: RequestOptions): Promise<MessageObject>;
144
+ create(body: MessageCreateParams & {
145
+ stream: true;
146
+ }, options?: RequestOptions): Promise<AsyncIterable<MessageStreamEvent>>;
147
+ }
99
148
  export {};
package/dist/index.js CHANGED
@@ -36,6 +36,55 @@ export function outputText(response) {
36
36
  }
37
37
  return "";
38
38
  }
39
+ /**
40
+ * Concatenate the assistant's text from a non-streamed Interactions response. The text
41
+ * lives in `steps[]` of type `model_output`, each a `content[]` of `{type:"text",text}`
42
+ * parts (a different shape from Responses/chat, so `outputText` returns "" on it). Returns
43
+ * "" when there is no text (e.g. a function-call-only interaction). Read-only: nothing is
44
+ * reshaped. Streamed interactions are not objects; collect their `step.delta` text events.
45
+ */
46
+ export function interactionText(interaction) {
47
+ const obj = interaction;
48
+ if (!isRecord(obj))
49
+ return "";
50
+ const steps = obj.steps;
51
+ if (!Array.isArray(steps))
52
+ return "";
53
+ let text = "";
54
+ for (const step of steps) {
55
+ if (!isRecord(step) || step.type !== "model_output" || !Array.isArray(step.content))
56
+ continue;
57
+ for (const part of step.content) {
58
+ if (isRecord(part) && part.type === "text" && typeof part.text === "string") {
59
+ text += part.text;
60
+ }
61
+ }
62
+ }
63
+ return text;
64
+ }
65
+ /**
66
+ * Concatenate the assistant's text from a non-streamed Messages response. The text lives
67
+ * in `content[]` as `{type:"text",text}` blocks (thinking and tool_use blocks are
68
+ * skipped) - the Anthropic Messages shape, a different layout from Responses/chat and
69
+ * Interactions, so `outputText` and `interactionText` return "" on it. Returns "" when
70
+ * there is no text (e.g. a tool_use-only response). Read-only: nothing is reshaped.
71
+ * Streamed messages are not objects; collect their `content_block_delta` text events.
72
+ */
73
+ export function messageText(message) {
74
+ const obj = message;
75
+ if (!isRecord(obj))
76
+ return "";
77
+ const content = obj.content;
78
+ if (!Array.isArray(content))
79
+ return "";
80
+ let text = "";
81
+ for (const block of content) {
82
+ if (isRecord(block) && block.type === "text" && typeof block.text === "string") {
83
+ text += block.text;
84
+ }
85
+ }
86
+ return text;
87
+ }
39
88
  export class FlexInferenceError extends Error {
40
89
  status;
41
90
  type;
@@ -87,6 +136,8 @@ function assertStartWithin(body) {
87
136
  export class FlexInference {
88
137
  responses;
89
138
  chat;
139
+ interactions;
140
+ messages;
90
141
  apiKey;
91
142
  baseURL;
92
143
  fetchImpl;
@@ -105,6 +156,8 @@ export class FlexInference {
105
156
  const post = (path, body, signal) => this.post(path, body, signal);
106
157
  this.responses = new Responses(post);
107
158
  this.chat = new Chat(post);
159
+ this.interactions = new Interactions(post);
160
+ this.messages = new Messages(post);
108
161
  }
109
162
  async post(path, body, signal) {
110
163
  // One AbortController fed by three sources: the caller's signal, a 10s connect
@@ -214,6 +267,44 @@ class ChatCompletions {
214
267
  }
215
268
  }
216
269
  }
270
+ class Interactions {
271
+ post;
272
+ constructor(post) {
273
+ this.post = post;
274
+ }
275
+ async create(body, options) {
276
+ assertStartWithin(body);
277
+ const { res, cleanup } = await this.post("/interactions", body, options?.signal);
278
+ if (body.stream) {
279
+ return streamSSE(res, cleanup);
280
+ }
281
+ try {
282
+ return (await res.json());
283
+ }
284
+ finally {
285
+ cleanup();
286
+ }
287
+ }
288
+ }
289
+ class Messages {
290
+ post;
291
+ constructor(post) {
292
+ this.post = post;
293
+ }
294
+ async create(body, options) {
295
+ assertStartWithin(body);
296
+ const { res, cleanup } = await this.post("/messages", body, options?.signal);
297
+ if (body.stream) {
298
+ return streamSSE(res, cleanup);
299
+ }
300
+ try {
301
+ return (await res.json());
302
+ }
303
+ finally {
304
+ cleanup();
305
+ }
306
+ }
307
+ }
217
308
  async function* streamSSE(res, cleanup) {
218
309
  if (!res.body) {
219
310
  cleanup();
package/dist/types.d.ts CHANGED
@@ -64,6 +64,40 @@ export interface paths {
64
64
  patch?: never;
65
65
  trace?: never;
66
66
  };
67
+ "/interactions": {
68
+ parameters: {
69
+ query?: never;
70
+ header?: never;
71
+ path?: never;
72
+ cookie?: never;
73
+ };
74
+ get?: never;
75
+ put?: never;
76
+ /** Create an interaction. The third FlexInference caller format; works for OpenAI and Gemini models via the canonical Responses path. Send start_within and do not send service_tier. */
77
+ post: operations["createInteraction"];
78
+ delete?: never;
79
+ options?: never;
80
+ head?: never;
81
+ patch?: never;
82
+ trace?: never;
83
+ };
84
+ "/messages": {
85
+ parameters: {
86
+ query?: never;
87
+ header?: never;
88
+ path?: never;
89
+ cookie?: never;
90
+ };
91
+ get?: never;
92
+ put?: never;
93
+ /** Create a message. The fourth FlexInference caller format (Anthropic Messages shape in and out); works for any model via the canonical Responses path. Send start_within and do not send service_tier. max_tokens is required. */
94
+ post: operations["createMessage"];
95
+ delete?: never;
96
+ options?: never;
97
+ head?: never;
98
+ patch?: never;
99
+ trace?: never;
100
+ };
67
101
  }
68
102
  export type webhooks = Record<string, never>;
69
103
  export interface components {
@@ -1105,7 +1139,7 @@ export interface components {
1105
1139
  */
1106
1140
  top_logprobs?: number;
1107
1141
  /**
1108
- * @description FlexInference deadline control. Required on every request. "default", "priority", and "auto" map to those OpenAI service tiers ("auto" lets OpenAI pick) and proxy any model. A duration "HHh-MMm-SSs" between 5 seconds and 10 minutes runs the flex tier on a flex-capable model and automatically falls back to standard if it has not started within the window. The retired value "standard" is no longer accepted (use "default").
1142
+ * @description FlexInference deadline control. Required on every request. "default" maps to the provider's standard real-time tier (OpenAI "default", Gemini "standard"), "priority" to the provider's priority tier, and "auto" to OpenAI's auto tier (OpenAI only; Gemini has no auto tier). These proxy any model. A duration "HHh-MMm-SSs" between 5 seconds and 10 minutes runs the provider's flex tier (OpenAI or Gemini) on a flex-capable model and automatically falls back to standard if it has not started within the window. Do not send service_tier (the router controls the tier). The retired value "standard" is no longer accepted (use "default").
1109
1143
  * @example 00h-00m-30s
1110
1144
  */
1111
1145
  start_within?: string;
@@ -5366,6 +5400,579 @@ export interface components {
5366
5400
  param?: string | null;
5367
5401
  };
5368
5402
  };
5403
+ /** Interaction Text Part */
5404
+ InteractionTextPart: {
5405
+ /** @constant */
5406
+ type: "text";
5407
+ text: string;
5408
+ };
5409
+ /** Interaction Image Part */
5410
+ InteractionImagePart: {
5411
+ /** @constant */
5412
+ type: "image";
5413
+ mime_type: string;
5414
+ /** @description Base64-encoded image bytes. */
5415
+ data: string;
5416
+ };
5417
+ /** Interaction Document Part */
5418
+ InteractionDocumentPart: {
5419
+ /** @constant */
5420
+ type: "document";
5421
+ mime_type: string;
5422
+ /** @description Base64-encoded document bytes. */
5423
+ data: string;
5424
+ };
5425
+ /**
5426
+ * Interaction Content Part
5427
+ * @description A single piece of multimodal content in an Interactions request.
5428
+ */
5429
+ InteractionContentPart: components["schemas"]["InteractionTextPart"] | components["schemas"]["InteractionImagePart"] | components["schemas"]["InteractionDocumentPart"];
5430
+ /** Interaction User Input Step */
5431
+ InteractionUserInputStep: {
5432
+ /** @constant */
5433
+ type: "user_input";
5434
+ content: components["schemas"]["InteractionContentPart"][];
5435
+ };
5436
+ /** Interaction Model Output Step */
5437
+ InteractionModelOutputStep: {
5438
+ /** @constant */
5439
+ type: "model_output";
5440
+ content: components["schemas"]["InteractionContentPart"][];
5441
+ };
5442
+ /** Interaction Function Call Step */
5443
+ InteractionFunctionCallStep: {
5444
+ /** @constant */
5445
+ type: "function_call";
5446
+ id?: string;
5447
+ name: string;
5448
+ /** @description Parsed function arguments object (not a JSON string). */
5449
+ arguments: {
5450
+ [key: string]: unknown;
5451
+ };
5452
+ };
5453
+ /** Interaction Function Result Step */
5454
+ InteractionFunctionResultStep: {
5455
+ /** @constant */
5456
+ type: "function_result";
5457
+ name: string;
5458
+ /** @description Tool result payload; any JSON value. */
5459
+ result: unknown;
5460
+ };
5461
+ /**
5462
+ * Interaction Step
5463
+ * @description One turn in a multi-turn Interactions request (a step list).
5464
+ */
5465
+ InteractionStep: components["schemas"]["InteractionUserInputStep"] | components["schemas"]["InteractionModelOutputStep"] | components["schemas"]["InteractionFunctionCallStep"] | components["schemas"]["InteractionFunctionResultStep"];
5466
+ /** Interaction Function Tool */
5467
+ InteractionFunctionTool: {
5468
+ /** @constant */
5469
+ type: "function";
5470
+ name: string;
5471
+ description?: string;
5472
+ /** @description JSON Schema for the function parameters. */
5473
+ parameters?: {
5474
+ [key: string]: unknown;
5475
+ };
5476
+ };
5477
+ /** Interaction Google Search Tool */
5478
+ InteractionGoogleSearchTool: {
5479
+ /** @constant */
5480
+ type: "google_search";
5481
+ };
5482
+ /** Interaction Tool */
5483
+ InteractionTool: components["schemas"]["InteractionFunctionTool"] | components["schemas"]["InteractionGoogleSearchTool"];
5484
+ /**
5485
+ * Interaction Generation Config
5486
+ * @description Generation controls. thinking_level maps to canonical reasoning.effort.
5487
+ */
5488
+ InteractionGenerationConfig: {
5489
+ max_output_tokens?: number;
5490
+ temperature?: number;
5491
+ top_p?: number;
5492
+ /** @enum {string} */
5493
+ thinking_level?: "minimal" | "low" | "medium" | "high";
5494
+ /** @description auto, none, or any. "any" maps to canonical tool_choice "required". */
5495
+ tool_choice?: string;
5496
+ };
5497
+ /**
5498
+ * Interaction Create Params
5499
+ * @description Request body for POST /v1/interactions. Works for both OpenAI and Gemini models via the canonical Responses path. Does not accept service_tier (the router owns the tier). start_within is required at runtime but left optional here.
5500
+ */
5501
+ InteractionCreateParams: {
5502
+ model: string;
5503
+ /** @description A prompt string, a content-part array (one turn), or a step list (multi-turn). */
5504
+ input?: string | components["schemas"]["InteractionContentPart"][] | components["schemas"]["InteractionStep"][];
5505
+ /** @description System instruction as a string or a content-part array. */
5506
+ system_instruction?: string | components["schemas"]["InteractionContentPart"][];
5507
+ tools?: components["schemas"]["InteractionTool"][];
5508
+ /** @description Inline JSON schema, mapped to canonical text.format.json_schema. */
5509
+ response_format?: {
5510
+ [key: string]: unknown;
5511
+ };
5512
+ generation_config?: components["schemas"]["InteractionGenerationConfig"];
5513
+ previous_interaction_id?: string;
5514
+ stream?: boolean;
5515
+ background?: boolean;
5516
+ store?: boolean;
5517
+ /** @description FlexInference deadline control (see the Responses/Chat ops). Required on every request; enforced by the router at runtime, not by this schema. */
5518
+ start_within?: string;
5519
+ } & {
5520
+ [key: string]: unknown;
5521
+ };
5522
+ /** Interaction Usage */
5523
+ InteractionUsage: {
5524
+ total_input_tokens?: number;
5525
+ total_output_tokens?: number;
5526
+ total_thought_tokens?: number;
5527
+ total_cached_tokens?: number;
5528
+ total_tokens?: number;
5529
+ total_tool_use_tokens?: number;
5530
+ };
5531
+ /**
5532
+ * Interaction Text Annotation
5533
+ * @description An opaque annotation on emitted text (e.g. a web-search citation).
5534
+ */
5535
+ InteractionTextAnnotation: {
5536
+ [key: string]: unknown;
5537
+ };
5538
+ /** Interaction Response Text Content */
5539
+ InteractionResponseTextContent: {
5540
+ /** @constant */
5541
+ type: "text";
5542
+ text: string;
5543
+ annotations?: components["schemas"]["InteractionTextAnnotation"][];
5544
+ };
5545
+ /** Interaction Model Output Response Step */
5546
+ InteractionModelOutputResponseStep: {
5547
+ /** @constant */
5548
+ type: "model_output";
5549
+ content: components["schemas"]["InteractionResponseTextContent"][];
5550
+ };
5551
+ /** Interaction Function Call Response Step */
5552
+ InteractionFunctionCallResponseStep: {
5553
+ /** @constant */
5554
+ type: "function_call";
5555
+ id?: string;
5556
+ name: string;
5557
+ arguments: {
5558
+ [key: string]: unknown;
5559
+ };
5560
+ };
5561
+ /** Interaction Google Search Call Step */
5562
+ InteractionGoogleSearchCallStep: {
5563
+ /** @constant */
5564
+ type: "google_search_call";
5565
+ id: string;
5566
+ };
5567
+ /** Interaction Response Step */
5568
+ InteractionResponseStep: components["schemas"]["InteractionModelOutputResponseStep"] | components["schemas"]["InteractionFunctionCallResponseStep"] | components["schemas"]["InteractionGoogleSearchCallStep"];
5569
+ /**
5570
+ * Interaction Object
5571
+ * @description Non-stream response from POST /v1/interactions.
5572
+ */
5573
+ InteractionObject: {
5574
+ id: string;
5575
+ /** @constant */
5576
+ object: "interaction";
5577
+ /** @enum {string} */
5578
+ status: "completed" | "requires_action" | "incomplete" | "failed";
5579
+ model: string;
5580
+ created?: number;
5581
+ updated?: number;
5582
+ service_tier?: string;
5583
+ usage?: components["schemas"]["InteractionUsage"];
5584
+ steps: components["schemas"]["InteractionResponseStep"][];
5585
+ };
5586
+ /**
5587
+ * Interaction Stream Snapshot
5588
+ * @description Interaction state carried by created and completed stream events.
5589
+ */
5590
+ InteractionStreamSnapshot: {
5591
+ id: string;
5592
+ status: string;
5593
+ /** @constant */
5594
+ object: "interaction";
5595
+ model: string;
5596
+ usage?: components["schemas"]["InteractionUsage"];
5597
+ } & {
5598
+ [key: string]: unknown;
5599
+ };
5600
+ /**
5601
+ * Interaction Stream Step
5602
+ * @description The step descriptor on a step.start event.
5603
+ */
5604
+ InteractionStreamStep: {
5605
+ /** @enum {string} */
5606
+ type: "model_output" | "function_call" | "google_search_call";
5607
+ id?: string;
5608
+ name?: string;
5609
+ };
5610
+ /**
5611
+ * Interaction Stream Delta
5612
+ * @description The incremental payload on a step.delta event.
5613
+ */
5614
+ InteractionStreamDelta: {
5615
+ /** @enum {string} */
5616
+ type?: "text" | "arguments_delta";
5617
+ text?: string;
5618
+ arguments?: string;
5619
+ annotations?: components["schemas"]["InteractionTextAnnotation"][];
5620
+ };
5621
+ /** Interaction Created Event */
5622
+ InteractionCreatedEvent: {
5623
+ /**
5624
+ * @description discriminator enum property added by openapi-typescript
5625
+ * @enum {string}
5626
+ */
5627
+ event_type: "interaction.created";
5628
+ interaction: components["schemas"]["InteractionStreamSnapshot"];
5629
+ };
5630
+ /** Interaction Status Update Event */
5631
+ InteractionStatusUpdateEvent: {
5632
+ /**
5633
+ * @description discriminator enum property added by openapi-typescript
5634
+ * @enum {string}
5635
+ */
5636
+ event_type: "interaction.status_update";
5637
+ interaction_id: string;
5638
+ status: string;
5639
+ };
5640
+ /** Interaction Completed Event */
5641
+ InteractionCompletedEvent: {
5642
+ /**
5643
+ * @description discriminator enum property added by openapi-typescript
5644
+ * @enum {string}
5645
+ */
5646
+ event_type: "interaction.completed";
5647
+ interaction: components["schemas"]["InteractionStreamSnapshot"];
5648
+ };
5649
+ /** Interaction Step Start Event */
5650
+ InteractionStepStartEvent: {
5651
+ /**
5652
+ * @description discriminator enum property added by openapi-typescript
5653
+ * @enum {string}
5654
+ */
5655
+ event_type: "step.start";
5656
+ index: number;
5657
+ step: components["schemas"]["InteractionStreamStep"];
5658
+ };
5659
+ /** Interaction Step Delta Event */
5660
+ InteractionStepDeltaEvent: {
5661
+ /**
5662
+ * @description discriminator enum property added by openapi-typescript
5663
+ * @enum {string}
5664
+ */
5665
+ event_type: "step.delta";
5666
+ index: number;
5667
+ delta: components["schemas"]["InteractionStreamDelta"];
5668
+ };
5669
+ /** Interaction Step Stop Event */
5670
+ InteractionStepStopEvent: {
5671
+ /**
5672
+ * @description discriminator enum property added by openapi-typescript
5673
+ * @enum {string}
5674
+ */
5675
+ event_type: "step.stop";
5676
+ index: number;
5677
+ };
5678
+ /** Interaction Error Event */
5679
+ InteractionErrorEvent: {
5680
+ /**
5681
+ * @description discriminator enum property added by openapi-typescript
5682
+ * @enum {string}
5683
+ */
5684
+ event_type: "error";
5685
+ /** @description Error payload (mirrors the FlexError error object). */
5686
+ error: {
5687
+ [key: string]: unknown;
5688
+ };
5689
+ };
5690
+ /**
5691
+ * Interaction Stream Event
5692
+ * @description One server-sent event frame on the Interactions stream.
5693
+ */
5694
+ InteractionStreamEvent: components["schemas"]["InteractionCreatedEvent"] | components["schemas"]["InteractionStatusUpdateEvent"] | components["schemas"]["InteractionCompletedEvent"] | components["schemas"]["InteractionStepStartEvent"] | components["schemas"]["InteractionStepDeltaEvent"] | components["schemas"]["InteractionStepStopEvent"] | components["schemas"]["InteractionErrorEvent"];
5695
+ /** Message Text Block */
5696
+ MessageTextBlock: {
5697
+ /** @constant */
5698
+ type: "text";
5699
+ text: string;
5700
+ };
5701
+ /**
5702
+ * Message Image Source
5703
+ * @description An image source, either base64-encoded bytes or a URL.
5704
+ */
5705
+ MessageImageSource: {
5706
+ /** @enum {string} */
5707
+ type: "base64" | "url";
5708
+ media_type?: string;
5709
+ /** @description Base64-encoded image bytes (type base64). */
5710
+ data?: string;
5711
+ /** @description Image URL (type url). */
5712
+ url?: string;
5713
+ };
5714
+ /** Message Image Block */
5715
+ MessageImageBlock: {
5716
+ /** @constant */
5717
+ type: "image";
5718
+ source: components["schemas"]["MessageImageSource"];
5719
+ };
5720
+ /** Message Thinking Block */
5721
+ MessageThinkingBlock: {
5722
+ /** @constant */
5723
+ type: "thinking";
5724
+ thinking: string;
5725
+ signature?: string;
5726
+ };
5727
+ /** Message Tool Use Block */
5728
+ MessageToolUseBlock: {
5729
+ /** @constant */
5730
+ type: "tool_use";
5731
+ id: string;
5732
+ name: string;
5733
+ /** @description Parsed tool input object (not a JSON string). */
5734
+ input: {
5735
+ [key: string]: unknown;
5736
+ };
5737
+ };
5738
+ /**
5739
+ * Message Tool Result Content Block
5740
+ * @description A single content block inside a tool_result (text or image).
5741
+ */
5742
+ MessageToolResultContentBlock: components["schemas"]["MessageTextBlock"] | components["schemas"]["MessageImageBlock"];
5743
+ /** Message Tool Result Block */
5744
+ MessageToolResultBlock: {
5745
+ /** @constant */
5746
+ type: "tool_result";
5747
+ tool_use_id: string;
5748
+ /** @description Tool result payload; a string or an array of content blocks. */
5749
+ content?: string | components["schemas"]["MessageToolResultContentBlock"][];
5750
+ };
5751
+ /**
5752
+ * Message Content Block
5753
+ * @description A single piece of multimodal content in a Messages request.
5754
+ */
5755
+ MessageContentBlock: components["schemas"]["MessageTextBlock"] | components["schemas"]["MessageImageBlock"] | components["schemas"]["MessageThinkingBlock"] | components["schemas"]["MessageToolUseBlock"] | components["schemas"]["MessageToolResultBlock"];
5756
+ /**
5757
+ * Message
5758
+ * @description One turn in a Messages conversation.
5759
+ */
5760
+ Message: {
5761
+ /** @enum {string} */
5762
+ role: "user" | "assistant";
5763
+ /** @description The turn content as a string or an array of content blocks. */
5764
+ content: string | components["schemas"]["MessageContentBlock"][];
5765
+ };
5766
+ /** Message Tool */
5767
+ MessageTool: {
5768
+ name: string;
5769
+ description?: string;
5770
+ /** @description JSON Schema for the tool input. */
5771
+ input_schema: {
5772
+ [key: string]: unknown;
5773
+ };
5774
+ };
5775
+ /** Message Tool Choice */
5776
+ MessageToolChoice: {
5777
+ /** @enum {string} */
5778
+ type: "auto" | "any" | "tool";
5779
+ /** @description Required when type is tool. */
5780
+ name?: string;
5781
+ };
5782
+ /**
5783
+ * Message Thinking Config
5784
+ * @description Extended thinking controls. "adaptive" lets the model choose the budget; "enabled" requires budget_tokens. display "summarized" surfaces reasoning text.
5785
+ */
5786
+ MessageThinkingConfig: {
5787
+ /** @enum {string} */
5788
+ type: "adaptive" | "enabled";
5789
+ /** @description Required when type is enabled; must be >= 1024 and less than max_tokens. */
5790
+ budget_tokens?: number;
5791
+ display?: string;
5792
+ };
5793
+ /**
5794
+ * Message Create Params
5795
+ * @description Request body for POST /v1/messages (Anthropic Messages shape). Works for any model via the canonical Responses path. max_tokens is required (Anthropic requires it and the router rejects a claude-* request that reaches the Anthropic upstream without a canonical max_output_tokens). Does not accept service_tier (the router owns the tier). start_within is required at runtime but left optional here.
5796
+ */
5797
+ MessageCreateParams: {
5798
+ model: string;
5799
+ max_tokens: number;
5800
+ /** @description System prompt as a string or an array of text blocks. */
5801
+ system?: string | components["schemas"]["MessageTextBlock"][];
5802
+ messages: components["schemas"]["Message"][];
5803
+ temperature?: number;
5804
+ top_p?: number;
5805
+ tools?: components["schemas"]["MessageTool"][];
5806
+ tool_choice?: components["schemas"]["MessageToolChoice"];
5807
+ thinking?: components["schemas"]["MessageThinkingConfig"];
5808
+ stream?: boolean;
5809
+ /** @description FlexInference deadline control (see the Responses/Chat ops). Required on every request; enforced by the router at runtime, not by this schema. */
5810
+ start_within?: string;
5811
+ } & {
5812
+ [key: string]: unknown;
5813
+ };
5814
+ /** Message Cache Creation */
5815
+ MessageCacheCreation: {
5816
+ ephemeral_5m_input_tokens?: number;
5817
+ ephemeral_1h_input_tokens?: number;
5818
+ };
5819
+ /** Message Usage Output Tokens Details */
5820
+ MessageUsageOutputTokensDetails: {
5821
+ thinking_tokens?: number;
5822
+ };
5823
+ /**
5824
+ * Message Usage
5825
+ * @description Anthropic usage. input_tokens EXCLUDES cache; output_tokens INCLUDES thinking. The router folds cache_read/cache_creation into canonical input and keeps output_tokens verbatim. service_tier here is authoritative for the served tier.
5826
+ */
5827
+ MessageUsage: {
5828
+ input_tokens?: number;
5829
+ cache_creation_input_tokens?: number | null;
5830
+ cache_read_input_tokens?: number | null;
5831
+ cache_creation?: components["schemas"]["MessageCacheCreation"];
5832
+ output_tokens?: number;
5833
+ output_tokens_details?: components["schemas"]["MessageUsageOutputTokensDetails"];
5834
+ service_tier?: string;
5835
+ inference_geo?: string;
5836
+ } & {
5837
+ [key: string]: unknown;
5838
+ };
5839
+ /**
5840
+ * Message Response Content Block
5841
+ * @description A content block on a Messages response (text, thinking, or tool_use).
5842
+ */
5843
+ MessageResponseContentBlock: components["schemas"]["MessageTextBlock"] | components["schemas"]["MessageThinkingBlock"] | components["schemas"]["MessageToolUseBlock"];
5844
+ /**
5845
+ * Message Object
5846
+ * @description Non-stream response from POST /v1/messages (Anthropic Messages shape).
5847
+ */
5848
+ MessageObject: {
5849
+ id: string;
5850
+ /** @constant */
5851
+ type: "message";
5852
+ /** @constant */
5853
+ role: "assistant";
5854
+ model: string;
5855
+ content: components["schemas"]["MessageResponseContentBlock"][];
5856
+ /** @enum {string|null} */
5857
+ stop_reason?: "end_turn" | "max_tokens" | "tool_use" | "stop_sequence" | "refusal" | null;
5858
+ stop_sequence?: string | null;
5859
+ /** @description The served tier, authoritative from usage.service_tier. Anthropic serves "standard" even when sent "standard_only". */
5860
+ service_tier?: string;
5861
+ usage?: components["schemas"]["MessageUsage"];
5862
+ };
5863
+ /**
5864
+ * Message Stream Content Block
5865
+ * @description The content block descriptor on a content_block_start event.
5866
+ */
5867
+ MessageStreamContentBlock: {
5868
+ type: string;
5869
+ } & {
5870
+ [key: string]: unknown;
5871
+ };
5872
+ /**
5873
+ * Message Stream Delta
5874
+ * @description The incremental payload on a content_block_delta event.
5875
+ */
5876
+ MessageStreamDelta: {
5877
+ /** @enum {string} */
5878
+ type: "text_delta" | "thinking_delta" | "input_json_delta" | "signature_delta";
5879
+ text?: string;
5880
+ thinking?: string;
5881
+ partial_json?: string;
5882
+ signature?: string;
5883
+ };
5884
+ /**
5885
+ * Message Delta Stop Info
5886
+ * @description The stop info carried by a message_delta event.
5887
+ */
5888
+ MessageDeltaStopInfo: {
5889
+ stop_reason?: string | null;
5890
+ stop_sequence?: string | null;
5891
+ };
5892
+ /** Message Start Event */
5893
+ MessageStartEvent: {
5894
+ /**
5895
+ * @description discriminator enum property added by openapi-typescript
5896
+ * @enum {string}
5897
+ */
5898
+ type: "message_start";
5899
+ message: components["schemas"]["MessageObject"];
5900
+ };
5901
+ /** Message Content Block Start Event */
5902
+ MessageContentBlockStartEvent: {
5903
+ /**
5904
+ * @description discriminator enum property added by openapi-typescript
5905
+ * @enum {string}
5906
+ */
5907
+ type: "content_block_start";
5908
+ index: number;
5909
+ content_block: components["schemas"]["MessageStreamContentBlock"];
5910
+ };
5911
+ /** Message Content Block Delta Event */
5912
+ MessageContentBlockDeltaEvent: {
5913
+ /**
5914
+ * @description discriminator enum property added by openapi-typescript
5915
+ * @enum {string}
5916
+ */
5917
+ type: "content_block_delta";
5918
+ index: number;
5919
+ delta: components["schemas"]["MessageStreamDelta"];
5920
+ };
5921
+ /** Message Content Block Stop Event */
5922
+ MessageContentBlockStopEvent: {
5923
+ /**
5924
+ * @description discriminator enum property added by openapi-typescript
5925
+ * @enum {string}
5926
+ */
5927
+ type: "content_block_stop";
5928
+ index: number;
5929
+ };
5930
+ /** Message Delta Event */
5931
+ MessageDeltaEvent: {
5932
+ /**
5933
+ * @description discriminator enum property added by openapi-typescript
5934
+ * @enum {string}
5935
+ */
5936
+ type: "message_delta";
5937
+ delta: components["schemas"]["MessageDeltaStopInfo"];
5938
+ usage?: components["schemas"]["MessageUsage"];
5939
+ };
5940
+ /** Message Stop Event */
5941
+ MessageStopEvent: {
5942
+ /**
5943
+ * @description discriminator enum property added by openapi-typescript
5944
+ * @enum {string}
5945
+ */
5946
+ type: "message_stop";
5947
+ };
5948
+ /** Message Ping Event */
5949
+ MessagePingEvent: {
5950
+ /**
5951
+ * @description discriminator enum property added by openapi-typescript
5952
+ * @enum {string}
5953
+ */
5954
+ type: "ping";
5955
+ };
5956
+ /**
5957
+ * Message Error Event
5958
+ * @description Terminal error frame emitted when the upstream stream fails.
5959
+ */
5960
+ MessageErrorEvent: {
5961
+ /**
5962
+ * @description discriminator enum property added by openapi-typescript
5963
+ * @enum {string}
5964
+ */
5965
+ type: "error";
5966
+ error: {
5967
+ type?: string;
5968
+ message?: string;
5969
+ };
5970
+ };
5971
+ /**
5972
+ * Message Stream Event
5973
+ * @description One server-sent event frame on the Messages stream.
5974
+ */
5975
+ MessageStreamEvent: components["schemas"]["MessageStartEvent"] | components["schemas"]["MessageContentBlockStartEvent"] | components["schemas"]["MessageContentBlockDeltaEvent"] | components["schemas"]["MessageContentBlockStopEvent"] | components["schemas"]["MessageDeltaEvent"] | components["schemas"]["MessageStopEvent"] | components["schemas"]["MessagePingEvent"] | components["schemas"]["MessageErrorEvent"];
5369
5976
  };
5370
5977
  responses: never;
5371
5978
  parameters: never;
@@ -5398,7 +6005,7 @@ export interface operations {
5398
6005
  "text/event-stream": components["schemas"]["CreateChatCompletionStreamResponse"];
5399
6006
  };
5400
6007
  };
5401
- /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, no_byok_key) or an OpenAI rejection passed through unchanged. */
6008
+ /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, no_byok_key, no_gemini_key, auto_unsupported_for_gemini, service_tier_not_allowed) or an OpenAI/Gemini rejection passed through unchanged. */
5402
6009
  400: {
5403
6010
  headers: {
5404
6011
  [name: string]: unknown;
@@ -5441,7 +6048,93 @@ export interface operations {
5441
6048
  "text/event-stream": components["schemas"]["ResponseStreamEvent"];
5442
6049
  };
5443
6050
  };
5444
- /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, no_byok_key) or an OpenAI rejection passed through unchanged. */
6051
+ /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, no_byok_key, no_gemini_key, auto_unsupported_for_gemini, service_tier_not_allowed) or an OpenAI/Gemini rejection passed through unchanged. */
6052
+ 400: {
6053
+ headers: {
6054
+ [name: string]: unknown;
6055
+ };
6056
+ content: {
6057
+ "application/json": components["schemas"]["FlexError"];
6058
+ };
6059
+ };
6060
+ /** @description Invalid or missing FlexInference API key (type flexinference_error, code invalid_api_key). */
6061
+ 401: {
6062
+ headers: {
6063
+ [name: string]: unknown;
6064
+ };
6065
+ content: {
6066
+ "application/json": components["schemas"]["FlexError"];
6067
+ };
6068
+ };
6069
+ };
6070
+ };
6071
+ createInteraction: {
6072
+ parameters: {
6073
+ query?: never;
6074
+ header?: never;
6075
+ path?: never;
6076
+ cookie?: never;
6077
+ };
6078
+ requestBody: {
6079
+ content: {
6080
+ "application/json": components["schemas"]["InteractionCreateParams"];
6081
+ };
6082
+ };
6083
+ responses: {
6084
+ /** @description OK */
6085
+ 200: {
6086
+ headers: {
6087
+ [name: string]: unknown;
6088
+ };
6089
+ content: {
6090
+ "application/json": components["schemas"]["InteractionObject"];
6091
+ "text/event-stream": components["schemas"]["InteractionStreamEvent"];
6092
+ };
6093
+ };
6094
+ /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, auto_unsupported_for_gemini, service_tier_not_allowed) or an OpenAI/Gemini rejection passed through unchanged. */
6095
+ 400: {
6096
+ headers: {
6097
+ [name: string]: unknown;
6098
+ };
6099
+ content: {
6100
+ "application/json": components["schemas"]["FlexError"];
6101
+ };
6102
+ };
6103
+ /** @description Invalid or missing FlexInference API key (type flexinference_error, code invalid_api_key). */
6104
+ 401: {
6105
+ headers: {
6106
+ [name: string]: unknown;
6107
+ };
6108
+ content: {
6109
+ "application/json": components["schemas"]["FlexError"];
6110
+ };
6111
+ };
6112
+ };
6113
+ };
6114
+ createMessage: {
6115
+ parameters: {
6116
+ query?: never;
6117
+ header?: never;
6118
+ path?: never;
6119
+ cookie?: never;
6120
+ };
6121
+ requestBody: {
6122
+ content: {
6123
+ "application/json": components["schemas"]["MessageCreateParams"];
6124
+ };
6125
+ };
6126
+ responses: {
6127
+ /** @description OK */
6128
+ 200: {
6129
+ headers: {
6130
+ [name: string]: unknown;
6131
+ };
6132
+ content: {
6133
+ "application/json": components["schemas"]["MessageObject"];
6134
+ "text/event-stream": components["schemas"]["MessageStreamEvent"];
6135
+ };
6136
+ };
6137
+ /** @description Bad request. A FlexInference-layer rejection (type flexinference_error, e.g. missing_start_within, invalid_start_within, model_not_flex_capable, flex_unsupported_for_anthropic, missing_max_tokens, service_tier_not_allowed) or an upstream provider rejection passed through unchanged. */
5445
6138
  400: {
5446
6139
  headers: {
5447
6140
  [name: string]: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexinference",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Official TypeScript SDK for FlexInference - a deadline-aware, OpenAI-compatible inference router.",
5
5
  "license": "MIT",
6
6
  "author": "Aditya Perswal <adityaperswal@gmail.com>",