### Install Dependencies and Configure Environment Source: https://inference-docs.cerebras.ai/integrations/stagehand Navigate to the project directory, install dependencies, and copy the example environment file. ```bash cd my-stagehand-app npm install cp .env.example .env ``` -------------------------------- ### Complete Example: Setup and Traced Request with Cerebras Source: https://inference-docs.cerebras.ai/integrations/arize-phoenix A comprehensive example demonstrating the setup for Phoenix integration with Cerebras AI and making a traced request. This includes environment variable loading and client initialization. ```python import os from dotenv import load_dotenv from phoenix.otel import register from openai import OpenAI load_dotenv() # For Phoenix Cloud instances created BEFORE June 24, 2025 if os.getenv("PHOENIX_CLIENT_HEADERS"): os.environ["PHOENIX_CLIENT_HEADERS"] = os.getenv("PHOENIX_CLIENT_HEADERS") # Register with Phoenix Cloud tracer_provider = register( project_name="cerebras-production", auto_instrument=True, ) # Initialize Cerebras client client = OpenAI( api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={ "X-Cerebras-3rd-Party-Integration": "Arize Phoenix" } ) # Make a request - automatically traced response = client.chat.completions.create( model="gpt-oss-120b", messages=[{"role": "user", "content": "Hello!"}] ) print(response.choices[0].message.content) ``` -------------------------------- ### Full Example: Assistant as Calculator Source: https://inference-docs.cerebras.ai/integrations/ag2 A complete example demonstrating the setup of an AssistantAgent configured to act as a calculator, with strict instructions to only perform basic math operations and end with TERMINATE. ```python import os from autogen import AssistantAgent, UserProxyAgent # Configure using environment variable config_list = [ { "model": "gpt-oss-120b", "api_key": os.getenv("CEREBRAS_API_KEY"), "api_type": "cerebras" } ] llm_config = { "config_list": config_list, "temperature": 0.7, } # Create assistant agent with strict instructions assistant = AssistantAgent( name="assistant", llm_config=llm_config, system_message="You are a Python calculator. Only write simple math code. No databases, no imports except basic math. Always end with TERMINATE after showing result." ) ``` -------------------------------- ### Install Libraries and Configure API Keys Source: https://inference-docs.cerebras.ai/cookbook/agents/build-your-own-perplexity Installs the necessary Python libraries (exa-py, cerebras-cloud-sdk) and sets up API keys for Exa and Cerebras. This is the initial setup step for the project. ```python pip install exa-py cerebras-cloud-sdk from exa_py import Exa from cerebras.cloud.sdk import Cerebras # Add your API keys here EXA_API_KEY = "" CEREBRAS_API_KEY = "" client = Cerebras(api_key = CEREBRAS_API_KEY) exa = Exa(api_key = EXA_API_KEY) print("✅ Setup complete") ``` -------------------------------- ### Install Llama Stack Source: https://inference-docs.cerebras.ai/integrations/llama-stack Install the Llama Stack server and client libraries. Use `uv` for faster installation. ```bash pip install llama-stack llama-stack-client ``` ```bash uv pip install llama-stack llama-stack-client ``` -------------------------------- ### Install requests package Source: https://inference-docs.cerebras.ai/integrations/dify Before making API calls, ensure you have the 'requests' package installed. This is a prerequisite for the Python example. ```bash pip install requests ``` -------------------------------- ### Start Flowise Service Source: https://inference-docs.cerebras.ai/integrations/flowise Start the Flowise service after installation. This command launches Flowise on http://localhost:3000. ```bash flowise start ``` -------------------------------- ### Install decK on Linux Source: https://inference-docs.cerebras.ai/integrations/kong-api-gateway Install decK on Linux by downloading the release, extracting it, and copying it to your PATH. Verify the installation by checking the version. ```bash curl -sL https://github.com/Kong/deck/releases/download/v1.43.0/deck_1.43.0_linux_amd64.tar.gz -o deck.tar.gz tar -xf deck.tar.gz -C /tmp sudo cp /tmp/deck /usr/local/bin/ # Verify installation deck version ``` -------------------------------- ### Start a Batch Job Source: https://inference-docs.cerebras.ai/capabilities/batch Initiate a batch job using the uploaded file ID and specify the endpoint and completion window. This example demonstrates starting a batch job with Python, Node.js, and cURL. ```python batch = client.batches.create( input_file_id=input_file.id, endpoint="/v1/chat/completions", completion_window="24h", metadata={"description": "Evaluation run - December 2025"} ) print(f"Batch started: {batch.id}") print(f"Status: {batch.status}") ``` ```javascript const batch = await client.batches.create({ input_file_id: file.id, endpoint: "/v1/chat/completions", completion_window: "24h", metadata: { description: "Evaluation run - December 2025" } }); console.log(`Batch started: ${batch.id}`); console.log(`Status: ${batch.status}`); ``` ```bash curl https://api.cerebras.ai/v1/batches \ -H "Authorization: Bearer $CEREBRAS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "input_file_id": "", "endpoint": "/v1/chat/completions", "completion_window": "24h", "metadata": {"description": "Evaluation run - December 2025"} }' ``` -------------------------------- ### Install decK on Windows Source: https://inference-docs.cerebras.ai/integrations/kong-api-gateway Install decK on Windows by downloading the release, extracting it, and adding it to your PATH. Alternatively, use Chocolatey. Verify the installation by checking the version. ```powershell # Download from GitHub releases curl -sL https://github.com/Kong/deck/releases/download/v1.43.0/deck_1.43.0_windows_amd64.tar.gz -o deck.tar.gz # Extract and add to PATH # Or use: choco install deck # Verify installation deck version ``` -------------------------------- ### Install AI Suite and SDKs Source: https://inference-docs.cerebras.ai/integrations/ai-suite Install the AI Suite library and the Cerebras SDK. If comparing with other providers, install their respective SDKs as well. ```bash pip install aisuite cerebras-cloud-sdk ``` ```bash pip install openai anthropic ``` -------------------------------- ### Install Instructor with Cerebras Support Source: https://inference-docs.cerebras.ai/integrations/instructor Install the Instructor library with the Cerebras Cloud SDK integration. This command also installs necessary dependencies. ```bash pip install "instructor[cerebras-cloud-sdk]" python-dotenv ``` -------------------------------- ### Install Python Dependencies Source: https://inference-docs.cerebras.ai/integrations/exa Install the Exa SDK, OpenAI client, and python-dotenv for managing environment variables. ```bash pip install "exa-py>=2.0" openai python-dotenv ``` -------------------------------- ### Install OpenAI SDK Source: https://inference-docs.cerebras.ai/integrations/huggingface Install the OpenAI SDK library using pip. ```bash pip install openai ``` -------------------------------- ### Install Browser-Use and Dependencies Source: https://inference-docs.cerebras.ai/integrations/browser-use Install the Browser-Use package and its dependencies, including Playwright. Then, install the necessary Playwright browser binaries. ```bash pip install browser-use python-dotenv langchain-openai playwright ``` ```bash playwright install ``` -------------------------------- ### Install OpenCode Source: https://inference-docs.cerebras.ai/integrations/opencode Run this command in your terminal to install OpenCode. After installation, reload your shell configuration to make the `opencode` command available. ```bash curl -fsSL https://opencode.ai/install | bash ``` ```bash source ~/.zshrc ``` ```bash source ~/.bashrc ``` -------------------------------- ### Install Dependencies Source: https://inference-docs.cerebras.ai/integrations/braintrust Install the necessary Python packages for autoevals, braintrust, and openai. ```bash pip install autoevals braintrust openai ``` -------------------------------- ### Install JavaScript/TypeScript Client Source: https://inference-docs.cerebras.ai/integrations/huggingface Install the Hugging Face Inference client for JavaScript/TypeScript using npm. ```bash npm install @huggingface/inference ``` -------------------------------- ### Create Context Directory and Download Sample Data Source: https://inference-docs.cerebras.ai/cookbook/agents/sales-agent-cerebras-livekit Creates a 'context' directory if it doesn't exist and downloads a sample 'products.json' file into it. This prepares the directory for loading context data. ```python !mkdir -p /content/context # Download sample Product JSON Data !wget -nc -P /content/context \ https://gist.githubusercontent.com/ShayneP/f373c26c5166d90446f2bc08baf9bf46/raw/products.json ``` -------------------------------- ### Setup Environment Variables Source: https://inference-docs.cerebras.ai/integrations/opik Configure your project's environment by creating a .env file with your Cerebras and Opik API keys and Opik workspace name. ```bash CEREBRAS_API_KEY=your-cerebras-api-key-here OPIK_API_KEY=your-opik-api-key-here OPIK_WORKSPACE=your-workspace-name ``` -------------------------------- ### Install LlamaIndex and Cerebras Dependencies Source: https://inference-docs.cerebras.ai/integrations/llamaindex Install the core LlamaIndex package and the Cerebras LLM integration. This setup is required before configuring the environment. ```bash pip install llama-index-core llama-index-llms-cerebras ``` -------------------------------- ### Deploy Kong Gateway Quickstart Source: https://inference-docs.cerebras.ai/integrations/kong-api-gateway Deploy a local Kong Gateway data plane connected to Konnect using the provided script. This script sets up a control plane and configures the gateway. ```bash curl -Ls https://get.konghq.com/quickstart | bash ``` -------------------------------- ### Install Hugging Face Hub Client Source: https://inference-docs.cerebras.ai/integrations/huggingface Install the Hugging Face Hub client library using pip. ```bash pip install huggingface_hub ``` -------------------------------- ### Clone Cerebras Docker Demo Repository Source: https://inference-docs.cerebras.ai/integrations/docker Clone the repository to get started with the Docker Cerebras demo. Navigate into the cloned directory to proceed. ```bash git clone https://github.com/sebastiand-cerebras/docker-cerebras-demo cd docker-cerebras-demo ``` -------------------------------- ### Initialize Git Repository Source: https://inference-docs.cerebras.ai/integrations/aider Sets up a new Git repository and performs an initial commit. This is a prerequisite for Aider to commit changes. ```bash git init git config user.name "Your Name" git config user.email "your.email@example.com" git add . git commit -m "Initial commit" ``` -------------------------------- ### Start Aider with Cerebras Model Source: https://inference-docs.cerebras.ai/integrations/aider Initiates an Aider session using a specified Cerebras model. Ensure the model name is correct for your Cerebras setup. ```bash aider --model cerebras/gpt-oss-120b ``` -------------------------------- ### Tool Calling for Chat Completions (Python) Source: https://inference-docs.cerebras.ai/api-reference/chat-completions Implement tool calling in Python for chat completions. This example defines a function to get weather information and uses it. ```python from cerebras.cloud.sdk import Cerebras import os client = Cerebras(api_key=os.environ.get("CEREBRAS_API_KEY")) tools = [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], }, }, "required": ["location"], "additionalProperties": False, }, }, } ] response = client.chat.completions.create( model="gpt-oss-120b", messages=[ {"role": "user", "content": "What's the weather like in Boston today?"} ], tools=tools, tool_choice="auto", ) print(response.choices[0].message.tool_calls) ``` -------------------------------- ### Install Node.js Dependencies Source: https://inference-docs.cerebras.ai/integrations/exa Install the Exa SDK, OpenAI client, and dotenv for managing environment variables in Node.js. ```bash npm install exa-js openai dotenv ``` -------------------------------- ### Stream Chat Completion Response using JavaScript SDK Source: https://inference-docs.cerebras.ai/api-reference/chat-completions Use the JavaScript SDK to stream chat completion responses. This example shows the basic setup for streaming. ```javascript import Cerebras from '@cerebras/cerebras_cloud_sdk'; ``` -------------------------------- ### Basic Chat Completion with OpenRouter Source: https://inference-docs.cerebras.ai/integrations/openrouter Send a request to OpenRouter for chat completions, specifying the model, provider, and message history. This example demonstrates how to get movie recommendations. ```python import requests import json url = "https://openrouter.ai/api/v1/chat/completions" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "HTTP-Referer": "https://cerebras.ai", "X-Title": "Cerebras" } data = { "model": "gpt-oss-120b", "provider": { "only": ["Cerebras"] }, "messages": [ {"role": "system", "content": "You are a helpful assistant that generates movie recommendations."}, {"role": "user", "content": "Suggest a sci-fi movie from the 1990s."} ], "response_format": { "type": "json_schema", "json_schema": { "name": "movie_schema", "strict": True, "schema": movie_schema } } } # Parse and display the result response = requests.post(url, headers=headers, json=data) result = response.json() if 'choices' in result: movie_data = json.loads(result['choices'][0]['message']['content']) print(json.dumps(movie_data, indent=2)) else: print(f"Error: {result}") ``` -------------------------------- ### Multi-Agent Entrypoint Configuration Source: https://inference-docs.cerebras.ai/cookbook/agents/sales-agent-cerebras-livekit Sets up a multi-agent system entry point where the Sales Agent initiates the conversation. It demonstrates how to connect, create an AgentSession, and start the session with a specified agent and room context. ```python async def multi_agent_entrypoint(ctx: JobContext): """Simple multi-agent entry point""" await ctx.connect() # Create session session = AgentSession() # Start with sales agent await session.start( agent=SalesAgent(), room=ctx.room ) # Run the simple multi-agent system jupyter.run_app( WorkerOptions(entrypoint_fnc=multi_agent_entrypoint), jupyter_url="https://jupyter-api-livekit.vercel.app/api/join-token" ) ``` -------------------------------- ### Retrieve a Specific Model using JavaScript Source: https://inference-docs.cerebras.ai/api-reference/models/public-models This JavaScript example shows how to get model details using the `fetch` API. Ensure you replace `gpt-oss-120b` with the target model's ID. ```javascript const modelId = 'gpt-oss-120b'; const response = await fetch( `https://api.cerebras.ai/public/v1/models/${modelId}` ); const model = await response.json(); ``` -------------------------------- ### Create a Basic Voice Agent with Cerebras LLM Source: https://inference-docs.cerebras.ai/integrations/livekit Builds a voice AI agent using OpenAI Whisper for STT and Cerebras for LLM responses. This example initializes STT, LLM, TTS, and VAD, then starts an AgentSession. ```python import logging import os from dotenv import load_dotenv from livekit import agents, api from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import openai, silero load_dotenv() logging.basicConfig(level=logging.INFO) logger = logging.getLogger("voice-agent") CEREBRAS_URL = "https://api.cerebras.ai/v1" CEREBRAS_API_KEY = os.getenv("CEREBRAS_API_KEY") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") LIVEKIT_API_KEY = os.getenv("LIVEKIT_API_KEY") LIVEKIT_API_SECRET = os.getenv("LIVEKIT_API_SECRET") LIVEKIT_URL = os.getenv("LIVEKIT_URL", "wss://cbrs-gk5k98e0.livekit.cloud") class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions="You are a helpful voice AI assistant.") # Initialize OpenAI STT (Speech-to-Text) using Whisper stt = openai.STT( model="whisper-1", api_key=OPENAI_API_KEY ) # Initialize Cerebras LLM for ultra-fast conversation llm = openai.LLM( model="gpt-oss-120b", api_key=CEREBRAS_API_KEY, base_url=CEREBRAS_URL, extra_headers={"X-Cerebras-3rd-Party-Integration": "livekit"} ) async def entrypoint(ctx: agents.JobContext): logger.info(f"Starting agent in room {ctx.room.name}") session = AgentSession( stt=stt, llm=llm, tts=openai.TTS(), # Use OpenAI TTS vad=silero.VAD.load(), ) await session.start( room=ctx.room, agent=Assistant(), ) await session.generate_reply( instructions="Greet the user and offer your assistance." ) if __name__ == "__main__": # Generate and display token if not LIVEKIT_API_KEY or not LIVEKIT_API_SECRET: print("Missing LIVEKIT_API_KEY or LIVEKIT_API_SECRET in .env file") print("Get these from your LiveKit Cloud dashboard: https://cloud.livekit.io/") else: token = api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET) \ .with_identity("test_user") \ .with_grants(api.VideoGrants( room_join=True, room="test_room", )) jwt_token = token.to_jwt() print("\n\nLiveKit Agent Ready to Connect!\033[0m\n\033[94m" + "="*50 + "\033[0m") print(f"\033[94mConnect at: https://agents-playground.livekit.io/\033[0m\n\033[94m") print(f"\033[94mURL: {LIVEKIT_URL}\033[0m") print(f"\033[94mToken: {jwt_token}" + "="*50 + "\033[0m") agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint)) ``` -------------------------------- ### Recommended Project Structures Source: https://inference-docs.cerebras.ai/console/projects Examples of project naming conventions based on deployment stage, application, or business unit. ```text dev, test, prod ``` ```text frontend, internal-tools ``` ```text team-console, team-platform ``` -------------------------------- ### Install CePO Prerequisites Source: https://inference-docs.cerebras.ai/capabilities/cepo Install the OptiLLM library and the latest Cerebras Inference SDK. Ensure you have the latest versions to use CePO. ```bash pip install --upgrade cerebras_cloud_sdk pip install --upgrade optillm ``` -------------------------------- ### Install llama-stack-client Package Source: https://inference-docs.cerebras.ai/integrations/llama-stack Ensure the `llama-stack-client` Python package is installed in your environment. This command installs or updates the client library. ```bash pip install llama-stack-client ``` -------------------------------- ### Install Flowise via NPM Source: https://inference-docs.cerebras.ai/integrations/flowise Install Flowise globally using NPM. Ensure Node.js 18 or higher is installed. ```bash npm install -g flowise ``` -------------------------------- ### Install Dependencies Source: https://inference-docs.cerebras.ai/integrations/foundry Install the OpenAI Python SDK and python-dotenv for managing environment variables. This is required to interact with the TrueFoundry gateway. ```bash pip install openai python-dotenv ``` -------------------------------- ### Install Aider using pip Source: https://inference-docs.cerebras.ai/integrations/aider Install Aider and its dependencies using pip. This is the standard method for installing Python packages. ```bash pip install aider-chat ``` -------------------------------- ### Install Unstructured Dependencies Source: https://inference-docs.cerebras.ai/integrations/unstructured Install specific dependencies for PDF support, local inference, or all features. Use this when encountering installation errors. ```bash # For PDF support pip install "unstructured[pdf]" ``` ```bash # For image processing with OCR pip install "unstructured[local-inference]" ``` ```bash # For all features pip install "unstructured[all-docs]" ``` -------------------------------- ### Install Dependencies Source: https://inference-docs.cerebras.ai/cookbook/agents/exa-grounded-research Install the necessary Python or Node.js packages for Exa and OpenAI integration. Ensure you have Python 3.10+ or Node.js 18+. ```bash pip install "exa-py>=2.0" openai python-dotenv ``` ```bash npm install exa-js openai dotenv ``` -------------------------------- ### Install LiteLLM Source: https://inference-docs.cerebras.ai/integrations/litellm Install the LiteLLM package using pip. This command also installs necessary dependencies like the OpenAI SDK. ```bash pip install litellm ``` -------------------------------- ### Configure Environment Variables Source: https://inference-docs.cerebras.ai/integrations/foundry Set up a .env file to securely store your TrueFoundry gateway API key and base URL. Ensure this file is added to your .gitignore to prevent accidental commits. ```bash TRUEFOUNDRY_API_KEY=your-truefoundry-gateway-key-here TRUEFOUNDRY_BASE_URL=https://gateway.truefoundry.ai ``` -------------------------------- ### Start Agent Session and Generate Initial Message Source: https://inference-docs.cerebras.ai/cookbook/agents/livekit This snippet shows how to start the AgentSession with a configured assistant and chat context, and then generate the first reply from the assistant. This is the entry point for the agent's interaction with the user. ```python await session.start( agent=Assistant(chat_ctx=chat_ctx), room=ctx.room) # Initial prompt from assistant assistant_msg = await session.generate_reply( instructions="Greet the user and start the phone screening process by asking a single question and waiting for the user's response." ) chat_ctx.add_message(role="assistant", content=assistant_msg) ``` -------------------------------- ### Install Pydantic AI and OpenAI Source: https://inference-docs.cerebras.ai/integrations/pydantic-ai Install Pydantic AI and its core dependencies using pip. For development, optional dependencies can be installed with extras. ```bash pip install pydantic-ai openai ``` ```bash pip install 'pydantic-ai[logfire]' ```