Cerebras OpenAI
Use Cerebras via OpenAI-compatible interface in Kern agents.
OpenAI-Compatible Integration
Cerebras can also be used via an OpenAI-compatible interface, making it easy to integrate with tools and libraries that expect the OpenAI API.
Using the OpenAI-Compatible Class
The CerebrasOpenAI class provides an OpenAI-style interface for Cerebras models:
First, install openai:
1uv pip install openai1from kern.agent import Agent2from kern.models.cerebras import CerebrasOpenAI34agent = Agent(5 model=CerebrasOpenAI(6 id="llama-4-scout-17b-16e-instruct", # Model ID to use7 # base_url="https://api.cerebras.ai", # Optional: default endpoint for Cerebras8 ),9 markdown=True,10)1112# Print the response in the terminal13agent.print_response("write a two sentence horror story")Configuration Options
The CerebrasOpenAI class accepts the following parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
id | str | Model identifier (e.g., "llama-4-scout-17b-16e-instruct") | Required |
name | str | Display name for the model | "Cerebras" |
provider | str | Provider name | "Cerebras" |
api_key | str | API key (falls back to CEREBRAS_API_KEY environment variable) | None |
base_url | str | URL of the Cerebras OpenAI-compatible endpoint | "https://api.cerebras.ai" |
CerebrasOpenAI also supports the parameters of OpenAI.
Examples
- View more examples here.