@b3os/sdk 0.1.0 → 0.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/README.md +172 -42
- package/dist/cjs/core/bytes.d.ts +30 -0
- package/dist/cjs/core/bytes.js +115 -0
- package/dist/cjs/core/bytes.js.map +1 -0
- package/dist/cjs/core/client.d.ts +80 -3
- package/dist/cjs/core/client.js +236 -33
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/core/errors.d.ts +16 -4
- package/dist/cjs/core/errors.js +9 -6
- package/dist/cjs/core/errors.js.map +1 -1
- package/dist/cjs/core/handle.d.ts +36 -0
- package/dist/cjs/core/handle.js +97 -0
- package/dist/cjs/core/handle.js.map +1 -0
- package/dist/cjs/core/index.d.ts +8 -4
- package/dist/cjs/core/index.js +14 -1
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/core/login.d.ts +24 -0
- package/dist/cjs/core/login.js +93 -0
- package/dist/cjs/core/login.js.map +1 -0
- package/dist/cjs/core/namespace.d.ts +1 -1
- package/dist/cjs/core/namespace.js +1 -1
- package/dist/cjs/core/op.d.ts +11 -1
- package/dist/cjs/core/timing.d.ts +1 -1
- package/dist/cjs/core/timing.js +8 -1
- package/dist/cjs/core/timing.js.map +1 -1
- package/dist/cjs/core/traces-api.d.ts +42 -0
- package/dist/cjs/core/traces-api.js +54 -0
- package/dist/cjs/core/traces-api.js.map +1 -0
- package/dist/cjs/core/traces.d.ts +120 -0
- package/dist/cjs/core/traces.js +306 -0
- package/dist/cjs/core/traces.js.map +1 -0
- package/dist/cjs/core/transport.js +1 -1
- package/dist/cjs/core/transport.js.map +1 -1
- package/dist/cjs/core/util.d.ts +15 -3
- package/dist/cjs/core/util.js +54 -2
- package/dist/cjs/core/util.js.map +1 -1
- package/dist/cjs/core/ws.d.ts +4 -0
- package/dist/cjs/core/ws.js +7 -4
- package/dist/cjs/core/ws.js.map +1 -1
- package/dist/cjs/generated/client.d.ts +2 -2
- package/dist/cjs/generated/client.js +2 -2
- package/dist/cjs/generated/errors.d.ts +1 -1
- package/dist/cjs/generated/errors.js +42 -0
- package/dist/cjs/generated/errors.js.map +1 -1
- package/dist/cjs/generated/ids.d.ts +12 -0
- package/dist/cjs/generated/ids.js +3 -0
- package/dist/cjs/generated/ids.js.map +1 -1
- package/dist/cjs/generated/jobs.js +1 -1
- package/dist/cjs/generated/ns/actions.d.ts +48 -6
- package/dist/cjs/generated/ns/actions.js +59 -6
- package/dist/cjs/generated/ns/actions.js.map +1 -1
- package/dist/cjs/generated/ns/infer.d.ts +185 -54
- package/dist/cjs/generated/ns/infer.js +28 -74
- package/dist/cjs/generated/ns/infer.js.map +1 -1
- package/dist/cjs/generated/ns/keys.d.ts +14 -1
- package/dist/cjs/generated/ns/keys.js +24 -1
- package/dist/cjs/generated/ns/keys.js.map +1 -1
- package/dist/cjs/generated/ns/render.d.ts +115 -6
- package/dist/cjs/generated/ns/render.js +135 -7
- package/dist/cjs/generated/ns/render.js.map +1 -1
- package/dist/cjs/generated/ns/requests.d.ts +3 -1
- package/dist/cjs/generated/ns/requests.js +3 -1
- package/dist/cjs/generated/ns/requests.js.map +1 -1
- package/dist/cjs/generated/ns/routines.d.ts +131 -9
- package/dist/cjs/generated/ns/routines.js +186 -9
- package/dist/cjs/generated/ns/routines.js.map +1 -1
- package/dist/cjs/generated/ns/sandboxes.d.ts +327 -31
- package/dist/cjs/generated/ns/sandboxes.js +417 -29
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
- package/dist/cjs/generated/ns/vision.d.ts +133 -14
- package/dist/cjs/generated/ns/vision.js +158 -12
- package/dist/cjs/generated/ns/vision.js.map +1 -1
- package/dist/cjs/generated/ns/webhooks.d.ts +8 -5
- package/dist/cjs/generated/ns/webhooks.js +8 -5
- package/dist/cjs/generated/ns/webhooks.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +2750 -328
- package/dist/cjs/helpers/agents.d.ts +95 -0
- package/dist/cjs/helpers/agents.js +205 -0
- package/dist/cjs/helpers/agents.js.map +1 -0
- package/dist/cjs/helpers/render.d.ts +15 -0
- package/dist/cjs/helpers/render.js +74 -0
- package/dist/cjs/helpers/render.js.map +1 -0
- package/dist/cjs/helpers/routines.d.ts +61 -0
- package/dist/cjs/helpers/routines.js +234 -0
- package/dist/cjs/helpers/routines.js.map +1 -0
- package/dist/cjs/helpers/sandboxes.d.ts +237 -0
- package/dist/cjs/helpers/sandboxes.js +608 -0
- package/dist/cjs/helpers/sandboxes.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +8 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/routines.d.ts +1 -0
- package/dist/cjs/routines.js +21 -0
- package/dist/cjs/routines.js.map +1 -0
- package/dist/cjs/webhooks.js.map +1 -1
- package/dist/esm/core/bytes.d.ts +30 -0
- package/dist/esm/core/bytes.js +111 -0
- package/dist/esm/core/bytes.js.map +1 -0
- package/dist/esm/core/client.d.ts +80 -3
- package/dist/esm/core/client.js +233 -31
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/core/errors.d.ts +16 -4
- package/dist/esm/core/errors.js +9 -6
- package/dist/esm/core/errors.js.map +1 -1
- package/dist/esm/core/handle.d.ts +36 -0
- package/dist/esm/core/handle.js +93 -0
- package/dist/esm/core/handle.js.map +1 -0
- package/dist/esm/core/index.d.ts +8 -4
- package/dist/esm/core/index.js +6 -2
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/login.d.ts +24 -0
- package/dist/esm/core/login.js +85 -0
- package/dist/esm/core/login.js.map +1 -0
- package/dist/esm/core/namespace.d.ts +1 -1
- package/dist/esm/core/namespace.js +1 -1
- package/dist/esm/core/op.d.ts +11 -1
- package/dist/esm/core/timing.d.ts +1 -1
- package/dist/esm/core/timing.js +8 -1
- package/dist/esm/core/timing.js.map +1 -1
- package/dist/esm/core/traces-api.d.ts +42 -0
- package/dist/esm/core/traces-api.js +50 -0
- package/dist/esm/core/traces-api.js.map +1 -0
- package/dist/esm/core/traces.d.ts +120 -0
- package/dist/esm/core/traces.js +295 -0
- package/dist/esm/core/traces.js.map +1 -0
- package/dist/esm/core/transport.js +1 -1
- package/dist/esm/core/transport.js.map +1 -1
- package/dist/esm/core/util.d.ts +15 -3
- package/dist/esm/core/util.js +48 -1
- package/dist/esm/core/util.js.map +1 -1
- package/dist/esm/core/ws.d.ts +4 -0
- package/dist/esm/core/ws.js +7 -4
- package/dist/esm/core/ws.js.map +1 -1
- package/dist/esm/generated/client.d.ts +2 -2
- package/dist/esm/generated/client.js +2 -2
- package/dist/esm/generated/errors.d.ts +1 -1
- package/dist/esm/generated/errors.js +42 -0
- package/dist/esm/generated/errors.js.map +1 -1
- package/dist/esm/generated/ids.d.ts +12 -0
- package/dist/esm/generated/ids.js +3 -0
- package/dist/esm/generated/ids.js.map +1 -1
- package/dist/esm/generated/jobs.js +1 -1
- package/dist/esm/generated/ns/actions.d.ts +48 -6
- package/dist/esm/generated/ns/actions.js +59 -6
- package/dist/esm/generated/ns/actions.js.map +1 -1
- package/dist/esm/generated/ns/infer.d.ts +185 -54
- package/dist/esm/generated/ns/infer.js +28 -74
- package/dist/esm/generated/ns/infer.js.map +1 -1
- package/dist/esm/generated/ns/keys.d.ts +14 -1
- package/dist/esm/generated/ns/keys.js +24 -1
- package/dist/esm/generated/ns/keys.js.map +1 -1
- package/dist/esm/generated/ns/render.d.ts +115 -6
- package/dist/esm/generated/ns/render.js +135 -7
- package/dist/esm/generated/ns/render.js.map +1 -1
- package/dist/esm/generated/ns/requests.d.ts +3 -1
- package/dist/esm/generated/ns/requests.js +3 -1
- package/dist/esm/generated/ns/requests.js.map +1 -1
- package/dist/esm/generated/ns/routines.d.ts +131 -9
- package/dist/esm/generated/ns/routines.js +186 -9
- package/dist/esm/generated/ns/routines.js.map +1 -1
- package/dist/esm/generated/ns/sandboxes.d.ts +327 -31
- package/dist/esm/generated/ns/sandboxes.js +417 -29
- package/dist/esm/generated/ns/sandboxes.js.map +1 -1
- package/dist/esm/generated/ns/vision.d.ts +133 -14
- package/dist/esm/generated/ns/vision.js +158 -12
- package/dist/esm/generated/ns/vision.js.map +1 -1
- package/dist/esm/generated/ns/webhooks.d.ts +8 -5
- package/dist/esm/generated/ns/webhooks.js +8 -5
- package/dist/esm/generated/ns/webhooks.js.map +1 -1
- package/dist/esm/generated/types.d.ts +2750 -328
- package/dist/esm/helpers/agents.d.ts +95 -0
- package/dist/esm/helpers/agents.js +199 -0
- package/dist/esm/helpers/agents.js.map +1 -0
- package/dist/esm/helpers/render.d.ts +15 -0
- package/dist/esm/helpers/render.js +70 -0
- package/dist/esm/helpers/render.js.map +1 -0
- package/dist/esm/helpers/routines.d.ts +61 -0
- package/dist/esm/helpers/routines.js +226 -0
- package/dist/esm/helpers/routines.js.map +1 -0
- package/dist/esm/helpers/sandboxes.d.ts +237 -0
- package/dist/esm/helpers/sandboxes.js +600 -0
- package/dist/esm/helpers/sandboxes.js.map +1 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routines.d.ts +1 -0
- package/dist/esm/routines.js +5 -0
- package/dist/esm/routines.js.map +1 -0
- package/dist/esm/webhooks.js.map +1 -1
- package/package.json +14 -3
- package/src/core/bytes.ts +112 -0
- package/src/core/client.ts +285 -33
- package/src/core/errors.ts +27 -10
- package/src/core/handle.ts +107 -0
- package/src/core/index.ts +17 -2
- package/src/core/login.ts +98 -0
- package/src/core/namespace.ts +1 -1
- package/src/core/op.ts +11 -1
- package/src/core/timing.ts +7 -2
- package/src/core/traces-api.ts +80 -0
- package/src/core/traces.ts +375 -0
- package/src/core/transport.ts +1 -1
- package/src/core/util.ts +53 -3
- package/src/core/ws.ts +11 -4
- package/src/generated/client.ts +2 -2
- package/src/generated/errors.ts +84 -0
- package/src/generated/ids.ts +3 -0
- package/src/generated/jobs.ts +1 -1
- package/src/generated/ns/actions.ts +69 -6
- package/src/generated/ns/infer.ts +229 -61
- package/src/generated/ns/keys.ts +25 -1
- package/src/generated/ns/render.ts +172 -7
- package/src/generated/ns/requests.ts +3 -1
- package/src/generated/ns/routines.ts +205 -9
- package/src/generated/ns/sandboxes.ts +493 -34
- package/src/generated/ns/vision.ts +168 -14
- package/src/generated/ns/webhooks.ts +8 -5
- package/src/generated/types.ts +3034 -472
- package/src/helpers/agents.ts +300 -0
- package/src/helpers/render.ts +91 -0
- package/src/helpers/routines.ts +278 -0
- package/src/helpers/sandboxes.ts +788 -0
- package/src/index.ts +29 -5
- package/src/routines.ts +5 -0
- package/src/webhooks.ts +5 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
|
|
2
2
|
|
|
3
|
+
import type { ByteStream } from "../../core/bytes.ts";
|
|
3
4
|
import type { RequestOptions, StreamOptions } from "../../core/client.ts";
|
|
4
5
|
import { Namespace } from "../../core/namespace.ts";
|
|
5
6
|
import type { Op } from "../../core/op.ts";
|
|
@@ -12,6 +13,7 @@ const createSpeechOp: Op = {
|
|
|
12
13
|
method: "POST",
|
|
13
14
|
path: "/v1/infer/audio/speech",
|
|
14
15
|
body: "json",
|
|
16
|
+
stream: "sse",
|
|
15
17
|
timeoutMs: 65000,
|
|
16
18
|
errorFormat: "openai",
|
|
17
19
|
scope: "infer:run",
|
|
@@ -69,7 +71,6 @@ const createResponseOp: Op = {
|
|
|
69
71
|
stream: "sse",
|
|
70
72
|
timeoutMs: 600000,
|
|
71
73
|
errorFormat: "openai",
|
|
72
|
-
stretch: true,
|
|
73
74
|
scope: "infer:run",
|
|
74
75
|
};
|
|
75
76
|
const createMessageOp: Op = {
|
|
@@ -79,8 +80,7 @@ const createMessageOp: Op = {
|
|
|
79
80
|
body: "json",
|
|
80
81
|
stream: "sse",
|
|
81
82
|
timeoutMs: 600000,
|
|
82
|
-
errorFormat: "
|
|
83
|
-
stretch: true,
|
|
83
|
+
errorFormat: "anthropic",
|
|
84
84
|
scope: "infer:run",
|
|
85
85
|
};
|
|
86
86
|
const countMessageTokensOp: Op = {
|
|
@@ -89,8 +89,7 @@ const countMessageTokensOp: Op = {
|
|
|
89
89
|
path: "/v1/infer/v1/messages/count_tokens",
|
|
90
90
|
body: "json",
|
|
91
91
|
timeoutMs: 30000,
|
|
92
|
-
errorFormat: "
|
|
93
|
-
stretch: true,
|
|
92
|
+
errorFormat: "anthropic",
|
|
94
93
|
scope: "infer:run",
|
|
95
94
|
};
|
|
96
95
|
|
|
@@ -117,20 +116,63 @@ export class InferAPI extends Namespace {
|
|
|
117
116
|
* word, which render uses to place clicks on words and cut captions. Every `response_format` is produced:
|
|
118
117
|
* `mp3`, `opus` (Ogg), `aac` (ADTS), `flac`, `wav` and `pcm` (16-bit mono at `sample_rate`, 24 kHz for
|
|
119
118
|
* `kokoro-82m`). `kokoro-82m` speaks at `speed` 0.5 to 2 and takes no `instructions`; other values return
|
|
120
|
-
* `400 unsupported_parameter`.
|
|
121
|
-
* `
|
|
119
|
+
* `400 unsupported_parameter`. OpenAI's voice names work: `alloy`, `echo`, `fable`, `nova` and `onyx` are
|
|
120
|
+
* Kokoro's `af_alloy`, `am_echo`, `bm_fable`, `af_nova` and `am_onyx`, and `ash`, `ballad`, `cedar`, `coral`,
|
|
121
|
+
* `marin`, `sage`, `shimmer` and `verse` are a fixed pick of other Kokoro voices (`am_michael`, `bm_george`,
|
|
122
|
+
* `am_fenrir`, `af_heart`, `af_kore`, `af_sarah`, `af_bella` and `am_puck`), not a claim that they sound alike.
|
|
123
|
+
* The `x-b3os-voice` header names the voice that spoke. Any other name is `404 voice_not_found`. B3OS
|
|
124
|
+
* extension: `language` reads `input` in another language than the voice's own (one of the `language` values
|
|
125
|
+
* `GET /v1/infer/audio/voices` lists; others are `400 unsupported_parameter`). While the
|
|
126
|
+
* node's voice service is down the answer is `503 infer_backend_unavailable` with `Retry-After`.
|
|
127
|
+
* `Server-Timing` carries the voice service's own
|
|
122
128
|
* `voice_queue` and `voice_run` beside b3osd's `synthesize` and `encode`. Bills `infer.audio_chars`
|
|
123
129
|
* (characters of `input`).
|
|
124
130
|
*
|
|
131
|
+
* Streaming: without `stream_format` the clip comes in one piece. With OpenAI's `stream_format` the audio
|
|
132
|
+
* is sent as it is made, sentence by sentence: `audio` sends the bytes of `response_format` as they come (a
|
|
133
|
+
* `wav` stream's header has open sizes, `0xFFFFFFFF`), and `sse` sends `speech.audio.delta` events with
|
|
134
|
+
* base64 audio, then one `speech.audio.done` with the format, duration, `words` when `timestamps` is `word`,
|
|
135
|
+
* and `b3os` timing. The response head waits for the first audio, so `Server-Timing` carries `ttfa`, the time
|
|
136
|
+
* from the request to the first audio bytes, and an error before any audio is a plain HTTP error. A failure
|
|
137
|
+
* after audio ends an `sse` stream with an `error` event and cuts an `audio` stream short; the characters of
|
|
138
|
+
* each part of the input that produced audio are billed. `timestamps: "word"` with `stream_format: "audio"`
|
|
139
|
+
* is `400 unsupported_parameter` (an audio stream carries only audio).
|
|
140
|
+
*
|
|
141
|
+
* In flight: each organization may have 32 speech answers on a node at once, streamed or not, each counted
|
|
142
|
+
* until its last byte is read; the next is `429 concurrency_limited` with `Retry-After: 1`. An answer whose
|
|
143
|
+
* caller reads nothing of it for 2 minutes ends, and its body is cut short.
|
|
144
|
+
*
|
|
125
145
|
* `POST /v1/infer/audio/speech` · scope `infer:run` · served by the node
|
|
126
146
|
*/
|
|
147
|
+
createSpeech(
|
|
148
|
+
body: T.SpeechRequest & { stream_format: "sse" },
|
|
149
|
+
options?: StreamOptions,
|
|
150
|
+
): EventStream<T.SpeechStreamEvent>;
|
|
151
|
+
createSpeech(body: T.SpeechRequest & { stream_format: "audio" }, options?: RequestOptions): ByteStream;
|
|
127
152
|
createSpeech(
|
|
128
153
|
body: T.SpeechRequest & { timestamps: "word" },
|
|
129
154
|
options?: RequestOptions,
|
|
130
155
|
): APIPromise<T.SpeechWithTimestamps>;
|
|
131
156
|
createSpeech(body: T.SpeechRequest, options?: RequestOptions): APIPromise<Uint8Array>;
|
|
132
|
-
createSpeech(
|
|
133
|
-
|
|
157
|
+
createSpeech(
|
|
158
|
+
body: T.SpeechRequest,
|
|
159
|
+
options: StreamOptions = {},
|
|
160
|
+
): APIPromise<T.SpeechWithTimestamps | Uint8Array> | EventStream<T.SpeechStreamEvent> | ByteStream {
|
|
161
|
+
const b = body as { timestamps?: string | null; stream_format?: string | null };
|
|
162
|
+
if (b.stream_format === "sse") {
|
|
163
|
+
return this._client._postStream<T.SpeechStreamEvent>(createSpeechOp, { body }, options, {
|
|
164
|
+
terminal: (e) => ["speech.audio.done", "error"].includes((e as { type?: string }).type ?? ""),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (b.stream_format === "audio") {
|
|
168
|
+
return this._client._postBytes(
|
|
169
|
+
createSpeechOp,
|
|
170
|
+
{ body },
|
|
171
|
+
options,
|
|
172
|
+
"audio/mpeg, audio/wav, audio/pcm, audio/ogg, audio/aac, audio/flac",
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
if (b.timestamps === "word") {
|
|
134
176
|
return this._client._call<T.SpeechWithTimestamps>(createSpeechOp, { body }, options);
|
|
135
177
|
}
|
|
136
178
|
return this._client._call<Uint8Array>(
|
|
@@ -145,8 +187,9 @@ export class InferAPI extends Namespace {
|
|
|
145
187
|
/**
|
|
146
188
|
* List voices
|
|
147
189
|
*
|
|
148
|
-
* Lists the voices each speech model offers,
|
|
149
|
-
*
|
|
190
|
+
* Lists the voices each speech model offers, featured voices first, with language, gender, where the word
|
|
191
|
+
* timings come from, the voice's tier and use case, whether it is its language's default, and an audio
|
|
192
|
+
* sample. A B3OS endpoint (not part of the OpenAI API), so it uses B3OS lists and errors: `503 infer_backend_unavailable` with `Retry-After` while
|
|
150
193
|
* the voice service is down. All voices arrive in one page (`next_cursor` is always `null`).
|
|
151
194
|
*
|
|
152
195
|
* `GET /v1/infer/audio/voices` · scope `infer:read` · served by the node
|
|
@@ -169,16 +212,41 @@ export class InferAPI extends Namespace {
|
|
|
169
212
|
* Parameters this node does not take return `400 unsupported_parameter` naming the parameter. Besides the
|
|
170
213
|
* OpenAI parameters below, it takes the sampling extensions `top_k`, `min_p`, `repetition_penalty` and
|
|
171
214
|
* `logit_bias`, and `chat_template_kwargs.enable_thinking` (the model answers without a reasoning phase
|
|
172
|
-
* unless it is `true`; the reasoning then arrives in `reasoning_content`). `
|
|
173
|
-
*
|
|
215
|
+
* unless it is `true`; the reasoning then arrives in `reasoning_content`). `reasoning_effort` turns the
|
|
216
|
+
* reasoning phase on with a ceiling the node enforces: `low` 256, `medium` 1,024, `high` 4,096 and `xhigh`
|
|
217
|
+
* 8,192 reasoning tokens, after which the reasoning closes and the answer starts in the same request; `none`
|
|
218
|
+
* and `minimal` turn it off. `metadata`, `store`,
|
|
219
|
+
* `service_tier`, `prompt_cache_key`, `prompt_cache_retention`, `safety_identifier` and `verbosity` are
|
|
220
|
+
* accepted and ignored. `null` means unset for every optional parameter. Image URLs are
|
|
174
221
|
* `https://` (fetched by the node through its egress guard, which refuses private, loopback and metadata
|
|
175
222
|
* addresses with `403 egress_denied`) or `data:image/{png,jpeg,webp,gif};base64,`. JSON Schemas (tool
|
|
176
223
|
* `parameters`, `response_format.json_schema.schema`) larger than 64 KiB or nested deeper than 32 levels are
|
|
177
224
|
* `400 unsupported_parameter`.
|
|
178
225
|
*
|
|
226
|
+
* The runtime caches prompt prefixes per organization: the node salts the cache with your organization on
|
|
227
|
+
* every chat completion, Messages and Responses request, so a request reuses cached prefixes only from your
|
|
228
|
+
* own organization's requests, and another organization's request never hits yours. The salt is the node's,
|
|
229
|
+
* not a parameter: `cache_salt` is `400 unsupported_parameter`. The runtime's image caches (processed and
|
|
230
|
+
* encoded images) are split the same way: the node gives every image an identity derived from your
|
|
231
|
+
* organization and the image's bytes, so a cached image serves only your own organization's requests. A
|
|
232
|
+
* content part's `uuid` is `400 invalid_request`.
|
|
233
|
+
*
|
|
234
|
+
* Conversations are checked against what the model's chat template takes (`400 invalid_request` with the
|
|
235
|
+
* pointer): every message but an assistant one needs `content`, and on `b3os/qwen3.5-9b` the conversation
|
|
236
|
+
* needs a user message that is more than tool results. Developer messages are system messages on this node's
|
|
237
|
+
* models (OpenAI's meaning of the role); on `b3os/qwen3.5-9b` the system and developer messages a
|
|
238
|
+
* conversation starts with are joined into one, separated by a blank line (its chat template takes one), and
|
|
239
|
+
* a system or developer message after another turn is `400 invalid_request` pointing at it.
|
|
240
|
+
*
|
|
179
241
|
* Bills input and output tokens. Requests are admitted against your organization's per-minute limits on the
|
|
180
|
-
* model: one request, and the estimated prompt plus `max_completion_tokens` (or `max_tokens`, else
|
|
181
|
-
* tokens), settled with the real counts when the request ends.
|
|
242
|
+
* model: one request, and the estimated prompt plus `max_completion_tokens` (or `max_tokens`, else the
|
|
243
|
+
* default output cap, else 512 tokens), settled with the real counts when the request ends. The default
|
|
244
|
+
* output cap is a node setting, shown per model as `b3os.default_max_tokens` in `GET /v1/infer/models`: where
|
|
245
|
+
* it is set, a request that sets neither stops there with `finish_reason: "length"` (set `max_tokens` to go
|
|
246
|
+
* higher); where it is `null`, there is no cap and such a request can run to the end of the context. Each
|
|
247
|
+
* `https://` image reserves the node's image size limit (10 MiB) from your organization's per-minute image
|
|
248
|
+
* bytes before it is fetched, and gives back what it did not use; the bytes fetched count against the
|
|
249
|
+
* organization's daily egress quota.
|
|
182
250
|
*
|
|
183
251
|
* `POST /v1/infer/chat/completions` · scope `infer:run` · served by the node
|
|
184
252
|
*/
|
|
@@ -246,34 +314,88 @@ export class InferAPI extends Namespace {
|
|
|
246
314
|
* Create a response (OpenAI Responses API)
|
|
247
315
|
*
|
|
248
316
|
* A stateless subset of the OpenAI Responses API on the node's own models, for SDKs and agent frameworks that
|
|
249
|
-
* speak Responses (the OpenAI Agents SDK among them) with only the base URL changed
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* `
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* `
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
317
|
+
* speak Responses (the OpenAI Agents SDK among them) with only the base URL changed. Nothing is stored: send
|
|
318
|
+
* the whole conversation as `input` items each turn, and every response reports `store: false`. Models are
|
|
319
|
+
* those of `GET /v1/infer/models`; there is no gateway route on Responses. `null` means unset for every
|
|
320
|
+
* optional parameter.
|
|
321
|
+
*
|
|
322
|
+
* **Supported**
|
|
323
|
+
*
|
|
324
|
+
* | Parameter | On this node |
|
|
325
|
+
* |---|---|
|
|
326
|
+
* | `model` | A chat model from `GET /v1/infer/models` |
|
|
327
|
+
* | `input` | A string, or items: `message` (`input_text` and `input_image` parts; `output_text` for assistant turns), `function_call`, `function_call_output` and `reasoning` |
|
|
328
|
+
* | `instructions` | Joined with the system and developer items `input` starts with into one system message |
|
|
329
|
+
* | `tools`, `tool_choice`, `parallel_tool_calls` | `function` tools (at most 128); `tool_choice` `none`, `auto`, `required` or a named function. A tool's `strict` is passed to the runtime when set, and the response echoes what was applied: the value sent, or `null` when unset (OpenAI's default is `true`; unset here, `auto` tool calls are not held to the schema) |
|
|
330
|
+
* | `text.format` | `text`, `json_schema` (at most 64 KiB serialized and 32 levels deep) and `json_object` |
|
|
331
|
+
* | `reasoning.effort` | `low` and above turn the model's reasoning phase on, at most 256, 1,024, 4,096 or 8,192 reasoning tokens (`low` to `xhigh`, as chat's `reasoning_effort`); its text arrives in `reasoning` items. `none` and `minimal` leave it off |
|
|
332
|
+
* | `max_output_tokens` | Caps the answer; admission reserves it. Unset, the answer stops at the model's default output cap where the node sets one (`b3os.default_max_tokens`), with `status: "incomplete"`; where that is `null`, it can run to the end of the context |
|
|
333
|
+
* | `temperature`, `top_p` | Passed to the runtime |
|
|
334
|
+
* | `stream` | The Responses event stream (`response.created` ... `response.completed`), as OpenAI sends it |
|
|
335
|
+
* | `input_image` | `https://` URLs (fetched by the node through its egress guard) or `data:image/{png,jpeg,webp,gif};base64,` URLs, with the image limits of chat completions |
|
|
336
|
+
*
|
|
337
|
+
* **Accepted and ignored**
|
|
267
338
|
*
|
|
339
|
+
* | Parameter | Why |
|
|
340
|
+
* |---|---|
|
|
341
|
+
* | `store` | Nothing is stored; the response says `store: false` |
|
|
342
|
+
* | `metadata` | Echoed in the response (at most 16 keys) |
|
|
343
|
+
* | `user`, `safety_identifier`, `prompt_cache_key`, `prompt_cache_retention`, `service_tier` | No effect on this node; the runtime caches prompt prefixes on its own, per organization |
|
|
344
|
+
* | `text.verbosity`, `reasoning.summary`, `reasoning.generate_summary` | Echoed; the reasoning text is returned whole |
|
|
345
|
+
* | `include: ["reasoning.encrypted_content"]` | Reasoning items carry their text in `content` |
|
|
346
|
+
* | `stream_options.include_obfuscation` | No obfuscation padding is sent |
|
|
347
|
+
* | `truncation: "disabled"` | The default; the node never drops input items |
|
|
348
|
+
*
|
|
349
|
+
* **Refused** (`400 unsupported_parameter`, pointing at the parameter)
|
|
350
|
+
*
|
|
351
|
+
* | Parameter | Why |
|
|
352
|
+
* |---|---|
|
|
353
|
+
* | `previous_response_id`, `conversation`, `background: true`, `item_reference` items | They need stored responses |
|
|
354
|
+
* | `prompt` | Stored prompts are not available |
|
|
355
|
+
* | `truncation: "auto"` | The node never drops input items; keep the input within the model's context |
|
|
356
|
+
* | Tools other than `function` (web search, file search, computer use, code interpreter, MCP, image generation, shell), `defer_loading: true`, `allowed_callers` other than `direct` | They run on OpenAI's side |
|
|
357
|
+
* | `input_file` parts, `file_id` images | The Files API is not available |
|
|
358
|
+
* | `top_logprobs`, `max_tool_calls`, other `include` values | Not available on this node |
|
|
359
|
+
* | Any other parameter | The request is closed |
|
|
360
|
+
*
|
|
361
|
+
* **Errors** (OpenAI shape, the B3OS code in `error.code`)
|
|
362
|
+
*
|
|
363
|
+
* | Status | When |
|
|
364
|
+
* |---|---|
|
|
365
|
+
* | `400 invalid_request` | A malformed value, or a conversation the chat template refuses: on `b3os/qwen3.5-9b` it needs a user message that is more than function call outputs, and a system or developer item after another turn is refused (pointing at `input`) |
|
|
366
|
+
* | `400 unsupported_parameter` | The Refused rows above |
|
|
367
|
+
* | `400 context_length_exceeded` | The prompt plus `max_output_tokens` does not fit the model's context |
|
|
368
|
+
* | `403 egress_denied` | An image URL on a private, loopback or metadata address |
|
|
369
|
+
* | `404 model_not_available` | The model is not served on this node |
|
|
370
|
+
* | `429` | Over your organization's requests or tokens per minute, image bytes per minute or requests in flight (`Retry-After` says when) |
|
|
371
|
+
* | `503 infer_backend_unavailable` | The runtime is restarting or its slots are taken (`Retry-After`) |
|
|
372
|
+
* | stream `error` event | A stream that fails after it started ends with an `error` event; one that fails before the first token is a plain HTTP error |
|
|
373
|
+
*
|
|
374
|
+
* The response head of a stream waits for the first generated token, so `Server-Timing` can carry `ttft`.
|
|
268
375
|
* Bills input and output tokens, with the admission and limits of chat completions (the estimated prompt
|
|
269
|
-
* plus `max_output_tokens`, else 512 tokens, settled with the real counts; an
|
|
270
|
-
* its last token).
|
|
376
|
+
* plus `max_output_tokens`, else the default output cap, else 512 tokens, settled with the real counts; an
|
|
377
|
+
* abandoned stream is billed to its last token).
|
|
271
378
|
*
|
|
272
379
|
* `POST /v1/infer/responses` · scope `infer:run` · served by the node
|
|
273
|
-
*
|
|
274
|
-
* Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
|
|
275
380
|
*/
|
|
276
|
-
createResponse(
|
|
381
|
+
createResponse(
|
|
382
|
+
body: T.ResponsesRequest & { stream: true },
|
|
383
|
+
options?: StreamOptions,
|
|
384
|
+
): EventStream<T.ResponsesStreamEvent>;
|
|
385
|
+
createResponse(
|
|
386
|
+
body: T.ResponsesRequest & { stream?: false | null },
|
|
387
|
+
options?: RequestOptions,
|
|
388
|
+
): APIPromise<T.ResponsesResponse>;
|
|
389
|
+
createResponse(
|
|
390
|
+
body: T.ResponsesRequest,
|
|
391
|
+
options: StreamOptions = {},
|
|
392
|
+
): APIPromise<T.ResponsesResponse> | EventStream<T.ResponsesStreamEvent> {
|
|
393
|
+
if (body.stream) {
|
|
394
|
+
return this._client._postStream<T.ResponsesStreamEvent>(createResponseOp, { body }, options, {
|
|
395
|
+
terminal: (e) =>
|
|
396
|
+
["response.completed", "response.incomplete", "error"].includes((e as { type?: string }).type ?? ""),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
277
399
|
return this._client._call<T.ResponsesResponse>(createResponseOp, { body }, options);
|
|
278
400
|
}
|
|
279
401
|
|
|
@@ -284,31 +406,79 @@ export class InferAPI extends Namespace {
|
|
|
284
406
|
* it with only the base URL and the credential changed: set `ANTHROPIC_BASE_URL` (or `base_url`) to
|
|
285
407
|
* `https://beta-api.b3os.org/v1/infer`, the same base URL as the OpenAI SDKs (`http://127.0.0.1:7700/v1/infer`
|
|
286
408
|
* inside a sandbox; the SDKs add `/v1/messages`), and send the B3OS key as a bearer token
|
|
287
|
-
* (`ANTHROPIC_AUTH_TOKEN`, or `auth_token` in the SDKs).
|
|
288
|
-
*
|
|
289
|
-
* `thinking` (the reasoning arrives in `thinking` blocks; `budget_tokens` caps it), JSON Schema output
|
|
290
|
-
* through `output_config.format`, stop sequences, a trailing assistant turn that the model continues, and
|
|
291
|
-
* streaming events (`message_start` ... `message_stop`, exactly as Anthropic sends them). Models are those
|
|
292
|
-
* of `GET /v1/infer/models`; there is no gateway route here.
|
|
293
|
-
*
|
|
294
|
-
* Parameters this node does not take return `400 unsupported_parameter` (tools Anthropic defines or runs,
|
|
295
|
-
* such as `web_search` or `bash`, `container`, `mcp_servers`, document and file sources).
|
|
296
|
-
* `cache_control`, `citations`, `metadata`, `service_tier`, `output_config.effort` and `thinking.display`
|
|
297
|
-
* are accepted and ignored (the runtime caches prompt prefixes on its own). Errors use the Anthropic shape
|
|
298
|
-
* (`{"type": "error", "error": {...}}`, with the B3OS code under `b3os`), except those raised before the
|
|
299
|
-
* request reaches the infer service (authentication, scopes, body size), which use the OpenAI shape of the
|
|
300
|
-
* rest of `/v1/infer`; Anthropic SDKs map both by HTTP status. A stream that fails after it started ends
|
|
301
|
-
* with an `error` event; one that fails before the first token is a plain HTTP error. The response head of
|
|
302
|
-
* a stream waits for the first generated token, so `Server-Timing` can carry `ttft`.
|
|
409
|
+
* (`ANTHROPIC_AUTH_TOKEN`, or `auth_token` in the SDKs). Models are those of `GET /v1/infer/models`; there is
|
|
410
|
+
* no gateway route here. `null` means unset for every optional parameter.
|
|
303
411
|
*
|
|
304
|
-
*
|
|
305
|
-
* plus `max_tokens`, settled with the real counts; an abandoned stream is billed to its last token).
|
|
412
|
+
* **Supported**
|
|
306
413
|
*
|
|
307
|
-
*
|
|
414
|
+
* | Parameter | On this node |
|
|
415
|
+
* |---|---|
|
|
416
|
+
* | `model`, `max_tokens` | Both required; `max_tokens` caps the answer and admission reserves it |
|
|
417
|
+
* | `messages` | `text`, `image` (`base64`, or `url` sources fetched by the node through its egress guard), `tool_use`, `tool_result` and `thinking` blocks. A trailing assistant turn ending in text is continued (prefill) |
|
|
418
|
+
* | `system` | A string or text blocks, joined with blank lines |
|
|
419
|
+
* | `tools`, `tool_choice` | Custom tools (`name`, `description`, `input_schema`, `strict`; at most 128); `tool_choice` `auto`, `any`, `tool` or `none`, with `disable_parallel_tool_use` |
|
|
420
|
+
* | `thinking` | `enabled` (`budget_tokens` from 1,024 and below `max_tokens` caps the reasoning), `adaptive` (capped at `output_config.effort`'s budget, `high` by default) or `disabled`; the reasoning arrives in `thinking` blocks |
|
|
421
|
+
* | `output_config.format` | JSON Schema output (`json_schema`, at most 64 KiB serialized and 32 levels deep) |
|
|
422
|
+
* | `stop_sequences` | At most 4 |
|
|
423
|
+
* | `temperature`, `top_p`, `top_k` | Passed to the runtime (`temperature` and `top_p` from 0 to 1) |
|
|
424
|
+
* | `stream` | Streaming events (`message_start` ... `message_stop`), exactly as Anthropic sends them |
|
|
308
425
|
*
|
|
309
|
-
*
|
|
426
|
+
* **Accepted and ignored**
|
|
427
|
+
*
|
|
428
|
+
* | Parameter | Why |
|
|
429
|
+
* |---|---|
|
|
430
|
+
* | `cache_control` (on any block or tool) | The runtime caches prompt prefixes on its own, per organization |
|
|
431
|
+
* | `context_management` | The node clears nothing from the conversation; the model sees every turn you send |
|
|
432
|
+
* | `citations` (on text blocks), `metadata.user_id`, `service_tier` | No effect on this node |
|
|
433
|
+
* | `output_config.effort` | With adaptive `thinking`, the reasoning budget: `low` 256, `medium` 1,024, `high` 4,096, `xhigh` and `max` 8,192 tokens (chat's `reasoning_effort` table). No effect otherwise |
|
|
434
|
+
* | `thinking.display` | The reasoning is always returned |
|
|
435
|
+
*
|
|
436
|
+
* **Refused** (`400 unsupported_parameter`, pointing at the parameter)
|
|
437
|
+
*
|
|
438
|
+
* | Parameter | Why |
|
|
439
|
+
* |---|---|
|
|
440
|
+
* | Tools Anthropic defines or runs (`web_search`, `bash`, `code_execution`, `computer`, `text_editor` and the like) | This node runs custom tools only |
|
|
441
|
+
* | `mcp_servers`, `container` | Not available on this node |
|
|
442
|
+
* | `document` blocks and `file` sources (the Files API) | Send text, or the image as base64 or a URL |
|
|
443
|
+
* | Any other parameter | The request is closed, as Anthropic refuses extra inputs |
|
|
444
|
+
*
|
|
445
|
+
* **Errors** (Anthropic shape, `{"type": "error", "error": {"type", "message"}}`, with the B3OS code under `b3os`)
|
|
446
|
+
*
|
|
447
|
+
* | Status (`error.type`) | When |
|
|
448
|
+
* |---|---|
|
|
449
|
+
* | `400 invalid_request_error` | A malformed value (`invalid_request`), a Refused row (`unsupported_parameter`), a prompt that does not fit the context (`context_length_exceeded`), or a conversation the chat template refuses: on `b3os/qwen3.5-9b` it needs a user turn with more than `tool_result` blocks, and is not empty once empty text blocks are dropped (pointing at `messages`) |
|
|
450
|
+
* | `403 permission_error` | An image URL on a private, loopback or metadata address (`egress_denied`) |
|
|
451
|
+
* | `404 not_found_error` | The model is not served on this node (`model_not_available`) |
|
|
452
|
+
* | `429 rate_limit_error` | Over your organization's requests or tokens per minute, image bytes per minute or requests in flight (`Retry-After` says when) |
|
|
453
|
+
* | `503 overloaded_error` | The runtime is restarting or its slots are taken (`infer_backend_unavailable`, `Retry-After`) |
|
|
454
|
+
* | stream `error` event | A stream that fails after it started ends with an `error` event; one that fails before the first token is a plain HTTP error |
|
|
455
|
+
*
|
|
456
|
+
* Errors raised before the request reaches the infer service (authentication, scopes, body size, an
|
|
457
|
+
* unavailable node), on the node and at the edge, use the same Anthropic shape, so Anthropic SDKs raise the
|
|
458
|
+
* exception they would for Anthropic's own API. The response head of a stream waits for the first generated
|
|
459
|
+
* token, so `Server-Timing` can carry `ttft`. Bills input and output
|
|
460
|
+
* tokens, with the admission and limits of chat completions (the estimated prompt plus `max_tokens`, settled
|
|
461
|
+
* with the real counts; an abandoned stream is billed to its last token).
|
|
462
|
+
*
|
|
463
|
+
* `POST /v1/infer/v1/messages` · scope `infer:run` · served by the node
|
|
310
464
|
*/
|
|
311
|
-
createMessage(
|
|
465
|
+
createMessage(
|
|
466
|
+
body: T.AnthropicMessagesRequest & { stream: true },
|
|
467
|
+
options?: StreamOptions,
|
|
468
|
+
): EventStream<T.AnthropicStreamEvent>;
|
|
469
|
+
createMessage(
|
|
470
|
+
body: T.AnthropicMessagesRequest & { stream?: false | null },
|
|
471
|
+
options?: RequestOptions,
|
|
472
|
+
): APIPromise<T.AnthropicMessage>;
|
|
473
|
+
createMessage(
|
|
474
|
+
body: T.AnthropicMessagesRequest,
|
|
475
|
+
options: StreamOptions = {},
|
|
476
|
+
): APIPromise<T.AnthropicMessage> | EventStream<T.AnthropicStreamEvent> {
|
|
477
|
+
if (body.stream) {
|
|
478
|
+
return this._client._postStream<T.AnthropicStreamEvent>(createMessageOp, { body }, options, {
|
|
479
|
+
terminal: (e) => ["message_stop", "error"].includes((e as { type?: string }).type ?? ""),
|
|
480
|
+
});
|
|
481
|
+
}
|
|
312
482
|
return this._client._call<T.AnthropicMessage>(createMessageOp, { body }, options);
|
|
313
483
|
}
|
|
314
484
|
|
|
@@ -320,8 +490,6 @@ export class InferAPI extends Namespace {
|
|
|
320
490
|
* template (images included). Free: it counts against your requests per minute, not your tokens.
|
|
321
491
|
*
|
|
322
492
|
* `POST /v1/infer/v1/messages/count_tokens` · scope `infer:run` · served by the node
|
|
323
|
-
*
|
|
324
|
-
* Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
|
|
325
493
|
*/
|
|
326
494
|
countMessageTokens(
|
|
327
495
|
body: T.AnthropicCountTokensRequest,
|
package/src/generated/ns/keys.ts
CHANGED
|
@@ -24,6 +24,14 @@ const createKeyOp: Op = {
|
|
|
24
24
|
timeoutMs: 10000,
|
|
25
25
|
scope: "platform:write",
|
|
26
26
|
};
|
|
27
|
+
const revokeCurrentKeyOp: Op = {
|
|
28
|
+
id: "platformRevokeCurrentKey",
|
|
29
|
+
method: "DELETE",
|
|
30
|
+
path: "/v1/keys/current",
|
|
31
|
+
edge: true,
|
|
32
|
+
timeoutMs: 10000,
|
|
33
|
+
scope: "authenticated",
|
|
34
|
+
};
|
|
27
35
|
const getCurrentKeyOp: Op = {
|
|
28
36
|
id: "platformGetCurrentKey",
|
|
29
37
|
method: "GET",
|
|
@@ -65,6 +73,7 @@ const updateKeyOp: Op = {
|
|
|
65
73
|
export const keysOps = {
|
|
66
74
|
listKeys: listKeysOp,
|
|
67
75
|
createKey: createKeyOp,
|
|
76
|
+
revokeCurrentKey: revokeCurrentKeyOp,
|
|
68
77
|
getCurrentKey: getCurrentKeyOp,
|
|
69
78
|
revokeKey: revokeKeyOp,
|
|
70
79
|
getKey: getKeyOp,
|
|
@@ -98,11 +107,26 @@ export class KeysAPI extends Namespace {
|
|
|
98
107
|
return this._client._call<T.ApiKeyWithSecret>(createKeyOp, { body }, options);
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Revoke the calling credential
|
|
112
|
+
*
|
|
113
|
+
* Revokes the API key or CLI token that sends this request. Any key or token may revoke itself, whatever its
|
|
114
|
+
* scopes, so a key without `platform:write` can still be retired; `b3os logout` calls this. It takes effect
|
|
115
|
+
* like `DELETE /v1/keys/{key_id}` and returns the revoked key. A dashboard session is not a key: it gets
|
|
116
|
+
* `409 conflict`, so sign out instead.
|
|
117
|
+
*
|
|
118
|
+
* `DELETE /v1/keys/current` · scope `authenticated` · served by beta-api.b3os.org
|
|
119
|
+
*/
|
|
120
|
+
revokeCurrentKey(options?: RequestOptions): APIPromise<T.ApiKey> {
|
|
121
|
+
return this._client._call<T.ApiKey>(revokeCurrentKeyOp, {}, options);
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
/**
|
|
102
125
|
* Describe the calling credential
|
|
103
126
|
*
|
|
104
127
|
* Returns who is calling: the key or CLI token (or dashboard session, or sandbox), its organization and
|
|
105
|
-
* project, scopes, spend cap and expiry. Any valid credential may call
|
|
128
|
+
* project, scopes, spend cap, what it has spent this billing period and expiry. Any valid credential may call
|
|
129
|
+
* it, whatever its scopes, so a key without `platform:read` can still see how much of its cap is used.
|
|
106
130
|
*
|
|
107
131
|
* `GET /v1/keys/current` · scope `authenticated` · served by beta-api.b3os.org
|
|
108
132
|
*/
|