-
Couldn't load subscription status.
- Fork 1.2k
Update Cerebras Integration #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…vercel ai-sdk integration. As well as added updated models to types/models.ts & updated docs to include Cerebras key integration
🦋 Changeset detectedLatest commit: d404d3d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR modernizes the Cerebras integration by migrating from a custom OpenAI-based implementation to the official @ai-sdk/cerebras integration, while adding 7 new Cerebras models.
Key Changes:
- Refactored
CerebrasClient.tsto delegate all functionality toAISdkClientusing@ai-sdk/cerebras - Removed ~280 lines of custom OpenAI wrapper code in favor of native AI SDK support
- Added 7 new models: llama-4 (maverick/scout), qwen-3 (multiple variants), and gpt-oss-120b
- Updated documentation to include
CEREBRAS_API_KEYenvironment variable - Exported
CerebrasClientinlib/index.ts
Implementation:
The refactor follows the established pattern used by other AI SDK integrations in the codebase. The CerebrasClient now strips the cerebras- prefix from model names and creates a language model instance via createCerebras(), then wraps it with AISdkClient to handle all LLM operations consistently.
Testing:
PR author reports passing all evals (iframe_form_filling, amazon_add_to_cart, dropdown, extract_repo_name, allrecipes, imbd_movie_details, sciquest) with Cerebras models.
Confidence Score: 4/5
- This PR is safe to merge with one minor process requirement needed.
- The code changes are well-structured and follow existing patterns in the codebase. The migration to
@ai-sdk/cerebrasis a clear improvement that removes custom wrapper code. The author has tested across multiple evals. However, the PR is missing a changeset file which is required by project policy for documenting version bumps and changes. - No files require special attention - all changes are straightforward and follow established patterns. Only missing changeset needs to be added.
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| lib/llm/CerebrasClient.ts | 5/5 | Refactored from OpenAI-based implementation to @ai-sdk/cerebras integration, delegating all logic to AISdkClient. Clean implementation with proper model name transformation. |
| types/model.ts | 5/5 | Added 7 new Cerebras model names (llama-4, qwen-3, gpt-oss) to the enum. All models follow existing naming convention. |
| lib/llm/LLMProvider.ts | 5/5 | Added new Cerebras models to modelToProviderMap. All mappings are correct and consistent. |
| docs/configuration/models.mdx | 5/5 | Added CEREBRAS_API_KEY to environment variable documentation. |
| lib/index.ts | 4/5 | Exported CerebrasClient for external use. Missing changeset file for this PR. |
Sequence Diagram
sequenceDiagram
participant User
participant LLMProvider
participant CerebrasClient
participant AISdkClient
participant CerebrasAPI as Cerebras API
User->>LLMProvider: getClient(modelName, clientOptions)
LLMProvider->>LLMProvider: Check modelToProviderMap["cerebras-*"]
LLMProvider->>CerebrasClient: new CerebrasClient({logger, cache, modelName, clientOptions})
CerebrasClient->>CerebrasClient: Strip "cerebras-" prefix from modelName
CerebrasClient->>CerebrasClient: createCerebras({apiKey, baseURL})
CerebrasClient->>CerebrasClient: cerebrasProvider(actualModelName)
CerebrasClient->>AISdkClient: new AISdkClient({model, logger, cache})
AISdkClient-->>CerebrasClient: Return client instance
CerebrasClient-->>LLMProvider: Return CerebrasClient instance
LLMProvider-->>User: Return client
User->>CerebrasClient: createChatCompletion(options)
CerebrasClient->>AISdkClient: createChatCompletion(options)
AISdkClient->>AISdkClient: Format messages to CoreMessage[]
alt Has response_model
AISdkClient->>CerebrasAPI: generateObject(model, messages, schema)
CerebrasAPI-->>AISdkClient: Return structured object
else No response_model
AISdkClient->>CerebrasAPI: generateText(model, messages, tools)
CerebrasAPI-->>AISdkClient: Return text/tool calls
end
AISdkClient->>AISdkClient: Transform response format
AISdkClient-->>CerebrasClient: Return formatted response
CerebrasClient-->>User: Return response
Additional Comments (1)
-
lib/index.ts, line 1052 (link)style: Missing changeset - custom instruction requires all PRs with code changes to include a changeset. Create one using
npx changeset.Context Used: Rule from
dashboard- All PRs that make code changes must include a changeset to document the version bump and changes. (source)
5 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
Refactored Cerebras integration from a custom OpenAI-compatible wrapper to use the official @ai-sdk/cerebras package through delegation to AISdkClient. This eliminates 300+ lines of custom formatting, caching, and error handling logic.
Key changes:
CerebrasClientnow creates anAISdkClientinstance and delegates allcreateChatCompletioncalls to it- Added 7 new Cerebras model variants (Llama 4, Qwen 3, GPT-OSS models)
- Updated documentation to include
CEREBRAS_API_KEYenvironment variable - Properly strips
cerebras-prefix before passing model name to the SDK - Follows the same delegation pattern used by other AI SDK integrations in the codebase
Minor type issue: The import of ClientOptions from types/model (which is OpenAIClientOptions | AnthropicClientOptions) doesn't perfectly match Cerebras SDK's expected options shape, though it works at runtime due to overlapping properties.
Confidence Score: 4/5
- This PR is safe to merge with minimal risk
- The refactoring significantly improves code maintainability by delegating to the battle-tested AISdkClient, reducing custom code by 300+ lines. The author tested all models across 7 different evals successfully. The only issue is a minor type mismatch with ClientOptions that doesn't affect runtime behavior. Score is 4 instead of 5 due to the type inconsistency that should ideally be cleaned up.
- lib/llm/CerebrasClient.ts requires attention for the ClientOptions type import - consider creating Cerebras-specific options type
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| lib/llm/CerebrasClient.ts | 3/5 | Refactored from OpenAI wrapper to AI SDK delegation pattern - removed 300+ lines of custom logic, now delegates to AISdkClient; minor issue with ClientOptions type mismatch |
| types/model.ts | 5/5 | Added 7 new Cerebras model variants to AvailableModelSchema |
| lib/llm/LLMProvider.ts | 5/5 | Added 7 new Cerebras models to modelToProviderMap |
Sequence Diagram
sequenceDiagram
participant App as Application
participant LLMProvider as LLMProvider
participant CerebrasClient as CerebrasClient
participant AISdkClient as AISdkClient
participant CerebrasSDK as @ai-sdk/cerebras
participant API as Cerebras API
App->>LLMProvider: getClient("cerebras-llama-3.3-70b", options)
LLMProvider->>LLMProvider: Check modelToProviderMap
LLMProvider->>CerebrasClient: new CerebrasClient({logger, cache, modelName, clientOptions})
CerebrasClient->>CerebrasClient: Strip "cerebras-" prefix
CerebrasClient->>CerebrasSDK: createCerebras({apiKey, baseURL})
CerebrasSDK-->>CerebrasClient: cerebrasProvider
CerebrasClient->>CerebrasSDK: cerebrasProvider(actualModelName)
CerebrasSDK-->>CerebrasClient: languageModel
CerebrasClient->>AISdkClient: new AISdkClient({model, logger, cache, enableCaching})
AISdkClient-->>CerebrasClient: client instance
CerebrasClient-->>LLMProvider: CerebrasClient instance
LLMProvider-->>App: client
App->>CerebrasClient: createChatCompletion(options)
CerebrasClient->>AISdkClient: createChatCompletion(options)
AISdkClient->>AISdkClient: Check cache
AISdkClient->>AISdkClient: Format messages
AISdkClient->>CerebrasSDK: generateObject/generateText()
CerebrasSDK->>API: HTTP Request
API-->>CerebrasSDK: Response
CerebrasSDK-->>AISdkClient: result
AISdkClient->>AISdkClient: Cache result
AISdkClient-->>CerebrasClient: formatted response
CerebrasClient-->>App: response
Additional Comments (1)
-
lib/llm/CerebrasClient.ts, line 3 (link)syntax:
ClientOptionsimported fromtypes/modelis defined asOpenAIClientOptions | AnthropicClientOptions, but@ai-sdk/cerebrasexpects a different shape ({apiKey?: string, baseURL?: string}). This works at runtime because the relevant properties overlap, but creates type confusion.Then define cerebras-specific options inline or create a new type.
No files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR modernizes the Cerebras integration by replacing a custom OpenAI-wrapper implementation with the official @ai-sdk/cerebras package. The changes significantly simplify the codebase by removing ~300 lines of custom message formatting, tool handling, and JSON parsing logic. The new implementation delegates all functionality to AISdkClient, which provides standardized handling through the Vercel AI SDK.
Key Changes:
- Replaced
openaidependency with@ai-sdk/cerebras - Removed custom message formatting and tool handling code
- Added 7 new Cerebras models (GPT-OSS, Llama 4, Qwen 3 variants)
- Updated documentation to include
CEREBRAS_API_KEYsetup - Included proper changeset for version bump
Technical Approach:
The refactor follows the delegation pattern used by other providers in the codebase. The CerebrasClient now acts as a thin wrapper that:
- Strips the
cerebras-prefix from model names - Initializes the Cerebras provider with API credentials
- Wraps the language model in
AISdkClientfor unified handling - Remaps logger categories from "aisdk" to "cerebras"
The implementation is consistent with the repository's architecture and leverages generateObject/generateText from the AI SDK, aligning with custom instruction c6910a06-83cf-42d7-8d62-5bcf8d671b6f for reliable parsing.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The implementation follows established patterns in the codebase, uses the official AI SDK package, includes proper testing (7 evals passed per PR description), has a complete changeset, and significantly reduces code complexity by removing custom implementations. No breaking changes to the public API.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| lib/llm/CerebrasClient.ts | 5/5 | Replaced custom OpenAI-based implementation with @ai-sdk/cerebras, delegating all functionality to AISdkClient wrapper. Clean refactor with proper model name handling. |
Sequence Diagram
sequenceDiagram
participant Client as Stagehand Client
participant Provider as LLMProvider
participant CerebrasClient as CerebrasClient
participant AISdkClient as AISdkClient
participant CerebrasSDK as @ai-sdk/cerebras
participant CerebrasAPI as Cerebras API
Client->>Provider: Request with cerebras model
Provider->>CerebrasClient: new CerebrasClient({logger, cache, modelName})
CerebrasClient->>CerebrasClient: Strip "cerebras-" prefix from modelName
CerebrasClient->>CerebrasSDK: createCerebras({apiKey, baseURL})
CerebrasSDK-->>CerebrasClient: cerebrasProvider
CerebrasClient->>CerebrasSDK: cerebrasProvider(actualModelName)
CerebrasSDK-->>CerebrasClient: languageModel
CerebrasClient->>AISdkClient: new AISdkClient({model, logger, cache})
AISdkClient-->>CerebrasClient: client instance
Client->>CerebrasClient: createChatCompletion(options)
CerebrasClient->>AISdkClient: createChatCompletion(options)
AISdkClient->>AISdkClient: Check cache
AISdkClient->>AISdkClient: Format messages
AISdkClient->>CerebrasSDK: generateObject/generateText
CerebrasSDK->>CerebrasAPI: API Request
CerebrasAPI-->>CerebrasSDK: Response
CerebrasSDK-->>AISdkClient: Structured response
AISdkClient->>AISdkClient: Cache response
AISdkClient-->>CerebrasClient: Formatted result
CerebrasClient-->>Client: Result
1 file reviewed, no comments
why
what changed
Compatibility notes
Test plan
|
why
The Cerebras integration was non-functional in testing and outdated in terms of models, and implementation.
what changed
Changed the way LLM calls were made with Cerebras, updated to use the vercel ai-sdk instead of OpenAI. Also updated model lists from Cerebras.
test plan
I ran through and passed all Cerebras models on the following evals: iframe_form_filling, amazon_add_to_cart, dropdown, extract_repo_name, allrecipes, imbd_movie_details, sciquest