Keep your API key secure. Never share it publicly or include it in client-side code (such as browsers or mobile apps). Instead, load it safely from an environment variable or a server-side key management service.
Authorization: Bearer CEREBRAS_API_KEY
curl --location 'https://api.cerebras.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${CEREBRAS_API_KEY}" \
--data '{
"model": "llama3.1-8b",
"messages": [
{"role": "user", "content": "Tell me a fun fact about space."}
]
}'
import os
from cerebras.cloud.sdk import Cerebras
client = Cerebras(
# This is the default and can be omitted
api_key=os.environ.get("CEREBRAS_API_KEY"),
)
export CEREBRAS_API_KEY="your-api-key"
Was this page helpful?