Skip to content

Conversation

@weeta-code
Copy link

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

…vercel ai-sdk integration. As well as added updated models to types/models.ts & updated docs to include Cerebras key integration
@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2025

🦋 Changeset detected

Latest 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

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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.ts to delegate all functionality to AISdkClient using @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_KEY environment variable
  • Exported CerebrasClient in lib/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/cerebras is 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
Loading

Additional Comments (1)

  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

Edit Code Review Agent Settings | Greptile

@weeta-code
Copy link
Author

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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:

  • CerebrasClient now creates an AISdkClient instance and delegates all createChatCompletion calls to it
  • Added 7 new Cerebras model variants (Llama 4, Qwen 3, GPT-OSS models)
  • Updated documentation to include CEREBRAS_API_KEY environment 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
Loading

Additional Comments (1)

  1. lib/llm/CerebrasClient.ts, line 3 (link)

    syntax: ClientOptions imported from types/model is defined as OpenAIClientOptions | AnthropicClientOptions, but @ai-sdk/cerebras expects 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

Edit Code Review Agent Settings | Greptile

@weeta-code
Copy link
Author

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 openai dependency 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_KEY setup
  • 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:

  1. Strips the cerebras- prefix from model names
  2. Initializes the Cerebras provider with API credentials
  3. Wraps the language model in AISdkClient for unified handling
  4. 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
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@weeta-code
Copy link
Author

why

  • Stability & maintainability: The old Cerebras client re-implemented message formatting, tool handling, and JSON parsing on top of OpenAI's SDK with a baseURL override. This implementation was brittle and higher-maintenance.
  • Consistency: Other providers already standardize on the Vercel AI SDK via our AISdkClient. Moving Cerebras to the same pattern reduces any potential future drift.
  • Feature parity & easier upgrades: Using @ai-sdk/cerebras keeps us aligned with the provider's latest behavior and model roster without custom glue.
  • Code reduction: ~300 lines of custom logic deleted -> simpler, safer code.

what changed

  • Refactor: lib/llm/CerebrasClient.ts now: strips the cerebras- prefix to get the actual model id. Instantiates the Cerebras provider via createCerebras() from @ai-sdk/cerebras. Wraps the language model with our AISdkClient for unified request/response handling, logging, and (when enabled) caching.
  • Exports: lib/index.ts now exports CerebrasClient.
  • Model map: lib/llm/LLMProvider.ts maps new model ids to "cerebras".
  • Type enum: types/model.ts adds the latest Cerebras models.
  • Docs: doc/configuration/models.mdx now properly documents new API key configuration for Cerebras.
  • Housekeeping: Removed legacy OpenAI-with-baseURL path and the associated tool/JSON plumbing.

Compatibility notes

  • API surface: Callers still select models via cerebras-* names.
  • Env var: if anyone previously relied on an OpenAI API key with a Cerebras baseURL, they must set CEREBRAS_API_KEY instead.
  • Vision: hasVision remains false for Cerebras (unchanged behavior).

Test plan

  • Run the existing eval suite on the following test (passed on every model tested.):
    • iframe_form_filling, amazon_add_to_cart, dropdown,
      extract_repo_name, allrecipes, imdb_movie_details
      sciquest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant