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:

pip install openai
from agno.agent import Agent
from agno.models.cerebras import CerebrasOpenAI

agent = Agent(
    model=CerebrasOpenAI(
        id="llama-4-scout-17b-16e-instruct",  # Model ID to use
        # base_url="https://api.cerebras.ai", # Optional: default endpoint for Cerebras
    ),
    markdown=True,
)

# Print the response in the terminal
agent.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 endpointhttps://api.cerebras.ai

Examples

  • View more examples here.