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 openai
1from kern.agent import Agent
2from kern.models.cerebras import CerebrasOpenAI
3
4agent = Agent(
5 model=CerebrasOpenAI(
6 id="llama-4-scout-17b-16e-instruct", # Model ID to use
7 # base_url="https://api.cerebras.ai", # Optional: default endpoint for Cerebras
8 ),
9 markdown=True,
10)
11
12# Print the response in the terminal
13agent.print_response("write a two sentence horror story")

Configuration Options

The CerebrasOpenAI class accepts the following parameters:

ParameterTypeDescriptionDefault
idstrModel identifier (e.g., "llama-4-scout-17b-16e-instruct")Required
namestrDisplay name for the model"Cerebras"
providerstrProvider name"Cerebras"
api_keystrAPI key (falls back to CEREBRAS_API_KEY environment variable)None
base_urlstrURL of the Cerebras OpenAI-compatible endpoint"https://api.cerebras.ai"

CerebrasOpenAI also supports the parameters of OpenAI.

Examples

  • View more examples here.