Backport: feat(cerebras): add chat language model provider#15428
Merged
github-actions[bot] merged 2 commits intoMay 19, 2026
Conversation
## Background #15349 this is a follow up to #15416. cerebras models could return a valid structured JSON answer, like {"result":"2026"}, while also marking the response as `tool_calls` and repeating a tool call in the same response. The AI SDK interpreted that as “keep calling tools,” so the loop continued until stopWhen was hit. Because the final step still had finish reason `tool-calls`, `result.output` was never parsed and threw `NoOutputGeneratedError` ## Summary - Added a CerebrasChatLanguageModel wrapper around the OpenAI-compatible chat model - For structured JSON output calls only, when cerebras returns non-empty text with raw finish reason `tool_calls`, we treat it as the final structured answer - In that narrow case, we normalize the finish reason to `stop` and drop the stray repeated tool-call part - Real tool-call turns without text are still preserved and executed normally what would have been a bug fix was treated as an opportunity to handle cerebras quirks specifically ## Manual Verification verified by running the repro: ```ts import { NoOutputGeneratedError, Output, isStepCount, tool, ToolLoopAgent } from "ai"; import z from "zod"; import { cerebras } from "@ai-sdk/cerebras"; import { run } from '../../lib/run'; run(async () => { const agent = new ToolLoopAgent({ instructions: "Use the required structured output. For simple arithmetic you may answer directly.", model: cerebras("zai-glm-4.7"), tools: { nonUsefulTool: tool({ description: "A non-useful tool that returns a magic number", inputSchema: z.object({}), execute: () => { return 2026; }, }), }, output: Output.object({ schema: z.object({ result: z.string() }), }), stopWhen: isStepCount(5), }); const result = await agent.generate({ prompt: "what is the magic number?", }); console.log( 'steps:', JSON.stringify( result.steps.map(step => ({ finishReason: step.finishReason, text: step.text, toolCalls: step.toolCalls.map(toolCall => ({ toolName: toolCall.toolName, input: toolCall.input, })), })), null, 2, ), ); try { console.log(result.output); } catch (cause) { if (NoOutputGeneratedError.isInstance(cause)) { console.error( "Structured output missing (last step did not yield valid JSON).", "finishReason:", result.finishReason, "lastText:", JSON.stringify(result.text), ); throw cause; } throw cause; } }); ``` ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #15349 --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
5 tasks
aayush-kapoor
approved these changes
May 19, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an automated backport of #15420 to the release-v6.0 branch. FYI @aayush-kapoor