@ai-sdk/cerebras 3.0.98 → 3.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.d.ts +22 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
- package/src/cerebras-model-catalog.ts +103 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @ai-sdk/cerebras
|
|
2
2
|
|
|
3
|
+
## 3.0.99
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e36f82b: refactor(cerebras): declare model capabilities per model ID
|
|
8
|
+
- Updated dependencies [f958ef0]
|
|
9
|
+
- @ai-sdk/provider@4.0.40
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.87
|
|
11
|
+
- @ai-sdk/openai-compatible@3.0.98
|
|
12
|
+
|
|
3
13
|
## 3.0.98
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -41,13 +41,31 @@ declare const cerebrasLanguageModelChatOptions: z.ZodObject<{
|
|
|
41
41
|
type CerebrasLanguageModelChatOptions = z.infer<typeof cerebrasLanguageModelChatOptions>;
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/cerebras-model-catalog.d.ts
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Language model matrix: model IDs by capability. To add a model, add a row
|
|
46
|
+
* and fill in every column.
|
|
47
|
+
*/
|
|
48
|
+
declare const languageModelDefinitions: {
|
|
49
|
+
'gpt-oss-120b': {
|
|
50
|
+
documented: true;
|
|
51
|
+
image: false;
|
|
52
|
+
objectGeneration: true;
|
|
53
|
+
functionTools: "streaming"[];
|
|
54
|
+
reasoning: true;
|
|
55
|
+
logprobs: true;
|
|
56
|
+
};
|
|
57
|
+
'gemma-4-31b': {
|
|
58
|
+
documented: true;
|
|
59
|
+
image: true;
|
|
60
|
+
objectGeneration: true;
|
|
61
|
+
functionTools: "streaming"[];
|
|
62
|
+
reasoning: true;
|
|
63
|
+
logprobs: true;
|
|
64
|
+
};
|
|
47
65
|
};
|
|
48
66
|
/** Known model IDs, derived from the declarations used to build the catalog. */
|
|
49
67
|
type CerebrasModelIds = {
|
|
50
|
-
language: keyof typeof
|
|
68
|
+
language: keyof typeof languageModelDefinitions;
|
|
51
69
|
};
|
|
52
70
|
//#endregion
|
|
53
71
|
//#region src/cerebras-chat-options.d.ts
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cerebras-chat-language-model-options.ts","../src/cerebras-model-catalog.ts","../src/cerebras-chat-options.ts","../src/cerebras-provider.ts","../src/version.ts"],"mappings":";;;;cAIa,kCAAgC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwB3C,EAAA,KAAA;KAEU,mCAAmC,EAAE,aACxC
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cerebras-chat-language-model-options.ts","../src/cerebras-model-catalog.ts","../src/cerebras-chat-options.ts","../src/cerebras-provider.ts","../src/version.ts"],"mappings":";;;;cAIa,kCAAgC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwB3C,EAAA,KAAA;KAEU,mCAAmC,EAAE,aACxC;;;;;;;cCiDH;;;;;;;;;;;;;;;;;;;KA6HM;EACV,uBAAuB;;;;KC3Mb,sBAAsB;;;cCmB5B,qBAAmB,EAAA;;;;;GAKvB,EAAA,KAAA;KAEU,oBAAoB,EAAE,aAAa;UAmE9B;;;;;EAKf,SAAS;;;;EAIT;;;;EAIA,UAAU;;;;;EAKV,QAAQ;;UAGO,yBAAyB;;;;GAIvC,SAAS,sBAAsB;;;;EAKhC,cAAc,SAAS,sBAAsB;;;;EAK7C,KAAK,SAAS,sBAAsB;;;;EAKpC,mBAAmB;;wBAGL,eACd,UAAS,2BACR;qBAoDU,UAAQ;;;qBC/LR"}
|
package/dist/index.js
CHANGED
|
@@ -115,7 +115,7 @@ var CerebrasChatLanguageModel = class CerebrasChatLanguageModel extends OpenAICo
|
|
|
115
115
|
};
|
|
116
116
|
//#endregion
|
|
117
117
|
//#region src/version.ts
|
|
118
|
-
const VERSION = "3.0.
|
|
118
|
+
const VERSION = "3.0.99";
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region src/cerebras-metadata-extractor.ts
|
|
121
121
|
const cerebrasMetadataExtractor = {
|
|
@@ -162,43 +162,76 @@ const cerebrasProviderOptions = { language: {
|
|
|
162
162
|
prediction: { description: "Predicted output content." },
|
|
163
163
|
promptCacheKey: { description: "Cache affinity key for shared prompts." }
|
|
164
164
|
} };
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Language model matrix: model IDs by capability. To add a model, add a row
|
|
167
|
+
* and fill in every column.
|
|
168
|
+
*/
|
|
169
|
+
const languageModelDefinitions = {
|
|
170
|
+
"gpt-oss-120b": {
|
|
171
|
+
documented: true,
|
|
172
|
+
image: false,
|
|
173
|
+
objectGeneration: true,
|
|
174
|
+
functionTools: ["streaming"],
|
|
175
|
+
reasoning: true,
|
|
176
|
+
logprobs: true
|
|
177
|
+
},
|
|
178
|
+
"gemma-4-31b": {
|
|
179
|
+
documented: true,
|
|
180
|
+
image: true,
|
|
181
|
+
objectGeneration: true,
|
|
182
|
+
functionTools: ["streaming"],
|
|
183
|
+
reasoning: true,
|
|
184
|
+
logprobs: true
|
|
185
|
+
}
|
|
168
186
|
};
|
|
169
|
-
|
|
170
|
-
|
|
187
|
+
/** Maps a matrix row to its entry. Nothing here inspects the model ID. */
|
|
188
|
+
function createLanguageModelEntry(row) {
|
|
171
189
|
return {
|
|
172
190
|
capabilities: { language: {
|
|
173
191
|
inputs: {
|
|
174
|
-
image: image
|
|
192
|
+
image: row.image,
|
|
175
193
|
audio: false
|
|
176
194
|
},
|
|
177
|
-
objectGeneration:
|
|
195
|
+
objectGeneration: row.objectGeneration,
|
|
178
196
|
tools: {
|
|
179
|
-
usage:
|
|
180
|
-
streaming:
|
|
197
|
+
usage: row.functionTools === "unknown" ? "unknown" : row.functionTools !== false,
|
|
198
|
+
streaming: row.functionTools === "unknown" ? "unknown" : row.functionTools !== false && row.functionTools.includes("streaming")
|
|
181
199
|
},
|
|
182
|
-
reasoning: { support },
|
|
200
|
+
reasoning: { support: row.reasoning },
|
|
183
201
|
sampling: {
|
|
184
202
|
temperature: "unknown",
|
|
185
203
|
topP: "unknown",
|
|
186
|
-
logprobs:
|
|
204
|
+
logprobs: row.logprobs
|
|
187
205
|
},
|
|
188
206
|
structuredOutput: { jsonSchema: true }
|
|
189
207
|
} },
|
|
190
|
-
providerOptions: { language: declareProviderOptions(cerebrasProviderOptions.language,
|
|
208
|
+
providerOptions: { language: declareProviderOptions(cerebrasProviderOptions.language, row.documented ? true : "unknown", {
|
|
191
209
|
strictJsonSchema: { condition: "Requires a JSON schema response format." },
|
|
210
|
+
logprobs: row.logprobs,
|
|
211
|
+
topLogprobs: row.logprobs,
|
|
192
212
|
serviceTier: { condition: "Requires a preview-enabled dedicated endpoint." },
|
|
193
213
|
queueThreshold: { condition: "Requires flex/auto on a preview-enabled dedicated endpoint." },
|
|
194
|
-
reasoningEffort:
|
|
195
|
-
reasoningFormat:
|
|
214
|
+
reasoningEffort: row.reasoning === true ? { condition: "Supported values depend on the reasoning model." } : row.reasoning,
|
|
215
|
+
reasoningFormat: row.reasoning === true ? { condition: "Available formats depend on the reasoning model." } : row.reasoning
|
|
196
216
|
}) }
|
|
197
217
|
};
|
|
198
218
|
}
|
|
199
|
-
const cerebrasModelCatalog = Object.fromEntries(Object.entries(
|
|
219
|
+
const cerebrasModelCatalog = Object.fromEntries(Object.entries(languageModelDefinitions).map(([modelId, row]) => [modelId, createLanguageModelEntry(row)]));
|
|
220
|
+
/** Row for every model ID that is not listed in the matrix. */
|
|
221
|
+
const unlistedLanguageModelRow = {
|
|
222
|
+
documented: false,
|
|
223
|
+
image: "unknown",
|
|
224
|
+
objectGeneration: "unknown",
|
|
225
|
+
functionTools: "unknown",
|
|
226
|
+
reasoning: "unknown",
|
|
227
|
+
logprobs: "unknown"
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Returns the entry of a listed language model ID from its row. Every other
|
|
231
|
+
* model ID uses the row for unlisted IDs.
|
|
232
|
+
*/
|
|
200
233
|
function getCerebrasLanguageModelEntry(modelId) {
|
|
201
|
-
return Object.prototype.hasOwnProperty.call(cerebrasModelCatalog, modelId) ? cerebrasModelCatalog[modelId] : createLanguageModelEntry();
|
|
234
|
+
return Object.prototype.hasOwnProperty.call(cerebrasModelCatalog, modelId) ? cerebrasModelCatalog[modelId] : createLanguageModelEntry(unlistedLanguageModelRow);
|
|
202
235
|
}
|
|
203
236
|
function declareProviderOptions(definitions, support, exceptions) {
|
|
204
237
|
return Object.fromEntries(Object.keys(definitions).map((option) => [option, exceptions[option] ?? support]));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/cerebras-chat-language-model-options.ts","../src/cerebras-chat-language-model.ts","../src/version.ts","../src/cerebras-metadata-extractor.ts","../src/cerebras-model-catalog.ts","../src/cerebras-provider.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type { CerebrasChatModelId } from './cerebras-chat-options';\n\nexport const cerebrasLanguageModelChatOptions = z.object({\n user: z.string().optional(),\n strictJsonSchema: z.boolean().optional(),\n parallelToolCalls: z.boolean().optional(),\n logprobs: z.boolean().optional(),\n topLogprobs: z.number().int().min(0).max(20).optional(),\n logitBias: z.record(z.string(), z.number().min(-100).max(100)).optional(),\n serviceTier: z.enum(['auto', 'default', 'flex', 'priority']).optional(),\n /** Maximum queue time in milliseconds for flex/auto requests. */\n queueThreshold: z.number().int().min(50).max(20000).optional(),\n reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),\n reasoningFormat: z\n .enum(['none', 'parsed', 'text_parsed', 'raw', 'hidden'])\n .optional(),\n prediction: z\n .object({\n type: z.literal('content'),\n content: z.union([\n z.string(),\n z.array(z.object({ type: z.literal('text'), text: z.string() })),\n ]),\n })\n .optional(),\n promptCacheKey: z.string().max(1024).optional(),\n});\n\nexport type CerebrasLanguageModelChatOptions = z.infer<\n typeof cerebrasLanguageModelChatOptions\n>;\n","import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\nimport type {\n LanguageModelV4,\n LanguageModelV4CallOptions,\n LanguageModelV4GenerateResult,\n LanguageModelV4StreamPart,\n LanguageModelV4StreamResult,\n} from '@ai-sdk/provider';\nimport {\n normalizeHeaders,\n parseProviderOptions,\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport {\n cerebrasLanguageModelChatOptions,\n type CerebrasChatModelId,\n} from './cerebras-chat-language-model-options';\n\ntype CerebrasChatConfig = ConstructorParameters<\n typeof OpenAICompatibleChatLanguageModel\n>[1];\n\nfunction isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason,\n hasText,\n responseFormatType,\n}: {\n rawFinishReason: string | undefined;\n hasText: boolean;\n responseFormatType:\n | NonNullable<LanguageModelV4CallOptions['responseFormat']>['type']\n | undefined;\n}) {\n return (\n responseFormatType === 'json' && rawFinishReason === 'tool_calls' && hasText\n );\n}\n\nexport class CerebrasChatLanguageModel\n extends OpenAICompatibleChatLanguageModel\n implements LanguageModelV4\n{\n static [WORKFLOW_SERIALIZE](model: CerebrasChatLanguageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: CerebrasChatModelId;\n config: CerebrasChatConfig;\n }) {\n return new CerebrasChatLanguageModel(options.modelId, options.config);\n }\n\n async doGenerate(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4GenerateResult> {\n const result = await super.doGenerate(\n await this.applyQueueThresholdHeader(options),\n );\n\n if (\n !isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: result.finishReason.raw,\n hasText: result.content.some(\n part => part.type === 'text' && part.text.length > 0,\n ),\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n return result;\n }\n\n return {\n ...result,\n // Cerebras GLM can return valid structured output text while also\n // repeating a tool call. Treat that mixed response as the final answer.\n content: result.content.filter(part => part.type !== 'tool-call'),\n finishReason: {\n ...result.finishReason,\n unified: 'stop',\n },\n };\n }\n\n async doStream(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4StreamResult> {\n const result = await super.doStream(\n await this.applyQueueThresholdHeader(options),\n );\n let hasText = false;\n\n return {\n ...result,\n stream: result.stream.pipeThrough(\n new TransformStream<\n LanguageModelV4StreamPart,\n LanguageModelV4StreamPart\n >({\n transform(part, controller) {\n if (part.type === 'text-delta' && part.delta.length > 0) {\n hasText = true;\n }\n\n if (\n part.type === 'finish' &&\n isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: part.finishReason.raw,\n hasText,\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n controller.enqueue({\n ...part,\n finishReason: {\n ...part.finishReason,\n unified: 'stop',\n },\n });\n return;\n }\n\n if (\n options.responseFormat?.type === 'json' &&\n hasText &&\n (part.type === 'tool-input-start' ||\n part.type === 'tool-input-delta' ||\n part.type === 'tool-input-end' ||\n part.type === 'tool-call')\n ) {\n return;\n }\n\n controller.enqueue(part);\n },\n }),\n ),\n };\n }\n\n private async applyQueueThresholdHeader(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4CallOptions> {\n const cerebrasOptions = await parseProviderOptions({\n provider: 'cerebras',\n providerOptions: options.providerOptions,\n schema: cerebrasLanguageModelChatOptions.pick({ queueThreshold: true }),\n });\n\n if (cerebrasOptions?.queueThreshold == null) {\n return options;\n }\n\n return {\n ...options,\n headers: {\n ...normalizeHeaders(options.headers),\n queue_threshold: String(cerebrasOptions.queueThreshold),\n },\n };\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import type { MetadataExtractor } from '@ai-sdk/openai-compatible';\nimport { safeValidateTypes } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const cerebrasMetadataExtractor: MetadataExtractor = {\n extractMetadata: async ({ parsedBody }) => {\n const parsed = await safeValidateTypes({\n value: parsedBody,\n schema: cerebrasServiceTierSchema,\n });\n\n if (!parsed.success) {\n return undefined;\n }\n\n const serviceTier = parsed.value.service_tier ?? undefined;\n\n return serviceTier != null ? { cerebras: { serviceTier } } : undefined;\n },\n\n createStreamExtractor: () => {\n let serviceTier: string | undefined;\n\n return {\n processChunk(parsedChunk) {\n serviceTier = getServiceTier(parsedChunk) ?? serviceTier;\n },\n\n buildMetadata() {\n return serviceTier != null ? { cerebras: { serviceTier } } : undefined;\n },\n };\n },\n};\n\nfunction getServiceTier(value: unknown): string | undefined {\n const parsed = cerebrasServiceTierSchema.safeParse(value);\n if (!parsed.success) {\n return undefined;\n }\n return parsed.data.service_tier ?? undefined;\n}\n\nconst cerebrasServiceTierSchema = z.looseObject({\n // The response tier may be absent or null when service-tier handling is not applied.\n service_tier: z.string().nullish(),\n});\n","import type {\n ModelCapabilities,\n ModelCapability,\n ModelEntry,\n ProviderOptionDefinition,\n ProviderOptionDefinitions,\n} from '@ai-sdk/provider';\nimport type { CerebrasLanguageModelChatOptions } from './cerebras-chat-language-model-options';\n\nexport const cerebrasProviderOptions = {\n language: {\n user: { description: 'End-user identifier for abuse monitoring.' },\n strictJsonSchema: { description: 'Use strict JSON schema validation.' },\n parallelToolCalls: { description: 'Allow parallel function calls.' },\n logprobs: { description: 'Return token log probabilities.' },\n topLogprobs: {\n description: 'Number of token log probabilities to return.',\n },\n logitBias: { description: 'Bias token selection by token ID.' },\n serviceTier: { description: 'Request processing tier.' },\n queueThreshold: { description: 'Maximum acceptable flex queue time.' },\n reasoningEffort: {\n description: 'Reasoning effort for configurable models.',\n },\n reasoningFormat: { description: 'Format of the returned reasoning.' },\n prediction: { description: 'Predicted output content.' },\n promptCacheKey: { description: 'Cache affinity key for shared prompts.' },\n } satisfies Record<\n keyof CerebrasLanguageModelChatOptions,\n ProviderOptionDefinition\n >,\n} as const satisfies ProviderOptionDefinitions;\n\ntype LanguageCapabilities = NonNullable<ModelCapabilities['language']> & {\n structuredOutput: { jsonSchema: boolean };\n};\n\ntype CerebrasLanguageModelEntry = ModelEntry & {\n capabilities: { language: LanguageCapabilities };\n providerOptions: {\n language: Record<keyof CerebrasLanguageModelChatOptions, ModelCapability>;\n };\n};\n\n// Preserve the provider page's model set and image-input exception.\nconst languageDefinitions = {\n 'gpt-oss-120b': false,\n 'gemma-4-31b': true,\n} satisfies Record<string, boolean>;\n\nfunction createLanguageModelEntry(image?: boolean): CerebrasLanguageModelEntry {\n const support = image != null ? true : 'unknown';\n const language: LanguageCapabilities = {\n inputs: { image: image ?? 'unknown', audio: false },\n objectGeneration: support,\n tools: { usage: support, streaming: support },\n reasoning: { support },\n sampling: { temperature: 'unknown', topP: 'unknown', logprobs: support },\n // Keep forwarding JSON schemas for custom IDs as the existing provider does.\n structuredOutput: { jsonSchema: true },\n };\n return {\n capabilities: { language },\n providerOptions: {\n language: declareProviderOptions(\n cerebrasProviderOptions.language,\n support,\n {\n strictJsonSchema: {\n condition: 'Requires a JSON schema response format.',\n },\n serviceTier: {\n condition: 'Requires a preview-enabled dedicated endpoint.',\n },\n queueThreshold: {\n condition:\n 'Requires flex/auto on a preview-enabled dedicated endpoint.',\n },\n reasoningEffort:\n image != null\n ? { condition: 'Supported values depend on the reasoning model.' }\n : 'unknown',\n reasoningFormat:\n image != null\n ? {\n condition: 'Available formats depend on the reasoning model.',\n }\n : 'unknown',\n },\n ),\n },\n };\n}\n\nexport const cerebrasModelCatalog: Readonly<\n Record<string, CerebrasLanguageModelEntry>\n> = Object.fromEntries(\n Object.entries(languageDefinitions).map(([modelId, image]) => [\n modelId,\n createLanguageModelEntry(image),\n ]),\n);\n\nexport function getCerebrasLanguageModelEntry(\n modelId: string,\n): CerebrasLanguageModelEntry {\n return Object.prototype.hasOwnProperty.call(cerebrasModelCatalog, modelId)\n ? cerebrasModelCatalog[modelId]\n : createLanguageModelEntry();\n}\n\nfunction declareProviderOptions<Option extends string>(\n definitions: Readonly<Record<Option, ProviderOptionDefinition>>,\n support: ModelCapability,\n exceptions: Partial<Record<Option, ModelCapability>>,\n): Record<Option, ModelCapability> {\n return Object.fromEntries(\n (Object.keys(definitions) as Option[]).map(option => [\n option,\n exceptions[option] ?? support,\n ]),\n ) as Record<Option, ModelCapability>;\n}\n\n/** Known model IDs, derived from the declarations used to build the catalog. */\nexport type CerebrasModelIds = {\n language: keyof typeof languageDefinitions;\n};\n","import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n type Resolvable,\n resolveWith,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { CerebrasChatLanguageModel } from './cerebras-chat-language-model';\nimport type { CerebrasChatModelId } from './cerebras-chat-options';\nimport { z } from 'zod/v4';\nimport { VERSION } from './version';\nimport { cerebrasMetadataExtractor } from './cerebras-metadata-extractor';\nimport { getCerebrasLanguageModelEntry } from './cerebras-model-catalog';\n\n// Add error schema and structure\nconst cerebrasErrorSchema = z.object({\n message: z.string(),\n type: z.string(),\n param: z.string(),\n code: z.string(),\n});\n\nexport type CerebrasErrorData = z.infer<typeof cerebrasErrorSchema>;\n\nconst cerebrasErrorStructure: ProviderErrorStructure<CerebrasErrorData> = {\n errorSchema: cerebrasErrorSchema,\n errorToMessage: data => data.message,\n};\n\n/**\n * Cerebras expects assistant reasoning history in the `reasoning` field, while\n * the shared OpenAI-compatible converter serializes it as `reasoning_content`.\n */\nfunction transformCerebrasRequestBody(\n args: Record<string, any>,\n): Record<string, any> {\n const {\n max_tokens: maxTokens,\n parallelToolCalls,\n topLogprobs,\n logitBias,\n serviceTier,\n queueThreshold: _queueThreshold,\n reasoningFormat,\n promptCacheKey,\n ...restArgs\n } = args;\n\n return {\n ...restArgs,\n ...(maxTokens !== undefined && {\n max_completion_tokens: maxTokens,\n }),\n ...(parallelToolCalls !== undefined && {\n parallel_tool_calls: parallelToolCalls,\n }),\n ...(topLogprobs !== undefined && { top_logprobs: topLogprobs }),\n ...(logitBias !== undefined && { logit_bias: logitBias }),\n ...(serviceTier !== undefined && { service_tier: serviceTier }),\n ...(reasoningFormat !== undefined && {\n reasoning_format: reasoningFormat,\n }),\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n messages: Array.isArray(args.messages)\n ? args.messages.map(message => {\n if (\n message == null ||\n typeof message !== 'object' ||\n message.role !== 'assistant' ||\n !('reasoning_content' in message)\n ) {\n return message;\n }\n\n const { reasoning_content, ...rest } = message;\n\n return {\n ...rest,\n ...(!('reasoning' in rest) && reasoning_content !== undefined\n ? { reasoning: reasoning_content }\n : {}),\n };\n })\n : args.messages,\n };\n}\n\nexport interface CerebrasProviderSettings {\n /**\n * Cerebras API key.\n * A function is called before each request and may return a promise.\n */\n apiKey?: Resolvable<string>;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface CerebrasProvider extends ProviderV4 {\n /**\n * Creates a Cerebras model for text generation.\n */\n (modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras model for text generation.\n */\n languageModel(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras chat model for text generation.\n */\n chat(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createCerebras(\n options: CerebrasProviderSettings = {},\n): CerebrasProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.cerebras.ai/v1',\n );\n const getHeaders = () =>\n resolveWith(options.apiKey, apiKey =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey,\n environmentVariableName: 'CEREBRAS_API_KEY',\n description: 'Cerebras API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-cerebras/${VERSION}`,\n ),\n );\n\n const createLanguageModel = (modelId: CerebrasChatModelId) => {\n return new CerebrasChatLanguageModel(modelId, {\n provider: `cerebras.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: cerebrasErrorStructure,\n supportsStructuredOutputs:\n getCerebrasLanguageModelEntry(modelId).capabilities.language\n .structuredOutput.jsonSchema,\n transformRequestBody: transformCerebrasRequestBody,\n metadataExtractor: cerebrasMetadataExtractor,\n });\n };\n\n const provider = (modelId: CerebrasChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const cerebras = createCerebras();\n"],"mappings":";;;;;AAIA,MAAa,mCAAmC,EAAE,OAAO;CACvD,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,kBAAkB,EAAE,QAAQ,CAAC,CAAC,SAAS;CACvC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,GACA,mBAAmB,SACrB,CACF;CAEF,MAAM,uBAAuB,YAAiC;EAC5D,OAAO,IAAI,0BAA0B,SAAS;GAC5C,UAAU;GACV,MAAM,EAAE,WAAW,GAAG,UAAU;GAChC,SAAS;GACT,OAAO,QAAQ;GACf,gBAAgB;GAChB,2BACE,8BAA8B,OAAO,CAAC,CAAC,aAAa,SACjD,iBAAiB;GACtB,sBAAsB;GACtB,mBAAmB;EACrB,CAAC;CACH;CAEA,MAAM,YAAY,YAChB,oBAAoB,OAAO;CAE7B,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAEhB,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,OAAO;AACT;AAEA,MAAa,WAAW,eAAe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/cerebras-chat-language-model-options.ts","../src/cerebras-chat-language-model.ts","../src/version.ts","../src/cerebras-metadata-extractor.ts","../src/cerebras-model-catalog.ts","../src/cerebras-provider.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type { CerebrasChatModelId } from './cerebras-chat-options';\n\nexport const cerebrasLanguageModelChatOptions = z.object({\n user: z.string().optional(),\n strictJsonSchema: z.boolean().optional(),\n parallelToolCalls: z.boolean().optional(),\n logprobs: z.boolean().optional(),\n topLogprobs: z.number().int().min(0).max(20).optional(),\n logitBias: z.record(z.string(), z.number().min(-100).max(100)).optional(),\n serviceTier: z.enum(['auto', 'default', 'flex', 'priority']).optional(),\n /** Maximum queue time in milliseconds for flex/auto requests. */\n queueThreshold: z.number().int().min(50).max(20000).optional(),\n reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),\n reasoningFormat: z\n .enum(['none', 'parsed', 'text_parsed', 'raw', 'hidden'])\n .optional(),\n prediction: z\n .object({\n type: z.literal('content'),\n content: z.union([\n z.string(),\n z.array(z.object({ type: z.literal('text'), text: z.string() })),\n ]),\n })\n .optional(),\n promptCacheKey: z.string().max(1024).optional(),\n});\n\nexport type CerebrasLanguageModelChatOptions = z.infer<\n typeof cerebrasLanguageModelChatOptions\n>;\n","import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\nimport type {\n LanguageModelV4,\n LanguageModelV4CallOptions,\n LanguageModelV4GenerateResult,\n LanguageModelV4StreamPart,\n LanguageModelV4StreamResult,\n} from '@ai-sdk/provider';\nimport {\n normalizeHeaders,\n parseProviderOptions,\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport {\n cerebrasLanguageModelChatOptions,\n type CerebrasChatModelId,\n} from './cerebras-chat-language-model-options';\n\ntype CerebrasChatConfig = ConstructorParameters<\n typeof OpenAICompatibleChatLanguageModel\n>[1];\n\nfunction isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason,\n hasText,\n responseFormatType,\n}: {\n rawFinishReason: string | undefined;\n hasText: boolean;\n responseFormatType:\n | NonNullable<LanguageModelV4CallOptions['responseFormat']>['type']\n | undefined;\n}) {\n return (\n responseFormatType === 'json' && rawFinishReason === 'tool_calls' && hasText\n );\n}\n\nexport class CerebrasChatLanguageModel\n extends OpenAICompatibleChatLanguageModel\n implements LanguageModelV4\n{\n static [WORKFLOW_SERIALIZE](model: CerebrasChatLanguageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: CerebrasChatModelId;\n config: CerebrasChatConfig;\n }) {\n return new CerebrasChatLanguageModel(options.modelId, options.config);\n }\n\n async doGenerate(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4GenerateResult> {\n const result = await super.doGenerate(\n await this.applyQueueThresholdHeader(options),\n );\n\n if (\n !isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: result.finishReason.raw,\n hasText: result.content.some(\n part => part.type === 'text' && part.text.length > 0,\n ),\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n return result;\n }\n\n return {\n ...result,\n // Cerebras GLM can return valid structured output text while also\n // repeating a tool call. Treat that mixed response as the final answer.\n content: result.content.filter(part => part.type !== 'tool-call'),\n finishReason: {\n ...result.finishReason,\n unified: 'stop',\n },\n };\n }\n\n async doStream(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4StreamResult> {\n const result = await super.doStream(\n await this.applyQueueThresholdHeader(options),\n );\n let hasText = false;\n\n return {\n ...result,\n stream: result.stream.pipeThrough(\n new TransformStream<\n LanguageModelV4StreamPart,\n LanguageModelV4StreamPart\n >({\n transform(part, controller) {\n if (part.type === 'text-delta' && part.delta.length > 0) {\n hasText = true;\n }\n\n if (\n part.type === 'finish' &&\n isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: part.finishReason.raw,\n hasText,\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n controller.enqueue({\n ...part,\n finishReason: {\n ...part.finishReason,\n unified: 'stop',\n },\n });\n return;\n }\n\n if (\n options.responseFormat?.type === 'json' &&\n hasText &&\n (part.type === 'tool-input-start' ||\n part.type === 'tool-input-delta' ||\n part.type === 'tool-input-end' ||\n part.type === 'tool-call')\n ) {\n return;\n }\n\n controller.enqueue(part);\n },\n }),\n ),\n };\n }\n\n private async applyQueueThresholdHeader(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4CallOptions> {\n const cerebrasOptions = await parseProviderOptions({\n provider: 'cerebras',\n providerOptions: options.providerOptions,\n schema: cerebrasLanguageModelChatOptions.pick({ queueThreshold: true }),\n });\n\n if (cerebrasOptions?.queueThreshold == null) {\n return options;\n }\n\n return {\n ...options,\n headers: {\n ...normalizeHeaders(options.headers),\n queue_threshold: String(cerebrasOptions.queueThreshold),\n },\n };\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import type { MetadataExtractor } from '@ai-sdk/openai-compatible';\nimport { safeValidateTypes } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const cerebrasMetadataExtractor: MetadataExtractor = {\n extractMetadata: async ({ parsedBody }) => {\n const parsed = await safeValidateTypes({\n value: parsedBody,\n schema: cerebrasServiceTierSchema,\n });\n\n if (!parsed.success) {\n return undefined;\n }\n\n const serviceTier = parsed.value.service_tier ?? undefined;\n\n return serviceTier != null ? { cerebras: { serviceTier } } : undefined;\n },\n\n createStreamExtractor: () => {\n let serviceTier: string | undefined;\n\n return {\n processChunk(parsedChunk) {\n serviceTier = getServiceTier(parsedChunk) ?? serviceTier;\n },\n\n buildMetadata() {\n return serviceTier != null ? { cerebras: { serviceTier } } : undefined;\n },\n };\n },\n};\n\nfunction getServiceTier(value: unknown): string | undefined {\n const parsed = cerebrasServiceTierSchema.safeParse(value);\n if (!parsed.success) {\n return undefined;\n }\n return parsed.data.service_tier ?? undefined;\n}\n\nconst cerebrasServiceTierSchema = z.looseObject({\n // The response tier may be absent or null when service-tier handling is not applied.\n service_tier: z.string().nullish(),\n});\n","import type {\n ModelCapabilities,\n ModelCapability,\n ModelEntry,\n ProviderOptionDefinition,\n ProviderOptionDefinitions,\n} from '@ai-sdk/provider';\nimport type { CerebrasLanguageModelChatOptions } from './cerebras-chat-language-model-options';\n\nexport const cerebrasProviderOptions = {\n language: {\n user: { description: 'End-user identifier for abuse monitoring.' },\n strictJsonSchema: { description: 'Use strict JSON schema validation.' },\n parallelToolCalls: { description: 'Allow parallel function calls.' },\n logprobs: { description: 'Return token log probabilities.' },\n topLogprobs: {\n description: 'Number of token log probabilities to return.',\n },\n logitBias: { description: 'Bias token selection by token ID.' },\n serviceTier: { description: 'Request processing tier.' },\n queueThreshold: { description: 'Maximum acceptable flex queue time.' },\n reasoningEffort: {\n description: 'Reasoning effort for configurable models.',\n },\n reasoningFormat: { description: 'Format of the returned reasoning.' },\n prediction: { description: 'Predicted output content.' },\n promptCacheKey: { description: 'Cache affinity key for shared prompts.' },\n } satisfies Record<\n keyof CerebrasLanguageModelChatOptions,\n ProviderOptionDefinition\n >,\n} as const satisfies ProviderOptionDefinitions;\n\ntype LanguageCapabilities = NonNullable<ModelCapabilities['language']> & {\n structuredOutput: { jsonSchema: boolean };\n};\n\ntype CerebrasLanguageModelEntry = ModelEntry & {\n capabilities: { language: LanguageCapabilities };\n providerOptions: {\n language: Record<keyof CerebrasLanguageModelChatOptions, ModelCapability>;\n };\n};\n\n/**\n * One row of the language model matrix. Every capability that differs between\n * models is one flat cell, and every listed model fills in every cell. Nothing\n * is derived from the model ID.\n *\n * Facts that depend on each other share one cell, so a row cannot contradict\n * itself: a cell is a single value, one of a fixed set of values, or the list\n * of what the model supports.\n */\nexport type CerebrasLanguageModelRow = {\n /**\n * `false`: nothing is documented for the model ID. Its provider options\n * without their own cell are then reported as `'unknown'`.\n */\n documented: boolean;\n image: ModelCapability;\n objectGeneration: ModelCapability;\n /**\n * `false`: the model does not call function tools. Otherwise it does, and\n * the list holds what it supports on top of that: `streaming` means it\n * also calls tools in a streamed response. `'unknown'`: not documented.\n */\n functionTools: 'unknown' | false | readonly 'streaming'[];\n /**\n * Reasons. `true`: the `reasoningEffort` and `reasoningFormat` options are\n * accepted, with values that depend on the model.\n */\n reasoning: ModelCapability;\n /** Returns token log probabilities (`logprobs`, `topLogprobs`). */\n logprobs: ModelCapability;\n};\n\n/**\n * Language model matrix: model IDs by capability. To add a model, add a row\n * and fill in every column.\n */\nconst languageModelDefinitions = {\n 'gpt-oss-120b': {\n documented: true,\n image: false,\n objectGeneration: true,\n functionTools: ['streaming'],\n reasoning: true,\n logprobs: true,\n },\n 'gemma-4-31b': {\n documented: true,\n image: true,\n objectGeneration: true,\n functionTools: ['streaming'],\n reasoning: true,\n logprobs: true,\n },\n} satisfies Record<string, CerebrasLanguageModelRow>;\n\n/** Maps a matrix row to its entry. Nothing here inspects the model ID. */\nfunction createLanguageModelEntry(\n row: CerebrasLanguageModelRow,\n): CerebrasLanguageModelEntry {\n const language: LanguageCapabilities = {\n inputs: { image: row.image, audio: false },\n objectGeneration: row.objectGeneration,\n tools: {\n usage:\n row.functionTools === 'unknown'\n ? 'unknown'\n : row.functionTools !== false,\n streaming:\n row.functionTools === 'unknown'\n ? 'unknown'\n : row.functionTools !== false &&\n row.functionTools.includes('streaming'),\n },\n reasoning: { support: row.reasoning },\n sampling: {\n temperature: 'unknown',\n topP: 'unknown',\n logprobs: row.logprobs,\n },\n // Keep forwarding JSON schemas for custom IDs as the existing provider does.\n structuredOutput: { jsonSchema: true },\n };\n return {\n capabilities: { language },\n providerOptions: {\n language: declareProviderOptions(\n cerebrasProviderOptions.language,\n row.documented ? true : 'unknown',\n {\n strictJsonSchema: {\n condition: 'Requires a JSON schema response format.',\n },\n logprobs: row.logprobs,\n topLogprobs: row.logprobs,\n serviceTier: {\n condition: 'Requires a preview-enabled dedicated endpoint.',\n },\n queueThreshold: {\n condition:\n 'Requires flex/auto on a preview-enabled dedicated endpoint.',\n },\n reasoningEffort:\n row.reasoning === true\n ? { condition: 'Supported values depend on the reasoning model.' }\n : row.reasoning,\n reasoningFormat:\n row.reasoning === true\n ? {\n condition: 'Available formats depend on the reasoning model.',\n }\n : row.reasoning,\n },\n ),\n },\n };\n}\n\nexport const cerebrasModelCatalog: Readonly<\n Record<string, CerebrasLanguageModelEntry>\n> = Object.fromEntries(\n Object.entries<CerebrasLanguageModelRow>(languageModelDefinitions).map(\n ([modelId, row]) => [modelId, createLanguageModelEntry(row)],\n ),\n);\n\n/** Row for every model ID that is not listed in the matrix. */\nconst unlistedLanguageModelRow: CerebrasLanguageModelRow = {\n documented: false,\n image: 'unknown',\n objectGeneration: 'unknown',\n functionTools: 'unknown',\n reasoning: 'unknown',\n logprobs: 'unknown',\n};\n\n/**\n * Returns the entry of a listed language model ID from its row. Every other\n * model ID uses the row for unlisted IDs.\n */\nexport function getCerebrasLanguageModelEntry(\n modelId: string,\n): CerebrasLanguageModelEntry {\n return Object.prototype.hasOwnProperty.call(cerebrasModelCatalog, modelId)\n ? cerebrasModelCatalog[modelId]\n : createLanguageModelEntry(unlistedLanguageModelRow);\n}\n\nfunction declareProviderOptions<Option extends string>(\n definitions: Readonly<Record<Option, ProviderOptionDefinition>>,\n support: ModelCapability,\n exceptions: Partial<Record<Option, ModelCapability>>,\n): Record<Option, ModelCapability> {\n return Object.fromEntries(\n (Object.keys(definitions) as Option[]).map(option => [\n option,\n exceptions[option] ?? support,\n ]),\n ) as Record<Option, ModelCapability>;\n}\n\n/** Known model IDs, derived from the declarations used to build the catalog. */\nexport type CerebrasModelIds = {\n language: keyof typeof languageModelDefinitions;\n};\n","import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n type Resolvable,\n resolveWith,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { CerebrasChatLanguageModel } from './cerebras-chat-language-model';\nimport type { CerebrasChatModelId } from './cerebras-chat-options';\nimport { z } from 'zod/v4';\nimport { VERSION } from './version';\nimport { cerebrasMetadataExtractor } from './cerebras-metadata-extractor';\nimport { getCerebrasLanguageModelEntry } from './cerebras-model-catalog';\n\n// Add error schema and structure\nconst cerebrasErrorSchema = z.object({\n message: z.string(),\n type: z.string(),\n param: z.string(),\n code: z.string(),\n});\n\nexport type CerebrasErrorData = z.infer<typeof cerebrasErrorSchema>;\n\nconst cerebrasErrorStructure: ProviderErrorStructure<CerebrasErrorData> = {\n errorSchema: cerebrasErrorSchema,\n errorToMessage: data => data.message,\n};\n\n/**\n * Cerebras expects assistant reasoning history in the `reasoning` field, while\n * the shared OpenAI-compatible converter serializes it as `reasoning_content`.\n */\nfunction transformCerebrasRequestBody(\n args: Record<string, any>,\n): Record<string, any> {\n const {\n max_tokens: maxTokens,\n parallelToolCalls,\n topLogprobs,\n logitBias,\n serviceTier,\n queueThreshold: _queueThreshold,\n reasoningFormat,\n promptCacheKey,\n ...restArgs\n } = args;\n\n return {\n ...restArgs,\n ...(maxTokens !== undefined && {\n max_completion_tokens: maxTokens,\n }),\n ...(parallelToolCalls !== undefined && {\n parallel_tool_calls: parallelToolCalls,\n }),\n ...(topLogprobs !== undefined && { top_logprobs: topLogprobs }),\n ...(logitBias !== undefined && { logit_bias: logitBias }),\n ...(serviceTier !== undefined && { service_tier: serviceTier }),\n ...(reasoningFormat !== undefined && {\n reasoning_format: reasoningFormat,\n }),\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n messages: Array.isArray(args.messages)\n ? args.messages.map(message => {\n if (\n message == null ||\n typeof message !== 'object' ||\n message.role !== 'assistant' ||\n !('reasoning_content' in message)\n ) {\n return message;\n }\n\n const { reasoning_content, ...rest } = message;\n\n return {\n ...rest,\n ...(!('reasoning' in rest) && reasoning_content !== undefined\n ? { reasoning: reasoning_content }\n : {}),\n };\n })\n : args.messages,\n };\n}\n\nexport interface CerebrasProviderSettings {\n /**\n * Cerebras API key.\n * A function is called before each request and may return a promise.\n */\n apiKey?: Resolvable<string>;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface CerebrasProvider extends ProviderV4 {\n /**\n * Creates a Cerebras model for text generation.\n */\n (modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras model for text generation.\n */\n languageModel(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras chat model for text generation.\n */\n chat(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createCerebras(\n options: CerebrasProviderSettings = {},\n): CerebrasProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.cerebras.ai/v1',\n );\n const getHeaders = () =>\n resolveWith(options.apiKey, apiKey =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey,\n environmentVariableName: 'CEREBRAS_API_KEY',\n description: 'Cerebras API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-cerebras/${VERSION}`,\n ),\n );\n\n const createLanguageModel = (modelId: CerebrasChatModelId) => {\n return new CerebrasChatLanguageModel(modelId, {\n provider: `cerebras.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: cerebrasErrorStructure,\n supportsStructuredOutputs:\n getCerebrasLanguageModelEntry(modelId).capabilities.language\n .structuredOutput.jsonSchema,\n transformRequestBody: transformCerebrasRequestBody,\n metadataExtractor: cerebrasMetadataExtractor,\n });\n };\n\n const provider = (modelId: CerebrasChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const cerebras = createCerebras();\n"],"mappings":";;;;;AAIA,MAAa,mCAAmC,EAAE,OAAO;CACvD,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,kBAAkB,EAAE,QAAQ,CAAC,CAAC,SAAS;CACvC,mBAAmB,EAAE,QAAQ,CAAC,CAAC,SAAS;CACxC,UAAU,EAAE,QAAQ,CAAC,CAAC,S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AAmB,GAAG,SAAS;GAEvC,OAAO;IACL,GAAG;IACH,GAAI,EAAE,eAAe,SAAS,sBAAsB,KAAA,IAChD,EAAE,WAAW,kBAAkB,IAC/B,CAAC;GACP;EACF,CAAC,IACD,KAAK;CACX;AACF;AA6CA,SAAgB,eACd,UAAoC,CAAC,GACnB;CAClB,MAAM,UAAU,qBACd,QAAQ,WAAW,4BACrB;CACA,MAAM,mBACJ,YAAY,QAAQ,SAAQ,WAC1B,oBACE;EACE,eAAe,UAAU,WAAW;GAClC;GACA,yBAAyB;GACzB,aAAa;EACf,CAAC;EACD,GAAG,QAAQ;CACb,GACA,mBAAmB,SACrB,CACF;CAEF,MAAM,uBAAuB,YAAiC;EAC5D,OAAO,IAAI,0BAA0B,SAAS;GAC5C,UAAU;GACV,MAAM,EAAE,WAAW,GAAG,UAAU;GAChC,SAAS;GACT,OAAO,QAAQ;GACf,gBAAgB;GAChB,2BACE,8BAA8B,OAAO,CAAC,CAAC,aAAa,SACjD,iBAAiB;GACtB,sBAAsB;GACtB,mBAAmB;EACrB,CAAC;CACH;CAEA,MAAM,YAAY,YAChB,oBAAoB,OAAO;CAE7B,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAEhB,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,OAAO;AACT;AAEA,MAAa,WAAW,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/cerebras",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,16 +29,17 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
33
|
-
"@ai-sdk/provider": "4.0.
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.98",
|
|
33
|
+
"@ai-sdk/provider": "4.0.40",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.87"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "22.19.19",
|
|
38
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
38
39
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
39
40
|
"@vercel/ai-tsdown-config": "0.0.0",
|
|
40
41
|
"tsdown": "^0.23.0",
|
|
41
|
-
"typescript": "6.0.
|
|
42
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
42
43
|
"zod": "4.6.7"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
@@ -70,6 +71,9 @@
|
|
|
70
71
|
"clean": "del-cli docs",
|
|
71
72
|
"type-check": "tsc --noEmit",
|
|
72
73
|
"test": "pnpm test:node && pnpm test:edge",
|
|
74
|
+
"test:node22": "node ../../tools/with-node.mjs 22 pnpm test",
|
|
75
|
+
"test:node24": "node ../../tools/with-node.mjs 24 pnpm test",
|
|
76
|
+
"test:node26": "node ../../tools/with-node.mjs 26 pnpm test",
|
|
73
77
|
"test:update": "pnpm test:node -u",
|
|
74
78
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
75
79
|
"test:edge": "vitest --config vitest.edge.config.js --run",
|
|
@@ -42,20 +42,85 @@ type CerebrasLanguageModelEntry = ModelEntry & {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
/**
|
|
46
|
+
* One row of the language model matrix. Every capability that differs between
|
|
47
|
+
* models is one flat cell, and every listed model fills in every cell. Nothing
|
|
48
|
+
* is derived from the model ID.
|
|
49
|
+
*
|
|
50
|
+
* Facts that depend on each other share one cell, so a row cannot contradict
|
|
51
|
+
* itself: a cell is a single value, one of a fixed set of values, or the list
|
|
52
|
+
* of what the model supports.
|
|
53
|
+
*/
|
|
54
|
+
export type CerebrasLanguageModelRow = {
|
|
55
|
+
/**
|
|
56
|
+
* `false`: nothing is documented for the model ID. Its provider options
|
|
57
|
+
* without their own cell are then reported as `'unknown'`.
|
|
58
|
+
*/
|
|
59
|
+
documented: boolean;
|
|
60
|
+
image: ModelCapability;
|
|
61
|
+
objectGeneration: ModelCapability;
|
|
62
|
+
/**
|
|
63
|
+
* `false`: the model does not call function tools. Otherwise it does, and
|
|
64
|
+
* the list holds what it supports on top of that: `streaming` means it
|
|
65
|
+
* also calls tools in a streamed response. `'unknown'`: not documented.
|
|
66
|
+
*/
|
|
67
|
+
functionTools: 'unknown' | false | readonly 'streaming'[];
|
|
68
|
+
/**
|
|
69
|
+
* Reasons. `true`: the `reasoningEffort` and `reasoningFormat` options are
|
|
70
|
+
* accepted, with values that depend on the model.
|
|
71
|
+
*/
|
|
72
|
+
reasoning: ModelCapability;
|
|
73
|
+
/** Returns token log probabilities (`logprobs`, `topLogprobs`). */
|
|
74
|
+
logprobs: ModelCapability;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Language model matrix: model IDs by capability. To add a model, add a row
|
|
79
|
+
* and fill in every column.
|
|
80
|
+
*/
|
|
81
|
+
const languageModelDefinitions = {
|
|
82
|
+
'gpt-oss-120b': {
|
|
83
|
+
documented: true,
|
|
84
|
+
image: false,
|
|
85
|
+
objectGeneration: true,
|
|
86
|
+
functionTools: ['streaming'],
|
|
87
|
+
reasoning: true,
|
|
88
|
+
logprobs: true,
|
|
89
|
+
},
|
|
90
|
+
'gemma-4-31b': {
|
|
91
|
+
documented: true,
|
|
92
|
+
image: true,
|
|
93
|
+
objectGeneration: true,
|
|
94
|
+
functionTools: ['streaming'],
|
|
95
|
+
reasoning: true,
|
|
96
|
+
logprobs: true,
|
|
97
|
+
},
|
|
98
|
+
} satisfies Record<string, CerebrasLanguageModelRow>;
|
|
50
99
|
|
|
51
|
-
|
|
52
|
-
|
|
100
|
+
/** Maps a matrix row to its entry. Nothing here inspects the model ID. */
|
|
101
|
+
function createLanguageModelEntry(
|
|
102
|
+
row: CerebrasLanguageModelRow,
|
|
103
|
+
): CerebrasLanguageModelEntry {
|
|
53
104
|
const language: LanguageCapabilities = {
|
|
54
|
-
inputs: { image: image
|
|
55
|
-
objectGeneration:
|
|
56
|
-
tools: {
|
|
57
|
-
|
|
58
|
-
|
|
105
|
+
inputs: { image: row.image, audio: false },
|
|
106
|
+
objectGeneration: row.objectGeneration,
|
|
107
|
+
tools: {
|
|
108
|
+
usage:
|
|
109
|
+
row.functionTools === 'unknown'
|
|
110
|
+
? 'unknown'
|
|
111
|
+
: row.functionTools !== false,
|
|
112
|
+
streaming:
|
|
113
|
+
row.functionTools === 'unknown'
|
|
114
|
+
? 'unknown'
|
|
115
|
+
: row.functionTools !== false &&
|
|
116
|
+
row.functionTools.includes('streaming'),
|
|
117
|
+
},
|
|
118
|
+
reasoning: { support: row.reasoning },
|
|
119
|
+
sampling: {
|
|
120
|
+
temperature: 'unknown',
|
|
121
|
+
topP: 'unknown',
|
|
122
|
+
logprobs: row.logprobs,
|
|
123
|
+
},
|
|
59
124
|
// Keep forwarding JSON schemas for custom IDs as the existing provider does.
|
|
60
125
|
structuredOutput: { jsonSchema: true },
|
|
61
126
|
};
|
|
@@ -64,11 +129,13 @@ function createLanguageModelEntry(image?: boolean): CerebrasLanguageModelEntry {
|
|
|
64
129
|
providerOptions: {
|
|
65
130
|
language: declareProviderOptions(
|
|
66
131
|
cerebrasProviderOptions.language,
|
|
67
|
-
|
|
132
|
+
row.documented ? true : 'unknown',
|
|
68
133
|
{
|
|
69
134
|
strictJsonSchema: {
|
|
70
135
|
condition: 'Requires a JSON schema response format.',
|
|
71
136
|
},
|
|
137
|
+
logprobs: row.logprobs,
|
|
138
|
+
topLogprobs: row.logprobs,
|
|
72
139
|
serviceTier: {
|
|
73
140
|
condition: 'Requires a preview-enabled dedicated endpoint.',
|
|
74
141
|
},
|
|
@@ -77,15 +144,15 @@ function createLanguageModelEntry(image?: boolean): CerebrasLanguageModelEntry {
|
|
|
77
144
|
'Requires flex/auto on a preview-enabled dedicated endpoint.',
|
|
78
145
|
},
|
|
79
146
|
reasoningEffort:
|
|
80
|
-
|
|
147
|
+
row.reasoning === true
|
|
81
148
|
? { condition: 'Supported values depend on the reasoning model.' }
|
|
82
|
-
:
|
|
149
|
+
: row.reasoning,
|
|
83
150
|
reasoningFormat:
|
|
84
|
-
|
|
151
|
+
row.reasoning === true
|
|
85
152
|
? {
|
|
86
153
|
condition: 'Available formats depend on the reasoning model.',
|
|
87
154
|
}
|
|
88
|
-
:
|
|
155
|
+
: row.reasoning,
|
|
89
156
|
},
|
|
90
157
|
),
|
|
91
158
|
},
|
|
@@ -95,18 +162,31 @@ function createLanguageModelEntry(image?: boolean): CerebrasLanguageModelEntry {
|
|
|
95
162
|
export const cerebrasModelCatalog: Readonly<
|
|
96
163
|
Record<string, CerebrasLanguageModelEntry>
|
|
97
164
|
> = Object.fromEntries(
|
|
98
|
-
Object.entries(
|
|
99
|
-
modelId,
|
|
100
|
-
|
|
101
|
-
]),
|
|
165
|
+
Object.entries<CerebrasLanguageModelRow>(languageModelDefinitions).map(
|
|
166
|
+
([modelId, row]) => [modelId, createLanguageModelEntry(row)],
|
|
167
|
+
),
|
|
102
168
|
);
|
|
103
169
|
|
|
170
|
+
/** Row for every model ID that is not listed in the matrix. */
|
|
171
|
+
const unlistedLanguageModelRow: CerebrasLanguageModelRow = {
|
|
172
|
+
documented: false,
|
|
173
|
+
image: 'unknown',
|
|
174
|
+
objectGeneration: 'unknown',
|
|
175
|
+
functionTools: 'unknown',
|
|
176
|
+
reasoning: 'unknown',
|
|
177
|
+
logprobs: 'unknown',
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns the entry of a listed language model ID from its row. Every other
|
|
182
|
+
* model ID uses the row for unlisted IDs.
|
|
183
|
+
*/
|
|
104
184
|
export function getCerebrasLanguageModelEntry(
|
|
105
185
|
modelId: string,
|
|
106
186
|
): CerebrasLanguageModelEntry {
|
|
107
187
|
return Object.prototype.hasOwnProperty.call(cerebrasModelCatalog, modelId)
|
|
108
188
|
? cerebrasModelCatalog[modelId]
|
|
109
|
-
: createLanguageModelEntry();
|
|
189
|
+
: createLanguageModelEntry(unlistedLanguageModelRow);
|
|
110
190
|
}
|
|
111
191
|
|
|
112
192
|
function declareProviderOptions<Option extends string>(
|
|
@@ -124,5 +204,5 @@ function declareProviderOptions<Option extends string>(
|
|
|
124
204
|
|
|
125
205
|
/** Known model IDs, derived from the declarations used to build the catalog. */
|
|
126
206
|
export type CerebrasModelIds = {
|
|
127
|
-
language: keyof typeof
|
|
207
|
+
language: keyof typeof languageModelDefinitions;
|
|
128
208
|
};
|