flexinference 1.1.0 → 1.3.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 +20 -0
- package/README.md +63 -4
- package/dist/index.d.ts +32 -0
- package/dist/index.js +54 -0
- package/dist/types.d.ts +341 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
Adds a typed **`PaymentRequiredError`** (a subclass of `FlexInferenceError`) thrown on
|
|
6
|
+
HTTP `402`, which the router returns when billing is past due and billable flex is paused
|
|
7
|
+
(free routing still works). Catch it on its own to prompt the user to update payment;
|
|
8
|
+
existing `catch (err instanceof FlexInferenceError)` handlers keep catching 402s because
|
|
9
|
+
it is a subclass. No other API or type changes.
|
|
10
|
+
|
|
11
|
+
## 1.2.0
|
|
12
|
+
|
|
13
|
+
Adds the **Messages** caller format (`client.messages.create`), the fourth format
|
|
14
|
+
alongside Responses, chat completions, and Interactions. It takes and returns the
|
|
15
|
+
Anthropic Messages shape and works for any model via the canonical Responses path,
|
|
16
|
+
posting to `/messages`. `max_tokens` is required (Anthropic requires it) and
|
|
17
|
+
`start_within` is required (same rule as the other formats); `service_tier` is a
|
|
18
|
+
compile-time error (the router owns the tier). New `messageText(obj)` helper pulls the
|
|
19
|
+
assistant text out of the response `content[]` blocks, where `outputText` and
|
|
20
|
+
`interactionText` return "". Also adds first-class Anthropic (`claude-*`) upstream
|
|
21
|
+
support behind the existing formats.
|
|
22
|
+
|
|
3
23
|
## 1.1.0
|
|
4
24
|
|
|
5
25
|
Adds the **Interactions** caller format (`client.interactions.create`), the third format
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# FlexInference (TypeScript)
|
|
2
2
|
|
|
3
|
-
The official TypeScript SDK for [FlexInference](https://flexinference.com) - a deadline-aware
|
|
3
|
+
The official TypeScript SDK for [FlexInference](https://flexinference.com) - a deadline-aware inference router across **OpenAI, Google Gemini, and Anthropic**. Send the OpenAI requests you already send, bring your own provider key, and set one required field - `start_within` - to trade latency for cost. Four caller formats are supported: `responses`, `chat.completions`, `interactions` (Gemini shape), and `messages` (Anthropic shape) - any of them reaches any provider.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install flexinference
|
|
@@ -26,14 +26,15 @@ Responses come back as the **raw OpenAI JSON** (we never reshape the body), so t
|
|
|
26
26
|
|
|
27
27
|
`start_within` is **required** on every request. It takes `"default"`, `"priority"`, `"auto"`, or a duration `"HHh-MMm-SSs"` (5s-10m). The duration races OpenAI's flex tier on a flex-capable model and falls back to standard if it can't start in time; `"default"`, `"priority"`, and `"auto"` map to those OpenAI service tiers and proxy any model. It is typed, so a missing value or a value outside the allowed shapes is a **compile-time** error; a duration that fits the shape but is malformed or out of range is caught at **runtime**, the same check plain-JavaScript callers get. See the [docs](https://flexinference.mintlify.app/deadline-routing).
|
|
28
28
|
|
|
29
|
-
## Providers (OpenAI and
|
|
29
|
+
## Providers (OpenAI, Gemini, and Anthropic)
|
|
30
30
|
|
|
31
|
-
FlexInference routes to **OpenAI** and **
|
|
31
|
+
FlexInference routes to **OpenAI**, **Google Gemini**, and **Anthropic**. Send the same OpenAI-shaped request and pass whichever model id you want - `gpt-5.5`, `o4-mini`, `gemini-3.5-flash`, `claude-opus-4-8`, and so on. We translate Gemini and Anthropic to and from the OpenAI shape, so your code is identical for all three.
|
|
32
32
|
|
|
33
33
|
- **OpenAI:** `default` (standard tier), `priority`, `auto`, and the flex race (a duration) on flex-capable models.
|
|
34
34
|
- **Gemini:** `default` maps to Gemini's **standard** tier, plus `priority` and the flex race on the Gemini flex models (`gemini-3.5-flash`, `gemini-3.1-flash-lite`, `gemini-3.1-pro-preview`, `gemini-3-flash-preview`, `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`). Gemini has no `auto` tier, so `start_within: "auto"` on a Gemini model returns `400`.
|
|
35
|
+
- **Anthropic (Claude):** proxy-only. `default`, `priority`, and `auto` work; there is **no flex race**, so a duration `start_within` on a `claude-*` model returns `400 flex_unsupported_for_anthropic`. Anthropic requires a token cap, so set `max_output_tokens` (`max_completion_tokens` on Chat, `max_tokens` on Messages) or you get `400 missing_max_tokens`. You keep the unified API and tier control, and draw down your own Anthropic credits.
|
|
35
36
|
|
|
36
|
-
Add the provider key you'll use (OpenAI and/or
|
|
37
|
+
Add the provider key you'll use (OpenAI, Gemini, and/or Anthropic) in the [dashboard](https://www.flexinference.com/dashboard). Text, streaming, structured outputs, function calling, image input, and web search work across providers (send a Responses `web_search` tool; we map it to Gemini's `google_search`).
|
|
37
38
|
|
|
38
39
|
Don't send `service_tier` - the router controls the tier from `start_within` and rejects a caller-supplied `service_tier` with `400 service_tier_not_allowed`.
|
|
39
40
|
|
|
@@ -64,6 +65,39 @@ const res = await client.chat.completions.create({
|
|
|
64
65
|
});
|
|
65
66
|
```
|
|
66
67
|
|
|
68
|
+
## Interactions (Gemini shape)
|
|
69
|
+
|
|
70
|
+
Speak Google's Interactions shape and reach any model. `interactionText(res)` pulls the assistant text out of the interaction's `steps`.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { interactionText } from "flexinference";
|
|
74
|
+
|
|
75
|
+
const res = await client.interactions.create({
|
|
76
|
+
model: "gemini-3.5-flash",
|
|
77
|
+
input: "Summarize this contract.",
|
|
78
|
+
start_within: "00h-01m-00s",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
console.log(interactionText(res));
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Messages (Anthropic shape)
|
|
85
|
+
|
|
86
|
+
Speak Anthropic's Messages shape and reach any model. `max_tokens` is required (Anthropic requires it). `messageText(res)` pulls the assistant text out of the message `content`.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { messageText } from "flexinference";
|
|
90
|
+
|
|
91
|
+
const res = await client.messages.create({
|
|
92
|
+
model: "claude-opus-4-8",
|
|
93
|
+
max_tokens: 1024,
|
|
94
|
+
messages: [{ role: "user", content: "Summarize this contract." }],
|
|
95
|
+
start_within: "default",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log(messageText(res));
|
|
99
|
+
```
|
|
100
|
+
|
|
67
101
|
## Timeouts and cancellation
|
|
68
102
|
|
|
69
103
|
Every client has a built-in timeout: **10 seconds to connect** and **600 seconds (10 min) total**, matching the router's budget, so a request can never hang forever. Override the total with the `timeout` option (raise it for very long streams):
|
|
@@ -102,6 +136,31 @@ try {
|
|
|
102
136
|
}
|
|
103
137
|
```
|
|
104
138
|
|
|
139
|
+
## Billing / 402
|
|
140
|
+
|
|
141
|
+
If your account's billing is past due, the router pauses **billable flex** and returns
|
|
142
|
+
`402 Payment Required` on those requests; free routing keeps working. The SDK throws a
|
|
143
|
+
typed `PaymentRequiredError` (a subclass of `FlexInferenceError`) for HTTP 402, so you
|
|
144
|
+
can catch it on its own and prompt the user to update payment while letting other errors
|
|
145
|
+
propagate:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { PaymentRequiredError } from "flexinference";
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
await client.responses.create({ model: "gpt-5.5", input: "hi", start_within: "00h-00m-30s" });
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (err instanceof PaymentRequiredError) {
|
|
154
|
+
console.log("Billing is past due - update payment in the dashboard to resume flex.");
|
|
155
|
+
} else {
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Because `PaymentRequiredError extends FlexInferenceError`, existing
|
|
162
|
+
`catch (err instanceof FlexInferenceError)` handlers keep catching 402s too.
|
|
163
|
+
|
|
105
164
|
## Configuration
|
|
106
165
|
|
|
107
166
|
| Option | Default | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export type InteractionCreateParams = WithStartWithin<Schemas["InteractionCreate
|
|
|
22
22
|
};
|
|
23
23
|
export type InteractionObject = Schemas["InteractionObject"];
|
|
24
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"];
|
|
25
30
|
/**
|
|
26
31
|
* Concatenate the assistant's text from a non-streamed response. Works on a Responses
|
|
27
32
|
* object (walks `output[].content[]` for `output_text` parts) and on a chat completion
|
|
@@ -40,6 +45,15 @@ export declare function outputText(response: ResponseObject | ChatCompletion): s
|
|
|
40
45
|
* reshaped. Streamed interactions are not objects; collect their `step.delta` text events.
|
|
41
46
|
*/
|
|
42
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;
|
|
43
57
|
export interface FlexErrorBody {
|
|
44
58
|
error: {
|
|
45
59
|
message: string;
|
|
@@ -55,6 +69,13 @@ export declare class FlexInferenceError extends Error {
|
|
|
55
69
|
readonly param: string | null | undefined;
|
|
56
70
|
constructor(status: number, body: Partial<FlexErrorBody> | undefined, fallback: string);
|
|
57
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Thrown on HTTP 402: billing is past due, so billable flex is paused. Free routing
|
|
74
|
+
* still works. A subclass of FlexInferenceError, so existing `catch (err instanceof
|
|
75
|
+
* FlexInferenceError)` handlers keep working; narrow to this to handle 402 specially.
|
|
76
|
+
*/
|
|
77
|
+
export declare class PaymentRequiredError extends FlexInferenceError {
|
|
78
|
+
}
|
|
58
79
|
export interface ClientOptions {
|
|
59
80
|
apiKey: string;
|
|
60
81
|
/** Base URL of the FlexInference router. Defaults to the hosted endpoint. */
|
|
@@ -79,6 +100,7 @@ export declare class FlexInference {
|
|
|
79
100
|
readonly responses: Responses;
|
|
80
101
|
readonly chat: Chat;
|
|
81
102
|
readonly interactions: Interactions;
|
|
103
|
+
readonly messages: Messages;
|
|
82
104
|
private readonly apiKey;
|
|
83
105
|
private readonly baseURL;
|
|
84
106
|
private readonly fetchImpl;
|
|
@@ -120,4 +142,14 @@ declare class Interactions {
|
|
|
120
142
|
stream: true;
|
|
121
143
|
}, options?: RequestOptions): Promise<AsyncIterable<InteractionStreamEvent>>;
|
|
122
144
|
}
|
|
145
|
+
declare class Messages {
|
|
146
|
+
private readonly post;
|
|
147
|
+
constructor(post: Post);
|
|
148
|
+
create(body: MessageCreateParams & {
|
|
149
|
+
stream?: false | null;
|
|
150
|
+
}, options?: RequestOptions): Promise<MessageObject>;
|
|
151
|
+
create(body: MessageCreateParams & {
|
|
152
|
+
stream: true;
|
|
153
|
+
}, options?: RequestOptions): Promise<AsyncIterable<MessageStreamEvent>>;
|
|
154
|
+
}
|
|
123
155
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,29 @@ export function interactionText(interaction) {
|
|
|
62
62
|
}
|
|
63
63
|
return text;
|
|
64
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
|
+
}
|
|
65
88
|
export class FlexInferenceError extends Error {
|
|
66
89
|
status;
|
|
67
90
|
type;
|
|
@@ -77,6 +100,13 @@ export class FlexInferenceError extends Error {
|
|
|
77
100
|
this.param = err?.param;
|
|
78
101
|
}
|
|
79
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Thrown on HTTP 402: billing is past due, so billable flex is paused. Free routing
|
|
105
|
+
* still works. A subclass of FlexInferenceError, so existing `catch (err instanceof
|
|
106
|
+
* FlexInferenceError)` handlers keep working; narrow to this to handle 402 specially.
|
|
107
|
+
*/
|
|
108
|
+
export class PaymentRequiredError extends FlexInferenceError {
|
|
109
|
+
}
|
|
80
110
|
const DEFAULT_BASE_URL = "https://api.flexinference.com/v1";
|
|
81
111
|
const DEFAULT_TIMEOUT_MS = 600_000; // 10 min total budget, matching the router's generosity
|
|
82
112
|
const CONNECT_TIMEOUT_MS = 10_000; // fail fast if the router is unreachable
|
|
@@ -114,6 +144,7 @@ export class FlexInference {
|
|
|
114
144
|
responses;
|
|
115
145
|
chat;
|
|
116
146
|
interactions;
|
|
147
|
+
messages;
|
|
117
148
|
apiKey;
|
|
118
149
|
baseURL;
|
|
119
150
|
fetchImpl;
|
|
@@ -133,6 +164,7 @@ export class FlexInference {
|
|
|
133
164
|
this.responses = new Responses(post);
|
|
134
165
|
this.chat = new Chat(post);
|
|
135
166
|
this.interactions = new Interactions(post);
|
|
167
|
+
this.messages = new Messages(post);
|
|
136
168
|
}
|
|
137
169
|
async post(path, body, signal) {
|
|
138
170
|
// One AbortController fed by three sources: the caller's signal, a 10s connect
|
|
@@ -193,6 +225,9 @@ export class FlexInference {
|
|
|
193
225
|
finally {
|
|
194
226
|
cleanup();
|
|
195
227
|
}
|
|
228
|
+
if (res.status === 402) {
|
|
229
|
+
throw new PaymentRequiredError(res.status, parsed, `HTTP ${String(res.status)} ${res.statusText}`);
|
|
230
|
+
}
|
|
196
231
|
throw new FlexInferenceError(res.status, parsed, `HTTP ${String(res.status)} ${res.statusText}`);
|
|
197
232
|
}
|
|
198
233
|
return { res, cleanup };
|
|
@@ -261,6 +296,25 @@ class Interactions {
|
|
|
261
296
|
}
|
|
262
297
|
}
|
|
263
298
|
}
|
|
299
|
+
class Messages {
|
|
300
|
+
post;
|
|
301
|
+
constructor(post) {
|
|
302
|
+
this.post = post;
|
|
303
|
+
}
|
|
304
|
+
async create(body, options) {
|
|
305
|
+
assertStartWithin(body);
|
|
306
|
+
const { res, cleanup } = await this.post("/messages", body, options?.signal);
|
|
307
|
+
if (body.stream) {
|
|
308
|
+
return streamSSE(res, cleanup);
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
return (await res.json());
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
cleanup();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
264
318
|
async function* streamSSE(res, cleanup) {
|
|
265
319
|
if (!res.body) {
|
|
266
320
|
cleanup();
|
package/dist/types.d.ts
CHANGED
|
@@ -81,6 +81,23 @@ export interface paths {
|
|
|
81
81
|
patch?: never;
|
|
82
82
|
trace?: never;
|
|
83
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
|
+
};
|
|
84
101
|
}
|
|
85
102
|
export type webhooks = Record<string, never>;
|
|
86
103
|
export interface components {
|
|
@@ -5675,6 +5692,287 @@ export interface components {
|
|
|
5675
5692
|
* @description One server-sent event frame on the Interactions stream.
|
|
5676
5693
|
*/
|
|
5677
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"];
|
|
5678
5976
|
};
|
|
5679
5977
|
responses: never;
|
|
5680
5978
|
parameters: never;
|
|
@@ -5813,4 +6111,47 @@ export interface operations {
|
|
|
5813
6111
|
};
|
|
5814
6112
|
};
|
|
5815
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. */
|
|
6138
|
+
400: {
|
|
6139
|
+
headers: {
|
|
6140
|
+
[name: string]: unknown;
|
|
6141
|
+
};
|
|
6142
|
+
content: {
|
|
6143
|
+
"application/json": components["schemas"]["FlexError"];
|
|
6144
|
+
};
|
|
6145
|
+
};
|
|
6146
|
+
/** @description Invalid or missing FlexInference API key (type flexinference_error, code invalid_api_key). */
|
|
6147
|
+
401: {
|
|
6148
|
+
headers: {
|
|
6149
|
+
[name: string]: unknown;
|
|
6150
|
+
};
|
|
6151
|
+
content: {
|
|
6152
|
+
"application/json": components["schemas"]["FlexError"];
|
|
6153
|
+
};
|
|
6154
|
+
};
|
|
6155
|
+
};
|
|
6156
|
+
};
|
|
5816
6157
|
}
|
package/package.json
CHANGED