@earendil-works/pi-ai 1.0.4 → 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/README.md +14 -3
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +63 -22
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/bedrock-converse-stream.js +33 -2
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/classifier-shared.d.ts +21 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +98 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -1
- package/dist/api/cloudflare-workers-ai-system-one.js +2 -1
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -1
- package/dist/api/lazy.d.ts.map +1 -1
- package/dist/api/lazy.js +4 -3
- package/dist/api/lazy.js.map +1 -1
- package/dist/api/llama-cpp-classify.d.ts.map +1 -1
- package/dist/api/llama-cpp-classify.js +2 -0
- package/dist/api/llama-cpp-classify.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +31 -14
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +7 -4
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-decisions.d.ts +4 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +162 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.lazy.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +0 -1
- package/dist/api/system-one-shared.d.ts.map +1 -1
- package/dist/api/system-one-shared.js +5 -89
- package/dist/api/system-one-shared.js.map +1 -1
- package/dist/api/typesafe-system-one.d.ts.map +1 -1
- package/dist/api/typesafe-system-one.js +2 -1
- package/dist/api/typesafe-system-one.js.map +1 -1
- package/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/dist/auth/oauth/anthropic.js +14 -6
- package/dist/auth/oauth/anthropic.js.map +1 -1
- package/dist/auth/oauth/openai-chatgpt.js +1 -1
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -1
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -1
- package/dist/auth/oauth/openai-codex.js +4 -4
- package/dist/auth/oauth/openai-codex.js.map +1 -1
- package/dist/auth/types.d.ts +5 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/models.d.ts +5 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -1
- package/dist/models.js.map +1 -1
- package/dist/providers/compat-schema.d.ts +338 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +375 -0
- package/dist/providers/compat-schema.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/google-vertex.json +1 -1
- package/dist/providers/data/google.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/meta.json +1 -1
- package/dist/providers/data/minimax-cn.json +1 -1
- package/dist/providers/data/minimax.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/radius.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +25 -8
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/model-schema.d.ts +91 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +55 -0
- package/dist/providers/model-schema.js.map +1 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +12 -3
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter-api.d.ts +40 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +41 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +11 -1
- package/dist/providers/openrouter.d.ts.map +1 -1
- package/dist/providers/openrouter.js +52 -1
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/radius.d.ts.map +1 -1
- package/dist/providers/radius.js +4 -12
- package/dist/providers/radius.js.map +1 -1
- package/dist/types.d.ts +21 -304
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/estimate.js +1 -1
- package/dist/utils/estimate.js.map +1 -1
- package/dist/utils/event-stream.d.ts +10 -1
- package/dist/utils/event-stream.d.ts.map +1 -1
- package/dist/utils/event-stream.js +25 -0
- package/dist/utils/event-stream.js.map +1 -1
- package/dist/utils/model-operations.d.ts +3 -1
- package/dist/utils/model-operations.d.ts.map +1 -1
- package/dist/utils/model-operations.js +6 -0
- package/dist/utils/model-operations.js.map +1 -1
- package/dist/utils/provider-retry.d.ts +2 -0
- package/dist/utils/provider-retry.d.ts.map +1 -1
- package/dist/utils/provider-retry.js +2 -0
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +5 -2
- package/dist/utils/retry.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { type Provider } from "../models.ts";
|
|
1
|
+
import { type Provider, type RefreshModelsContext } from "../models.ts";
|
|
2
|
+
import type { AnyModel } from "../types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Restrict an OpenRouter catalog to the chat models the key may use, with the key's limits and
|
|
5
|
+
* prices from `GET /models/user`. Image and classifier models are returned unchanged. A missing
|
|
6
|
+
* limit keeps the catalog value. The request uses the provider's configured base URL, so regional
|
|
7
|
+
* endpoints such as `https://us.openrouter.ai/api/v1` apply their region's filtering. When the
|
|
8
|
+
* endpoint rejects the key (401/403) or does not exist (404), for example with a proxy configured
|
|
9
|
+
* in models.json, the catalog is returned unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function personalizeOpenRouterCatalog(catalog: readonly AnyModel[], context: RefreshModelsContext): Promise<readonly AnyModel[]>;
|
|
2
12
|
export declare function openrouterProvider(): Provider<"anthropic-messages" | "openai-completions">;
|
|
3
13
|
//# sourceMappingURL=openrouter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../src/providers/openrouter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../src/providers/openrouter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ5C;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CACjD,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,SAAS,QAAQ,EAAE,CAAC,CAiC9B;AAED,wBAAgB,kBAAkB,IAAI,QAAQ,CAAC,oBAAoB,GAAG,oBAAoB,CAAC,CA0B1F"}
|
|
@@ -5,12 +5,63 @@ import { typesafeSystemOneApi } from "../api/typesafe-system-one.lazy.js";
|
|
|
5
5
|
import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.js";
|
|
6
6
|
import { loadOpenRouterOAuth } from "../auth/oauth/load.js";
|
|
7
7
|
import { createProvider } from "../models.js";
|
|
8
|
+
import { isModelType } from "../utils/model-operations.js";
|
|
8
9
|
import { OPENROUTER_CLASSIFIER_MODELS, OPENROUTER_IMAGE_MODELS, OPENROUTER_MODELS } from "./openrouter.models.js";
|
|
10
|
+
import { openRouterCost } from "./openrouter-api.js";
|
|
11
|
+
const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
12
|
+
const OPENROUTER_USER_MODELS_TIMEOUT_MS = 15_000;
|
|
13
|
+
/**
|
|
14
|
+
* Restrict an OpenRouter catalog to the chat models the key may use, with the key's limits and
|
|
15
|
+
* prices from `GET /models/user`. Image and classifier models are returned unchanged. A missing
|
|
16
|
+
* limit keeps the catalog value. The request uses the provider's configured base URL, so regional
|
|
17
|
+
* endpoints such as `https://us.openrouter.ai/api/v1` apply their region's filtering. When the
|
|
18
|
+
* endpoint rejects the key (401/403) or does not exist (404), for example with a proxy configured
|
|
19
|
+
* in models.json, the catalog is returned unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export async function personalizeOpenRouterCatalog(catalog, context) {
|
|
22
|
+
const key = context.credential?.type === "oauth" ? context.credential.access : context.credential?.key;
|
|
23
|
+
if (!key)
|
|
24
|
+
return catalog;
|
|
25
|
+
const response = await fetch(`${(context.baseUrl ?? OPENROUTER_BASE_URL).replace(/\/+$/, "")}/models/user`, {
|
|
26
|
+
headers: { accept: "application/json", authorization: `Bearer ${key}` },
|
|
27
|
+
signal: AbortSignal.any([context.signal, AbortSignal.timeout(OPENROUTER_USER_MODELS_TIMEOUT_MS)]),
|
|
28
|
+
});
|
|
29
|
+
if (response.status === 401 || response.status === 403 || response.status === 404)
|
|
30
|
+
return catalog;
|
|
31
|
+
if (!response.ok)
|
|
32
|
+
throw new Error(`OpenRouter model list request failed: ${response.status}`);
|
|
33
|
+
const body = await response.json();
|
|
34
|
+
if (typeof body !== "object" || body === null || !("data" in body) || !Array.isArray(body.data)) {
|
|
35
|
+
throw new Error("Invalid OpenRouter model list response");
|
|
36
|
+
}
|
|
37
|
+
const allowed = new Map();
|
|
38
|
+
for (const entry of body.data) {
|
|
39
|
+
if (typeof entry === "object" && entry !== null && "id" in entry && typeof entry.id === "string") {
|
|
40
|
+
allowed.set(entry.id, entry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return catalog.flatMap((model) => {
|
|
44
|
+
if (!isModelType(model, "chat"))
|
|
45
|
+
return [model];
|
|
46
|
+
const entry = allowed.get(model.id);
|
|
47
|
+
if (!entry)
|
|
48
|
+
return [];
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
...model,
|
|
52
|
+
// `||`: OpenRouter reports a missing limit as absent, null or 0, like the generator's fallback.
|
|
53
|
+
contextWindow: entry.top_provider?.context_length || entry.context_length || model.contextWindow,
|
|
54
|
+
maxTokens: entry.top_provider?.max_completion_tokens || model.maxTokens,
|
|
55
|
+
cost: entry.pricing ? openRouterCost(entry.pricing) : model.cost,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
9
60
|
export function openrouterProvider() {
|
|
10
61
|
return createProvider({
|
|
11
62
|
id: "openrouter",
|
|
12
63
|
name: "OpenRouter",
|
|
13
|
-
baseUrl:
|
|
64
|
+
baseUrl: OPENROUTER_BASE_URL,
|
|
14
65
|
auth: {
|
|
15
66
|
apiKey: envApiKeyAuth("OpenRouter API key", ["OPENROUTER_API_KEY"]),
|
|
16
67
|
oauth: lazyOAuth({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../../src/providers/openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC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BAAuB,CAAC;YACzC,GAAG,MAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC;SAC9C;QACD,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,oBAAoB,EAAE,oBAAoB,EAAE;SAC5C;QACD,MAAM,EAAE,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,EAAE;QACtD,yEAAyE;QACzE,WAAW,EAAE,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,EAAE;KAC9D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { anthropicMessagesApi } from \"../api/anthropic-messages.lazy.ts\";\nimport { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openrouterImagesApi } from \"../api/openrouter-images.lazy.ts\";\nimport { typesafeSystemOneApi } from \"../api/typesafe-system-one.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadOpenRouterOAuth } from \"../auth/oauth/load.ts\";\nimport { createProvider, type Provider, type RefreshModelsContext } from \"../models.ts\";\nimport type { AnyModel } from \"../types.ts\";\nimport { isModelType } from \"../utils/model-operations.ts\";\nimport { OPENROUTER_CLASSIFIER_MODELS, OPENROUTER_IMAGE_MODELS, OPENROUTER_MODELS } from \"./openrouter.models.ts\";\nimport { type OpenRouterModel, openRouterCost } from \"./openrouter-api.ts\";\n\nconst OPENROUTER_BASE_URL = \"https://openrouter.ai/api/v1\";\nconst OPENROUTER_USER_MODELS_TIMEOUT_MS = 15_000;\n\n/**\n * Restrict an OpenRouter catalog to the chat models the key may use, with the key's limits and\n * prices from `GET /models/user`. Image and classifier models are returned unchanged. A missing\n * limit keeps the catalog value. The request uses the provider's configured base URL, so regional\n * endpoints such as `https://us.openrouter.ai/api/v1` apply their region's filtering. When the\n * endpoint rejects the key (401/403) or does not exist (404), for example with a proxy configured\n * in models.json, the catalog is returned unchanged.\n */\nexport async function personalizeOpenRouterCatalog(\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n): Promise<readonly AnyModel[]> {\n\tconst key = context.credential?.type === \"oauth\" ? context.credential.access : context.credential?.key;\n\tif (!key) return catalog;\n\tconst response = await fetch(`${(context.baseUrl ?? OPENROUTER_BASE_URL).replace(/\\/+$/, \"\")}/models/user`, {\n\t\theaders: { accept: \"application/json\", authorization: `Bearer ${key}` },\n\t\tsignal: AbortSignal.any([context.signal, AbortSignal.timeout(OPENROUTER_USER_MODELS_TIMEOUT_MS)]),\n\t});\n\tif (response.status === 401 || response.status === 403 || response.status === 404) return catalog;\n\tif (!response.ok) throw new Error(`OpenRouter model list request failed: ${response.status}`);\n\tconst body: unknown = await response.json();\n\tif (typeof body !== \"object\" || body === null || !(\"data\" in body) || !Array.isArray(body.data)) {\n\t\tthrow new Error(\"Invalid OpenRouter model list response\");\n\t}\n\tconst allowed = new Map<string, OpenRouterModel>();\n\tfor (const entry of body.data as unknown[]) {\n\t\tif (typeof entry === \"object\" && entry !== null && \"id\" in entry && typeof entry.id === \"string\") {\n\t\t\tallowed.set(entry.id, entry as OpenRouterModel);\n\t\t}\n\t}\n\treturn catalog.flatMap((model): AnyModel[] => {\n\t\tif (!isModelType(model, \"chat\")) return [model];\n\t\tconst entry = allowed.get(model.id);\n\t\tif (!entry) return [];\n\t\treturn [\n\t\t\t{\n\t\t\t\t...model,\n\t\t\t\t// `||`: OpenRouter reports a missing limit as absent, null or 0, like the generator's fallback.\n\t\t\t\tcontextWindow: entry.top_provider?.context_length || entry.context_length || model.contextWindow,\n\t\t\t\tmaxTokens: entry.top_provider?.max_completion_tokens || model.maxTokens,\n\t\t\t\tcost: entry.pricing ? openRouterCost(entry.pricing) : model.cost,\n\t\t\t},\n\t\t];\n\t});\n}\n\nexport function openrouterProvider(): Provider<\"anthropic-messages\" | \"openai-completions\"> {\n\treturn createProvider<\"anthropic-messages\" | \"openai-completions\">({\n\t\tid: \"openrouter\",\n\t\tname: \"OpenRouter\",\n\t\tbaseUrl: OPENROUTER_BASE_URL,\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"OpenRouter API key\", [\"OPENROUTER_API_KEY\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"OpenRouter OAuth\",\n\t\t\t\tloginLabel: \"Sign in with OpenRouter\",\n\t\t\t\tload: loadOpenRouterOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: [\n\t\t\t...Object.values(OPENROUTER_MODELS),\n\t\t\t...Object.values(OPENROUTER_IMAGE_MODELS),\n\t\t\t...Object.values(OPENROUTER_CLASSIFIER_MODELS),\n\t\t],\n\t\tapi: {\n\t\t\t\"anthropic-messages\": anthropicMessagesApi(),\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t},\n\t\timages: { \"openrouter-images\": openrouterImagesApi() },\n\t\t// OpenRouter serves TypeSafe's System One protocol at /api/v1/systemone.\n\t\tclassifiers: { \"typesafe-system-one\": typesafeSystemOneApi() },\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radius.d.ts","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAW7C,MAAM,WAAW,qBAAqB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"radius.d.ts","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAW7C,MAAM,WAAW,qBAAqB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,aAAa,CAAC,CAoE3F"}
|
package/dist/providers/radius.js
CHANGED
|
@@ -11,7 +11,9 @@ export function radiusProvider(options = {}) {
|
|
|
11
11
|
const baselineModels = gateway === normalizeRadiusGatewayUrl(DEFAULT_RADIUS_GATEWAY)
|
|
12
12
|
? Object.values(RADIUS_MODELS).map((model) => ({ ...model, provider: id }))
|
|
13
13
|
: [];
|
|
14
|
-
|
|
14
|
+
// Gateway catalog for this account. Radius org owners can disable models, so once known it replaces
|
|
15
|
+
// the shipped baseline instead of overlaying it. The baseline only covers the time before any catalog exists.
|
|
16
|
+
let dynamicModels;
|
|
15
17
|
const streams = piMessagesApi();
|
|
16
18
|
return {
|
|
17
19
|
id,
|
|
@@ -20,17 +22,7 @@ export function radiusProvider(options = {}) {
|
|
|
20
22
|
apiKey: envApiKeyAuth("Radius API key", ["RADIUS_API_KEY"]),
|
|
21
23
|
oauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),
|
|
22
24
|
},
|
|
23
|
-
getModels: () =>
|
|
24
|
-
const merged = [...baselineModels];
|
|
25
|
-
for (const model of dynamicModels) {
|
|
26
|
-
const index = merged.findIndex((entry) => entry.id === model.id);
|
|
27
|
-
if (index >= 0)
|
|
28
|
-
merged[index] = model;
|
|
29
|
-
else
|
|
30
|
-
merged.push(model);
|
|
31
|
-
}
|
|
32
|
-
return merged;
|
|
33
|
-
},
|
|
25
|
+
getModels: () => dynamicModels ?? baselineModels,
|
|
34
26
|
refreshModels: async (context) => {
|
|
35
27
|
const stored = context.stored;
|
|
36
28
|
if (stored) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radius.js","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,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AAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;gBACrD,MAAM,EAAE,GAAG,EAAE;oBACZ,aAAa,GAAG,SAAS,CAAC;gBAC3B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC;QACxF,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC;KACpG,CAAC;AACH,CAAC","sourcesContent":["import { piMessagesApi } from \"../api/pi-messages.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadRadiusOAuth } from \"../auth/oauth/load.ts\";\nimport type { Provider } from \"../models.ts\";\nimport type { Model } from \"../types.ts\";\nimport { RADIUS_MODELS } from \"./radius.models.ts\";\nimport {\n\tDEFAULT_RADIUS_GATEWAY,\n\tgetRadiusModels,\n\tgetRadiusModelsFromConfig,\n\tloadRadiusGatewayConfig,\n\tnormalizeRadiusGatewayUrl,\n} from \"./radius-config.ts\";\n\nexport interface RadiusProviderOptions {\n\tid?: string;\n\tname?: string;\n\tgateway?: string;\n}\n\n/** Radius gateway provider with a persisted, dynamically refreshed catalog. */\nexport function radiusProvider(options: RadiusProviderOptions = {}): Provider<\"pi-messages\"> {\n\tconst id = options.id ?? \"radius\";\n\tconst name = options.name ?? \"Radius\";\n\tconst gateway = normalizeRadiusGatewayUrl(options.gateway ?? DEFAULT_RADIUS_GATEWAY);\n\tconst baselineModels: Model<\"pi-messages\">[] =\n\t\tgateway === normalizeRadiusGatewayUrl(DEFAULT_RADIUS_GATEWAY)\n\t\t\t? Object.values(RADIUS_MODELS).map((model) => ({ ...model, provider: id }))\n\t\t\t: [];\n\t// Gateway catalog for this account. Radius org owners can disable models, so once known it replaces\n\t// the shipped baseline instead of overlaying it. The baseline only covers the time before any catalog exists.\n\tlet dynamicModels: Model<\"pi-messages\">[] | undefined;\n\tconst streams = piMessagesApi();\n\n\treturn {\n\t\tid,\n\t\tname,\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Radius API key\", [\"RADIUS_API_KEY\"]),\n\t\t\toauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),\n\t\t},\n\t\tgetModels: () => dynamicModels ?? baselineModels,\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tif (stored) {\n\t\t\t\tconst restored = stored.models.filter((model) => model.provider === id) as Model<\"pi-messages\">[];\n\t\t\t\tif (\n\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Import catalogs cached by the pre-ModelsStore Radius implementation.\n\t\t\tif (!stored && context.credential?.type === \"oauth\") {\n\t\t\t\tconst legacy = getRadiusModels(id, context.credential);\n\t\t\t\tif (legacy.length > 0) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\t\tpersist: { models: legacy, checkedAt: Date.now() },\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tdynamicModels = legacy;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}))\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tconst apiKey = context.credential?.type === \"oauth\" ? context.credential.access : context.credential?.key;\n\t\t\tconst config = await loadRadiusGatewayConfig(gateway, apiKey, context.signal);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst refreshed = getRadiusModelsFromConfig(id, config);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = refreshed;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tstream: (model, context, streamOptions) => streams.stream(model, context, streamOptions),\n\t\tstreamSimple: (model, context, streamOptions) => streams.streamSimple(model, context, streamOptions),\n\t};\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,29 +9,24 @@ import type { OpenAICodexResponsesOptions } from "./api/openai-codex-responses.t
|
|
|
9
9
|
import type { OpenAICompletionsOptions } from "./api/openai-completions.ts";
|
|
10
10
|
import type { OpenAIResponsesOptions } from "./api/openai-responses.ts";
|
|
11
11
|
import type { PiMessagesOptions } from "./api/pi-messages.ts";
|
|
12
|
+
import type { AnthropicMessagesCompat, BedrockCompat, MistralConversationsCompat, OpenAICompletionsCompat, OpenAIResponsesCompat } from "./providers/compat-schema.ts";
|
|
13
|
+
import type { CacheRetention, ModelCost, ModelInputLimits, ModelInputModality, ModelPromptCache, ModelThinkingLevel, ThinkingLevel, ThinkingLevelMap } from "./providers/model-schema.ts";
|
|
12
14
|
import type { AssistantMessageDiagnostic } from "./utils/diagnostics.ts";
|
|
13
15
|
import type { AssistantMessageEventStream } from "./utils/event-stream.ts";
|
|
16
|
+
export type { AnthropicAllowedFallbackModel, AnthropicMessagesCompat, BedrockCompat, ChatTemplateKwargValue, MistralConversationsCompat, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenRouterRouting, SessionAffinityFormat, ThinkingTokenBudgetField, VercelGatewayRouting, } from "./providers/compat-schema.ts";
|
|
17
|
+
export type { CacheRetention, ModelCost, ModelCostRates, ModelCostTier, ModelImageInputLimits, ModelImageResizeOptions, ModelInputLimits, ModelInputModality, ModelPromptCache, ModelThinkingLevel, ThinkingLevel, ThinkingLevelMap, } from "./providers/model-schema.ts";
|
|
14
18
|
export type { AssistantMessageEventStream } from "./utils/event-stream.ts";
|
|
15
19
|
export type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-codex-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex" | "pi-messages";
|
|
16
20
|
export type Api = KnownApi | (string & {});
|
|
17
21
|
export type KnownImageApi = "openrouter-images";
|
|
18
22
|
export type ImageApi = KnownImageApi | (string & {});
|
|
19
|
-
export type KnownClassifierApi = "typesafe-system-one" | "cloudflare-workers-ai-system-one" | "llama-cpp-classify";
|
|
23
|
+
export type KnownClassifierApi = "typesafe-system-one" | "cloudflare-workers-ai-system-one" | "llama-cpp-classify" | "openai-decisions";
|
|
20
24
|
export type ClassifierApi = KnownClassifierApi | (string & {});
|
|
21
25
|
export type KnownProvider = "amazon-bedrock" | "ant-ling" | "anthropic" | "google" | "google-vertex" | "openai" | "azure" | "openai-codex" | "radius" | "typesafe" | "nvidia" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "zai-coding-cn" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "together" | "baseten" | "opencode" | "opencode-go" | "kimi-coding" | "meta" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "qwen-token-plan" | "qwen-token-plan-cn" | "qwen-token-plan-individual" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
|
|
22
26
|
export type ProviderId = KnownProvider | string;
|
|
23
27
|
export type ToolChoice = "auto" | "none";
|
|
24
|
-
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
25
|
-
export type ModelThinkingLevel = "off" | ThinkingLevel;
|
|
26
|
-
export type ThinkingLevelMap = Partial<Record<ModelThinkingLevel, string | null>>;
|
|
27
28
|
export type SamplingParams = Record<string, unknown>;
|
|
28
29
|
export type SamplingParamsByThinkingLevel = Partial<Record<ModelThinkingLevel, SamplingParams>>;
|
|
29
|
-
export type ChatTemplateKwargValue = string | number | boolean | null | {
|
|
30
|
-
$var: "thinking.enabled" | "thinking.effort" | "thinking.budget";
|
|
31
|
-
omitWhenOff?: boolean;
|
|
32
|
-
};
|
|
33
|
-
/** Top-level request field used to cap reasoning tokens on OpenAI-compatible servers. */
|
|
34
|
-
export type ThinkingTokenBudgetField = "thinking_token_budget" | "thinking_budget" | "thinking_budget_tokens";
|
|
35
30
|
/** Token budgets for each thinking level (token-based providers only) */
|
|
36
31
|
export interface ThinkingBudgets {
|
|
37
32
|
minimal?: number;
|
|
@@ -39,18 +34,11 @@ export interface ThinkingBudgets {
|
|
|
39
34
|
medium?: number;
|
|
40
35
|
high?: number;
|
|
41
36
|
}
|
|
42
|
-
export type CacheRetention = "none" | "short" | "long";
|
|
43
|
-
/**
|
|
44
|
-
* Best-effort prompt cache lifetime in seconds for each retention tier a request can ask for.
|
|
45
|
-
* A missing tier means the lifetime is unknown; pi does not warm such caches.
|
|
46
|
-
*/
|
|
47
|
-
export type ModelPromptCache = Partial<Record<Exclude<CacheRetention, "none">, number>>;
|
|
48
37
|
export type Transport = "sse" | "websocket" | "websocket-cached" | "auto";
|
|
49
38
|
/** Provider-scoped environment overrides. Values take precedence over process.env. */
|
|
50
39
|
export type ProviderEnv = Record<string, string>;
|
|
51
40
|
export type ProviderHeaders = Record<string, string | null>;
|
|
52
41
|
export type FetchFunction = typeof globalThis.fetch;
|
|
53
|
-
export type SessionAffinityFormat = "openai" | "openai-nosession" | "openrouter";
|
|
54
42
|
export interface ProviderResponse {
|
|
55
43
|
status: number;
|
|
56
44
|
headers: Record<string, string>;
|
|
@@ -236,11 +224,6 @@ export interface ImagesOptions extends ProviderRequestOptions<ImageModel<ImageAp
|
|
|
236
224
|
metadata?: Record<string, unknown>;
|
|
237
225
|
}
|
|
238
226
|
export type ProviderImagesOptions = ImagesOptions & Record<string, unknown>;
|
|
239
|
-
export interface AnthropicAllowedFallbackModel {
|
|
240
|
-
provider: ProviderId;
|
|
241
|
-
model: string;
|
|
242
|
-
cost: ModelCost;
|
|
243
|
-
}
|
|
244
227
|
export interface SimpleStreamOptions extends StreamOptions {
|
|
245
228
|
/** Provider-neutral tool selection for simple requests. When omitted, adapters use provider-specific behavior. */
|
|
246
229
|
toolChoice?: ToolChoice;
|
|
@@ -394,7 +377,14 @@ export interface AssistantMessage {
|
|
|
394
377
|
* Preserved for debugging and does not currently affect agent control flow.
|
|
395
378
|
*/
|
|
396
379
|
endTurn?: boolean;
|
|
380
|
+
/** Unix timestamp in milliseconds when the request started. */
|
|
397
381
|
timestamp: number;
|
|
382
|
+
/**
|
|
383
|
+
* Milliseconds from `timestamp` until the response ended, measured with a monotonic clock. Set by
|
|
384
|
+
* `AssistantMessageEventStream` on the final message of a response it saw start; absent for legacy messages and
|
|
385
|
+
* for deferred results fetched later.
|
|
386
|
+
*/
|
|
387
|
+
durationMs?: number;
|
|
398
388
|
}
|
|
399
389
|
/** A tool call that another tool made while it ran, for example from a codemode script. */
|
|
400
390
|
export interface NestedToolCallRecord {
|
|
@@ -427,7 +417,10 @@ export type ToolResultMessage<TDetails = JsonValue> = IsJsonCompatible<TDetails>
|
|
|
427
417
|
/** Calls this tool made to other tools. Kept for the session record; not sent to the model. */
|
|
428
418
|
nestedCalls?: NestedToolCalls;
|
|
429
419
|
isError: boolean;
|
|
420
|
+
/** Unix timestamp in milliseconds when the result was created. */
|
|
430
421
|
timestamp: number;
|
|
422
|
+
/** Milliseconds the tool's execution took, measured with a monotonic clock. Absent for legacy results. */
|
|
423
|
+
durationMs?: number;
|
|
431
424
|
} : never;
|
|
432
425
|
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolResultMessage;
|
|
433
426
|
export type ImagesInputContent = TextContent | ImageContent;
|
|
@@ -468,6 +461,11 @@ export interface ClassifierBoolQuestion {
|
|
|
468
461
|
export type ClassifierQuestion = ClassifierChoiceQuestion | ClassifierScoreQuestion | ClassifierBoolQuestion;
|
|
469
462
|
export interface ClassifierContext {
|
|
470
463
|
state: JsonObject;
|
|
464
|
+
/**
|
|
465
|
+
* Images judged together with `state`. Only models whose `input` includes `"image"` accept them;
|
|
466
|
+
* other models return an error result.
|
|
467
|
+
*/
|
|
468
|
+
images?: ImageContent[];
|
|
471
469
|
questions: Record<string, ClassifierQuestion>;
|
|
472
470
|
}
|
|
473
471
|
export interface ClassifierChoiceAnswer {
|
|
@@ -617,287 +615,6 @@ export type AssistantMessageEvent = {
|
|
|
617
615
|
reason: Extract<StopReason, "aborted" | "error">;
|
|
618
616
|
error: AssistantMessage;
|
|
619
617
|
};
|
|
620
|
-
/**
|
|
621
|
-
* Compatibility settings for OpenAI-compatible completions APIs.
|
|
622
|
-
* Use this to override URL-based auto-detection for custom providers.
|
|
623
|
-
*/
|
|
624
|
-
export interface OpenAICompletionsCompat {
|
|
625
|
-
/** Whether the provider supports the `store` field. Default: auto-detected from URL. */
|
|
626
|
-
supportsStore?: boolean;
|
|
627
|
-
/** Whether the provider supports the `developer` role (vs `system`). Default: auto-detected from URL. */
|
|
628
|
-
supportsDeveloperRole?: boolean;
|
|
629
|
-
/** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */
|
|
630
|
-
supportsReasoningEffort?: boolean;
|
|
631
|
-
/** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */
|
|
632
|
-
supportsUsageInStreaming?: boolean;
|
|
633
|
-
/** Whether streamed responses include `finish_reason`. When false, pi infers `stop` or `toolUse` when the stream ends. Default: true. */
|
|
634
|
-
supportsFinishReason?: boolean;
|
|
635
|
-
/** Which field to use for max tokens. Default: auto-detected from URL. */
|
|
636
|
-
maxTokensField?: "max_completion_tokens" | "max_tokens";
|
|
637
|
-
/** Whether tool results require the `name` field. Default: auto-detected from URL. */
|
|
638
|
-
requiresToolResultName?: boolean;
|
|
639
|
-
/** Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL. */
|
|
640
|
-
requiresAssistantAfterToolResult?: boolean;
|
|
641
|
-
/** Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL. */
|
|
642
|
-
requiresThinkingAsText?: boolean;
|
|
643
|
-
/** Whether all replayed assistant messages must include an empty reasoning_content field when reasoning is enabled. Default: auto-detected from URL. */
|
|
644
|
-
requiresReasoningContentOnAssistantMessages?: boolean;
|
|
645
|
-
/** Format for reasoning/thinking parameter. "openai" uses reasoning_effort, "openrouter" uses reasoning: { effort }, "deepseek" uses thinking: { type } plus reasoning_effort when supported, "together" uses reasoning: { enabled } plus reasoning_effort when supported, "baseten" uses configurable chat_template_args plus reasoning_effort when supported, "zai" uses thinking: { type }, "qwen" uses top-level enable_thinking: boolean, "qwen-chat-template" uses chat_template_kwargs.enable_thinking and preserve_thinking, "chat-template" uses configurable chat_template_kwargs, "string-thinking" uses top-level thinking: string, and "ant-ling" uses reasoning: { effort } only when the mapped effort is non-null. Default: "openai". */
|
|
646
|
-
thinkingFormat?: "openai" | "openrouter" | "deepseek" | "together" | "baseten" | "zai" | "qwen" | "chat-template" | "qwen-chat-template" | "string-thinking" | "ant-ling";
|
|
647
|
-
/** Kwargs to send as `chat_template_kwargs` when `thinkingFormat` is `chat-template`. Use `{ "$var": "thinking.enabled" }`, `{ "$var": "thinking.effort" }`, or `{ "$var": "thinking.budget" }` for pi-controlled thinking values. */
|
|
648
|
-
chatTemplateKwargs?: Record<string, ChatTemplateKwargValue>;
|
|
649
|
-
/** Arguments to send as `chat_template_args` when `thinkingFormat` is `baseten`. Use `{ "$var": "thinking.enabled" }`, `{ "$var": "thinking.effort" }`, or `{ "$var": "thinking.budget" }` for pi-controlled thinking values. */
|
|
650
|
-
chatTemplateArgs?: Record<string, ChatTemplateKwargValue>;
|
|
651
|
-
/** OpenRouter-compatible routing preferences sent as the `provider` request field. */
|
|
652
|
-
openRouterRouting?: OpenRouterRouting;
|
|
653
|
-
/** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */
|
|
654
|
-
vercelGatewayRouting?: VercelGatewayRouting;
|
|
655
|
-
/** Whether z.ai supports top-level `tool_stream: true` for streaming tool call deltas. Default: false. */
|
|
656
|
-
zaiToolStream?: boolean;
|
|
657
|
-
/**
|
|
658
|
-
* Top-level request field used to cap reasoning tokens from `thinkingBudgets`.
|
|
659
|
-
* Reasoning and the answer share `max_tokens` on these endpoints, so without a budget a
|
|
660
|
-
* reasoning-heavy turn can consume the whole response and emit no answer.
|
|
661
|
-
* `"thinking_token_budget"` is vLLM, `"thinking_budget"` is Qwen/DashScope/SGLang,
|
|
662
|
-
* `"thinking_budget_tokens"` is llama.cpp. Off by default; not set on the generated catalog.
|
|
663
|
-
*/
|
|
664
|
-
thinkingTokenBudgetField?: ThinkingTokenBudgetField;
|
|
665
|
-
/** Alias for `thinkingTokenBudgetField: "thinking_token_budget"` (vLLM). Prefer `thinkingTokenBudgetField`. Default: false. */
|
|
666
|
-
supportsThinkingTokenBudget?: boolean;
|
|
667
|
-
/** Whether the provider supports OpenAI custom tools with Lark/regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. Default: false; the generated model catalog enables it for capable models. */
|
|
668
|
-
supportsOpenAIGrammarTools?: boolean;
|
|
669
|
-
/** Whether the exact model accepts system or developer messages after the conversation has started. When false, later system messages are folded into the leading system message. Default: false; the generated model catalog enables it for verified models. */
|
|
670
|
-
supportsMidConvoSystemMessages?: boolean;
|
|
671
|
-
/** Whether system messages can introduce additional tools mid-conversation. Requires `supportsMidConvoSystemMessages`. Default: false; the generated model catalog enables it for capable models. */
|
|
672
|
-
supportsMidConvoToolAdditions?: boolean;
|
|
673
|
-
/** Whether the provider supports the `strict` field in tool definitions. Default: false; generated capable models enable it explicitly. */
|
|
674
|
-
supportsStrictMode?: boolean;
|
|
675
|
-
/** Cache control convention for prompt caching. "anthropic" applies Anthropic-style `cache_control` markers to the system prompt, last tool definition, and last user, assistant, or tool-result text content. */
|
|
676
|
-
cacheControlFormat?: "anthropic";
|
|
677
|
-
/** Whether to send session-affinity data from `options.sessionId`. Default: true for OpenRouter endpoints, false otherwise. */
|
|
678
|
-
sendSessionAffinityHeaders?: boolean;
|
|
679
|
-
/** Session-affinity header format: `openai` sends `session_id`, `x-client-request-id`, and `x-session-affinity`; `openai-nosession` sends `x-client-request-id` and `x-session-affinity`; `openrouter` sends `x-session-id`. Does not affect the `prompt_cache_key` body param, which is governed by cache retention. Default: auto-detected. */
|
|
680
|
-
sessionAffinityFormat?: SessionAffinityFormat;
|
|
681
|
-
/** Whether the provider supports long prompt cache retention (`prompt_cache_retention: "24h"` or Anthropic-style `cache_control.ttl: "1h"`, depending on format). Default: true. */
|
|
682
|
-
supportsLongCacheRetention?: boolean;
|
|
683
|
-
/**
|
|
684
|
-
* vLLM scheduler priority sent as the top-level `priority` request field (lower values are
|
|
685
|
-
* handled earlier; server default 0). Only meaningful when vLLM runs with
|
|
686
|
-
* `--scheduling-policy priority`; useful for keeping background/batch work from stalling
|
|
687
|
-
* interactive sessions. Off by default; not set on the generated catalog.
|
|
688
|
-
*/
|
|
689
|
-
vllmPriority?: number;
|
|
690
|
-
}
|
|
691
|
-
/** Compatibility settings for OpenAI Responses APIs. */
|
|
692
|
-
export interface OpenAIResponsesCompat {
|
|
693
|
-
/** Whether the provider supports the `developer` role (vs `system`). Default: true. */
|
|
694
|
-
supportsDeveloperRole?: boolean;
|
|
695
|
-
/** Whether the exact model accepts developer or system messages after the conversation has started. When false, later system messages are folded into the leading system message. Default: false; the generated model catalog enables it for verified models. */
|
|
696
|
-
supportsMidConvoSystemMessages?: boolean;
|
|
697
|
-
/** Session-affinity header format: `openai` sends `session_id` and `x-client-request-id`; `openai-nosession` sends `x-client-request-id`; `openrouter` sends `x-session-id`. Does not affect the `prompt_cache_key` body param, which is governed by cache retention. Default: auto-detected. */
|
|
698
|
-
sessionAffinityFormat?: SessionAffinityFormat;
|
|
699
|
-
/** Whether the provider supports long prompt cache retention. This uses `prompt_cache_options.ttl: "30m"` on GPT-5.6+ and `prompt_cache_retention: "24h"` on earlier models. Default: true. */
|
|
700
|
-
supportsLongCacheRetention?: boolean;
|
|
701
|
-
/** Whether the provider supports strict JSON-schema function tools. Defaults are API-specific; generated OpenAI models enable it explicitly. */
|
|
702
|
-
supportsStrictMode?: boolean;
|
|
703
|
-
/** Whether to emit OpenAI custom tools with Lark/regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. Default: false; the generated model catalog enables it for capable models. */
|
|
704
|
-
supportsOpenAIGrammarTools?: boolean;
|
|
705
|
-
/** Whether the model supports message-anchored `additional_tools` input items. Default: false. */
|
|
706
|
-
supportsAdditionalTools?: boolean;
|
|
707
|
-
/** Whether the model supports client-executed tool search for transcript-anchored additions. Default: false. */
|
|
708
|
-
supportsToolSearch?: boolean;
|
|
709
|
-
/** Whether the model accepts `prompt_cache_options` (OpenAI GPT-5.6+ prompt caching). Older OpenAI models reject the parameter. Default: false. */
|
|
710
|
-
supportsExplicitPromptCacheMode?: boolean;
|
|
711
|
-
/** Whether the provider accepts the `max_output_tokens` parameter. Some Codex-protocol gateways reject it. Default: true. */
|
|
712
|
-
supportsMaxOutputTokens?: boolean;
|
|
713
|
-
}
|
|
714
|
-
/** Compatibility settings for Anthropic Messages-compatible APIs. */
|
|
715
|
-
export interface AnthropicMessagesCompat {
|
|
716
|
-
/**
|
|
717
|
-
* Whether the provider accepts per-tool `eager_input_streaming`.
|
|
718
|
-
* When false, the Anthropic provider omits `tools[].eager_input_streaming`
|
|
719
|
-
* and sends the legacy `fine-grained-tool-streaming-2025-05-14` beta header
|
|
720
|
-
* for tool-enabled requests.
|
|
721
|
-
* Default: true.
|
|
722
|
-
*/
|
|
723
|
-
supportsEagerToolInputStreaming?: boolean;
|
|
724
|
-
/** Whether the provider supports Anthropic long cache retention (`cache_control.ttl: "1h"`). Default: true. */
|
|
725
|
-
supportsLongCacheRetention?: boolean;
|
|
726
|
-
/**
|
|
727
|
-
* Whether to send the `x-session-affinity` header from `options.sessionId`
|
|
728
|
-
* when caching is enabled. Required for providers like Fireworks that use
|
|
729
|
-
* session affinity for prompt cache routing (requests to the same replica
|
|
730
|
-
* maximize cache hits).
|
|
731
|
-
* Default: false.
|
|
732
|
-
*/
|
|
733
|
-
sendSessionAffinityHeaders?: boolean;
|
|
734
|
-
/** Session-affinity format. `"openrouter"` sends `x-session-id`; when unset, sends `x-session-affinity`. */
|
|
735
|
-
sessionAffinityFormat?: "openrouter";
|
|
736
|
-
/**
|
|
737
|
-
* Whether the provider supports Anthropic-style `cache_control` markers on
|
|
738
|
-
* tool definitions. When false, `cache_control` is omitted from tool params.
|
|
739
|
-
* Some Anthropic-compatible providers (e.g., Fireworks) do not support this
|
|
740
|
-
* field on tools and may reject or ignore it.
|
|
741
|
-
* Default: true.
|
|
742
|
-
*/
|
|
743
|
-
supportsCacheControlOnTools?: boolean;
|
|
744
|
-
/**
|
|
745
|
-
* Whether the model accepts the Anthropic `temperature` request field.
|
|
746
|
-
* Claude Opus 4.7+ rejects non-default temperature values.
|
|
747
|
-
* Default: true.
|
|
748
|
-
*/
|
|
749
|
-
supportsTemperature?: boolean;
|
|
750
|
-
/**
|
|
751
|
-
* Whether to force adaptive thinking (`thinking.type: "adaptive"` plus
|
|
752
|
-
* `output_config.effort`) regardless of the model id. Built-in models that
|
|
753
|
-
* require adaptive thinking set this in generated metadata. Custom
|
|
754
|
-
* Anthropic-compatible providers can set this to `true` for any model whose
|
|
755
|
-
* upstream requires the adaptive format. Set to `false` to
|
|
756
|
-
* opt out on overridden built-in models.
|
|
757
|
-
* Default: false.
|
|
758
|
-
*/
|
|
759
|
-
forceAdaptiveThinking?: boolean;
|
|
760
|
-
/** Whether to replay empty thinking signatures as `signature: ""` instead of converting thinking to text. Default: false. */
|
|
761
|
-
allowEmptySignature?: boolean;
|
|
762
|
-
/** Whether the provider supports Anthropic strict tool schemas. Default: false; generated Anthropic models enable it explicitly. */
|
|
763
|
-
supportsStrictTools?: boolean;
|
|
764
|
-
/** Whether the exact model transport supports effort-only system messages and thinking binding controls. Default: false. */
|
|
765
|
-
supportsMidConvoEffort?: boolean;
|
|
766
|
-
/** Whether the exact model accepts system-role messages inside the conversation. When false, later system messages are folded into the top-level system prompt. Default: false. */
|
|
767
|
-
supportsMidConvoSystemMessages?: boolean;
|
|
768
|
-
/** Whether the exact model accepts mid-conversation `tool_addition` blocks with inline tool definitions (`inline-tools-2026-09-15`) and `tool_removal` blocks. Requires `supportsMidConvoSystemMessages`. Default: false. */
|
|
769
|
-
supportsMidConvoToolChanges?: boolean;
|
|
770
|
-
/**
|
|
771
|
-
* Models Anthropic accepts in `fallbacks` for server-side refusal fallback,
|
|
772
|
-
* with local pricing metadata for returned fallback responses. When absent or
|
|
773
|
-
* empty, callers must omit `fallbacks`; Anthropic rejects the field for models
|
|
774
|
-
* with no permitted fallback targets.
|
|
775
|
-
*/
|
|
776
|
-
allowedFallbackModels?: AnthropicAllowedFallbackModel[];
|
|
777
|
-
}
|
|
778
|
-
/** Compatibility settings for Amazon Bedrock models. */
|
|
779
|
-
export interface BedrockCompat {
|
|
780
|
-
/** Whether the model supports Bedrock strict tool schemas. Default: false. */
|
|
781
|
-
supportsStrictMode?: boolean;
|
|
782
|
-
}
|
|
783
|
-
/** Compatibility settings for the Mistral chat API. */
|
|
784
|
-
export interface MistralConversationsCompat {
|
|
785
|
-
/** Whether the exact model accepts system messages after the conversation has started. When false, later system messages are folded into the leading system message. Default: false. */
|
|
786
|
-
supportsMidConvoSystemMessages?: boolean;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* OpenRouter provider routing preferences.
|
|
790
|
-
* Controls which upstream providers OpenRouter routes requests to.
|
|
791
|
-
* Sent as the `provider` field in the OpenRouter API request body.
|
|
792
|
-
* @see https://openrouter.ai/docs/guides/routing/provider-selection
|
|
793
|
-
*/
|
|
794
|
-
export interface OpenRouterRouting {
|
|
795
|
-
/** Whether to allow backup providers to serve requests. Default: true. */
|
|
796
|
-
allow_fallbacks?: boolean;
|
|
797
|
-
/** Whether to filter providers to only those that support all parameters in the request. Default: false. */
|
|
798
|
-
require_parameters?: boolean;
|
|
799
|
-
/** Data collection setting. "allow" (default): allow providers that may store/train on data. "deny": only use providers that don't collect user data. */
|
|
800
|
-
data_collection?: "deny" | "allow";
|
|
801
|
-
/** Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. */
|
|
802
|
-
zdr?: boolean;
|
|
803
|
-
/** Whether to restrict routing to only models that allow text distillation. */
|
|
804
|
-
enforce_distillable_text?: boolean;
|
|
805
|
-
/** An ordered list of provider names/slugs to try in sequence, falling back to the next if unavailable. */
|
|
806
|
-
order?: string[];
|
|
807
|
-
/** List of provider names/slugs to exclusively allow for this request. */
|
|
808
|
-
only?: string[];
|
|
809
|
-
/** List of provider names/slugs to skip for this request. */
|
|
810
|
-
ignore?: string[];
|
|
811
|
-
/** A list of quantization levels to filter providers by (e.g., ["fp16", "bf16", "fp8", "fp6", "int8", "int4", "fp4", "fp32"]). */
|
|
812
|
-
quantizations?: string[];
|
|
813
|
-
/** Sorting strategy. Can be a string (e.g., "price", "throughput", "latency") or an object with `by` and `partition`. */
|
|
814
|
-
sort?: string | {
|
|
815
|
-
/** The sorting metric: "price", "throughput", "latency". */
|
|
816
|
-
by?: string;
|
|
817
|
-
/** Partitioning strategy: "model" (default) or "none". */
|
|
818
|
-
partition?: string | null;
|
|
819
|
-
};
|
|
820
|
-
/** Maximum price per million tokens (USD). */
|
|
821
|
-
max_price?: {
|
|
822
|
-
/** Price per million prompt tokens. */
|
|
823
|
-
prompt?: number | string;
|
|
824
|
-
/** Price per million completion tokens. */
|
|
825
|
-
completion?: number | string;
|
|
826
|
-
/** Price per image. */
|
|
827
|
-
image?: number | string;
|
|
828
|
-
/** Price per audio unit. */
|
|
829
|
-
audio?: number | string;
|
|
830
|
-
/** Price per request. */
|
|
831
|
-
request?: number | string;
|
|
832
|
-
};
|
|
833
|
-
/** Preferred minimum throughput (tokens/second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. */
|
|
834
|
-
preferred_min_throughput?: number | {
|
|
835
|
-
/** Minimum tokens/second at the 50th percentile. */
|
|
836
|
-
p50?: number;
|
|
837
|
-
/** Minimum tokens/second at the 75th percentile. */
|
|
838
|
-
p75?: number;
|
|
839
|
-
/** Minimum tokens/second at the 90th percentile. */
|
|
840
|
-
p90?: number;
|
|
841
|
-
/** Minimum tokens/second at the 99th percentile. */
|
|
842
|
-
p99?: number;
|
|
843
|
-
};
|
|
844
|
-
/** Preferred maximum latency (seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. */
|
|
845
|
-
preferred_max_latency?: number | {
|
|
846
|
-
/** Maximum latency in seconds at the 50th percentile. */
|
|
847
|
-
p50?: number;
|
|
848
|
-
/** Maximum latency in seconds at the 75th percentile. */
|
|
849
|
-
p75?: number;
|
|
850
|
-
/** Maximum latency in seconds at the 90th percentile. */
|
|
851
|
-
p90?: number;
|
|
852
|
-
/** Maximum latency in seconds at the 99th percentile. */
|
|
853
|
-
p99?: number;
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Vercel AI Gateway routing preferences.
|
|
858
|
-
* Controls which upstream providers the gateway routes requests to.
|
|
859
|
-
* @see https://vercel.com/docs/ai-gateway/models-and-providers/provider-options
|
|
860
|
-
*/
|
|
861
|
-
export interface VercelGatewayRouting {
|
|
862
|
-
/** List of provider slugs to exclusively use for this request (e.g., ["bedrock", "anthropic"]). */
|
|
863
|
-
only?: string[];
|
|
864
|
-
/** List of provider slugs to try in order (e.g., ["anthropic", "openai"]). */
|
|
865
|
-
order?: string[];
|
|
866
|
-
}
|
|
867
|
-
export interface ModelCostRates {
|
|
868
|
-
input: number;
|
|
869
|
-
output: number;
|
|
870
|
-
cacheRead: number;
|
|
871
|
-
cacheWrite: number;
|
|
872
|
-
}
|
|
873
|
-
export interface ModelCostTier extends ModelCostRates {
|
|
874
|
-
/** Use this tier for requests whose total input usage exceeds this token count. */
|
|
875
|
-
inputTokensAbove: number;
|
|
876
|
-
}
|
|
877
|
-
export interface ModelCost extends ModelCostRates {
|
|
878
|
-
/** Request-wide pricing tiers. The highest matching input threshold applies to the full request. */
|
|
879
|
-
tiers?: ModelCostTier[];
|
|
880
|
-
}
|
|
881
|
-
export interface ModelImageResizeOptions {
|
|
882
|
-
maxWidth?: number;
|
|
883
|
-
maxHeight?: number;
|
|
884
|
-
/** Maximum base64-encoded payload size in bytes. */
|
|
885
|
-
maxBytes?: number;
|
|
886
|
-
jpegQuality?: number;
|
|
887
|
-
}
|
|
888
|
-
export interface ModelImageInputLimits {
|
|
889
|
-
/** Cache-safe resize profile applied before a new image enters conversation history. */
|
|
890
|
-
resize?: ModelImageResizeOptions;
|
|
891
|
-
/** Maximum images accepted in one provider message. */
|
|
892
|
-
maxPerMessage?: number;
|
|
893
|
-
/** Maximum images accepted across one provider request. */
|
|
894
|
-
maxPerRequest?: number;
|
|
895
|
-
}
|
|
896
|
-
export interface ModelInputLimits {
|
|
897
|
-
/** Maximum serialized provider request size in bytes. */
|
|
898
|
-
maxRequestBytes?: number;
|
|
899
|
-
images?: ModelImageInputLimits;
|
|
900
|
-
}
|
|
901
618
|
/** Fields shared by every catalog entry, regardless of what you can do with it. */
|
|
902
619
|
export interface BaseModel<TApi extends string> {
|
|
903
620
|
id: string;
|
|
@@ -905,7 +622,7 @@ export interface BaseModel<TApi extends string> {
|
|
|
905
622
|
api: TApi;
|
|
906
623
|
provider: ProviderId;
|
|
907
624
|
baseUrl: string;
|
|
908
|
-
input:
|
|
625
|
+
input: ModelInputModality[];
|
|
909
626
|
/** Provider input limits and cache-safe preprocessing metadata. */
|
|
910
627
|
inputLimits?: ModelInputLimits;
|
|
911
628
|
cost: ModelCost;
|