Skip to content

Commit 6c97be6

Browse files
authored
feat(ai): add native Cerebras and Together AI providers (anomalyco#45098)
1 parent 6cd1ffa commit 6c97be6

25 files changed

Lines changed: 507 additions & 115 deletions

‎bun.lock‎

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/ai/script/setup-recording-env.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ const PROVIDERS: ReadonlyArray<Provider> = [
157157
id: "togetherai",
158158
label: "TogetherAI",
159159
tier: "compatible",
160-
note: "Existing OpenAI-compatible text/tool recorded tests",
161-
vars: [{ name: "TOGETHER_AI_API_KEY" }],
162-
validate: (env) => validateBearer("https://api.together.xyz/v1/models", Redacted.make(env.TOGETHER_AI_API_KEY)),
160+
note: "Native Together AI text/tool recorded tests",
161+
vars: [{ name: "TOGETHER_API_KEY" }],
162+
validate: (env) => validateBearer("https://api.together.xyz/v1/models", Redacted.make(env.TOGETHER_API_KEY)),
163163
},
164164
{
165165
id: "minimax",
@@ -200,8 +200,8 @@ const PROVIDERS: ReadonlyArray<Provider> = [
200200
{
201201
id: "cerebras",
202202
label: "Cerebras",
203-
tier: "optional",
204-
note: "OpenAI-compatible bridge",
203+
tier: "compatible",
204+
note: "Native Cerebras text/tool/tool-loop recorded tests",
205205
vars: [{ name: "CEREBRAS_API_KEY" }],
206206
validate: (env) => validateBearer("https://api.cerebras.ai/v1/models", Redacted.make(env.CEREBRAS_API_KEY)),
207207
},
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { ProviderPackage } from "../provider-package.js"
2+
import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat.js"
3+
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
4+
import type { RouteDefaultsInput } from "../route/client.js"
5+
import { ProviderID, type ModelID } from "../schema/index.js"
6+
import { profiles } from "./openai-compatible-profile.js"
7+
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
8+
9+
export const id = ProviderID.make("cerebras")
10+
11+
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
12+
ProviderAuthOption<"optional"> & {
13+
readonly baseURL?: string
14+
readonly providerOptions?: OpenAIProviderOptionsInput
15+
}
16+
17+
export interface Settings extends ProviderPackage.Settings {
18+
readonly apiKey?: string
19+
readonly baseURL?: string
20+
readonly providerOptions?: OpenAIProviderOptionsInput
21+
}
22+
23+
export const route = OpenAICompatibleChat.route.with({
24+
id: "cerebras-chat",
25+
provider: id,
26+
endpoint: { baseURL: profiles.cerebras.baseURL },
27+
})
28+
29+
export const routes = [route]
30+
31+
export const configure = (input: LanguageModelOptions = {}) => {
32+
const { apiKey: _apiKey, auth: _auth, baseURL, ...defaults } = input
33+
const configured = route.with({
34+
...defaults,
35+
endpoint: { baseURL: baseURL ?? profiles.cerebras.baseURL },
36+
auth: AuthOptions.bearer(input, "CEREBRAS_API_KEY"),
37+
})
38+
return {
39+
id,
40+
model: (modelID: string | ModelID) =>
41+
configured.model<OpenAIProviderOptionsInput>({
42+
id: modelID,
43+
compatibility: { maxTokensField: "max_tokens", reasoningField: "reasoning", supportsStore: false },
44+
}),
45+
configure,
46+
}
47+
}
48+
49+
export const provider = configure()
50+
51+
export const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"] = (modelID, settings) =>
52+
configure({
53+
apiKey: settings.apiKey,
54+
baseURL: settings.baseURL,
55+
headers: settings.headers === undefined ? undefined : { ...settings.headers },
56+
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
57+
providerOptions: settings.providerOptions,
58+
}).model(modelID)

‎packages/ai/src/providers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * as AnthropicCompatible from "./anthropic-compatible.js"
33
export * as AmazonBedrock from "./amazon-bedrock.js"
44
export * as AmazonBedrockMantle from "./amazon-bedrock-mantle.js"
55
export * as Azure from "./azure.js"
6+
export * as Cerebras from "./cerebras.js"
67
export * as Cloudflare from "./cloudflare.js"
78
export { CloudflareAIGateway, CloudflareWorkersAI } from "./cloudflare.js"
89
export * as Google from "./google.js"
@@ -14,5 +15,6 @@ export * as OpenAI from "./openai.js"
1415
export * as OpenAICompatible from "./openai-compatible.js"
1516
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js"
1617
export * as OpenRouter from "./openrouter.js"
18+
export * as TogetherAI from "./togetherai.js"
1719
export * as XAI from "./xai.js"
1820
export * as ZAI from "./zai.js"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { ProviderPackage } from "../provider-package.js"
2+
import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat.js"
3+
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
4+
import type { RouteDefaultsInput } from "../route/client.js"
5+
import { ProviderID, type ModelID } from "../schema/index.js"
6+
import { profiles } from "./openai-compatible-profile.js"
7+
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
8+
9+
export const id = ProviderID.make("togetherai")
10+
11+
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
12+
ProviderAuthOption<"optional"> & {
13+
readonly baseURL?: string
14+
readonly providerOptions?: OpenAIProviderOptionsInput
15+
}
16+
17+
export interface Settings extends ProviderPackage.Settings {
18+
readonly apiKey?: string
19+
readonly baseURL?: string
20+
readonly providerOptions?: OpenAIProviderOptionsInput
21+
}
22+
23+
export const route = OpenAICompatibleChat.route.with({
24+
id: "togetherai-chat",
25+
provider: id,
26+
endpoint: { baseURL: profiles.togetherai.baseURL },
27+
})
28+
29+
export const routes = [route]
30+
31+
export const configure = (input: LanguageModelOptions = {}) => {
32+
const { apiKey: _apiKey, auth: _auth, baseURL, ...defaults } = input
33+
const configured = route.with({
34+
...defaults,
35+
endpoint: { baseURL: baseURL ?? profiles.togetherai.baseURL },
36+
auth: AuthOptions.bearer(input, ["TOGETHER_API_KEY", "TOGETHER_AI_API_KEY"]),
37+
})
38+
return {
39+
id,
40+
model: (modelID: string | ModelID) =>
41+
configured.model<OpenAIProviderOptionsInput>({
42+
id: modelID,
43+
compatibility: { maxTokensField: "max_tokens", supportsStore: false, supportsStrictMode: false },
44+
}),
45+
configure,
46+
}
47+
}
48+
49+
export const provider = configure()
50+
51+
export const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"] = (modelID, settings) =>
52+
configure({
53+
apiKey: settings.apiKey,
54+
baseURL: settings.baseURL,
55+
headers: settings.headers === undefined ? undefined : { ...settings.headers },
56+
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
57+
providerOptions: settings.providerOptions,
58+
}).model(modelID)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": 1,
3+
"metadata": {
4+
"provider": "cerebras",
5+
"route": "cerebras-chat",
6+
"transport": "http",
7+
"model": "gpt-oss-120b",
8+
"tags": ["prefix:cerebras-chat", "provider:cerebras", "text", "golden"],
9+
"name": "cerebras-chat/cerebras-gpt-oss-120b-text",
10+
"recordedAt": "2026-08-25T23:55:27.619Z"
11+
},
12+
"interactions": [
13+
{
14+
"transport": "http",
15+
"request": {
16+
"method": "POST",
17+
"url": "https://api.cerebras.ai/v1/chat/completions",
18+
"headers": {
19+
"content-type": "application/json"
20+
},
21+
"body": "{\"model\":\"gpt-oss-120b\",\"messages\":[{\"role\":\"system\",\"content\":\"You are concise.\"},{\"role\":\"user\",\"content\":\"Reply exactly with: Hello!\"}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":256}"
22+
},
23+
"response": {
24+
"status": 200,
25+
"headers": {
26+
"content-type": "text/event-stream; charset=utf-8"
27+
},
28+
"body": "data: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"role\":\"assistant\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\"The\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\" user says: \\\"Reply exactly with: Hello!\\\" So we must output exactly\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\" \\\"Hello!\\\" with no extra characters, no formatting\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\". Ensure no extra spaces or new\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\"lines? Probably just \\\"Hello!\\\".\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"reasoning\":\" Usually we output exactly that.\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{\"content\":\"Hello!\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-cd45cd6e-886a-433e-8ba9-caca78c1f13a\",\"choices\":[{\"delta\":{},\"finish_reason\":\"stop\",\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_e2cabf4999eb0aead3d1\",\"object\":\"chat.completion.chunk\",\"usage\":{\"total_tokens\":142,\"completion_tokens\":58,\"completion_tokens_details\":{\"accepted_prediction_tokens\":0,\"rejected_prediction_tokens\":0,\"reasoning_tokens\":46},\"prompt_tokens\":84,\"prompt_tokens_details\":{\"cached_tokens\":0}},\"time_info\":{\"created\":1787702127.645281,\"queue_time\":0.003817115,\"prompt_time\":0.001587193,\"completion_time\":0.029805929,\"total_time\":0.036823272705078125}}\n\ndata: [DONE]\n\n"
29+
}
30+
}
31+
]
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": 1,
3+
"metadata": {
4+
"provider": "cerebras",
5+
"route": "cerebras-chat",
6+
"transport": "http",
7+
"model": "gpt-oss-120b",
8+
"tags": ["prefix:cerebras-chat", "provider:cerebras", "tool", "tool-call", "golden"],
9+
"name": "cerebras-chat/cerebras-gpt-oss-120b-tool-call",
10+
"recordedAt": "2026-08-25T23:55:28.454Z"
11+
},
12+
"interactions": [
13+
{
14+
"transport": "http",
15+
"request": {
16+
"method": "POST",
17+
"url": "https://api.cerebras.ai/v1/chat/completions",
18+
"headers": {
19+
"content-type": "application/json"
20+
},
21+
"body": "{\"model\":\"gpt-oss-120b\",\"messages\":[{\"role\":\"system\",\"content\":\"Call tools exactly as requested.\"},{\"role\":\"user\",\"content\":\"Call get_weather with city exactly Paris.\"}],\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"description\":\"Get current weather for a city.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\"}},\"required\":[\"city\"],\"additionalProperties\":false},\"strict\":false}}],\"tool_choice\":{\"type\":\"function\",\"function\":{\"name\":\"get_weather\"}},\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":512}"
22+
},
23+
"response": {
24+
"status": 200,
25+
"headers": {
26+
"content-type": "text/event-stream; charset=utf-8"
27+
},
28+
"body": "data: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"role\":\"assistant\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"reasoning\":\"We\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"reasoning\":\" need to call the function get_weather with city \\\"\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"reasoning\":\"Paris\\\".\"},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"tool_calls\":[{\"function\":{\"name\":\"get_weather\",\"arguments\":\"\"},\"type\":\"function\",\"id\":\"3d860cefe\",\"index\":0}]},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{\"tool_calls\":[{\"function\":{\"arguments\":\"{\\\"city\\\":\\\"Paris\\\"}\"},\"type\":\"function\",\"index\":0}]},\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\"}\n\ndata: {\"id\":\"chatcmpl-402a09cc-8668-446d-8f9c-3e4121f5fa51\",\"choices\":[{\"delta\":{},\"finish_reason\":\"tool_calls\",\"index\":0}],\"created\":1787702127,\"model\":\"gpt-oss-120b\",\"system_fingerprint\":\"fp_4cfabdd6620dc0120785\",\"object\":\"chat.completion.chunk\",\"usage\":{\"total_tokens\":174,\"completion_tokens\":37,\"completion_tokens_details\":{\"accepted_prediction_tokens\":0,\"rejected_prediction_tokens\":0,\"reasoning_tokens\":13},\"prompt_tokens\":137,\"prompt_tokens_details\":{\"cached_tokens\":0}},\"time_info\":{\"created\":1787702127.8019717,\"queue_time\":0.31196235,\"prompt_time\":0.005234764,\"completion_time\":0.020198402,\"total_time\":0.702225923538208}}\n\ndata: [DONE]\n\n"
29+
}
30+
}
31+
]
32+
}

0 commit comments

Comments
 (0)