| Crates.io | llm-kit-cerebras |
| lib.rs | llm-kit-cerebras |
| version | 0.1.0 |
| created_at | 2026-01-18 20:18:25.5814+00 |
| updated_at | 2026-01-18 20:18:25.5814+00 |
| description | Cerebras provider for the LLM Kit |
| homepage | https://github.com/saribmah/llm-kit |
| repository | https://github.com/saribmah/llm-kit |
| max_upload_size | |
| id | 2053014 |
| size | 106,528 |
Cerebras provider for LLM Kit - High-speed AI model inference powered by Cerebras Wafer-Scale Engines and CS-3 systems.
Note: This provider uses the standardized builder pattern. See the Quick Start section for the recommended usage.
Add this to your Cargo.toml:
[dependencies]
llm-kit-cerebras = "0.1"
llm-kit-core = "0.1"
llm-kit-provider = "0.1"
tokio = { version = "1", features = ["full"] }
use llm_kit_cerebras::CerebrasClient;
use llm_kit_provider::LanguageModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create provider using the client builder
let provider = CerebrasClient::new()
.api_key("your-api-key") // Or use CEREBRAS_API_KEY env var
.build();
// Create a language model
let model = provider.chat_model("llama-3.3-70b");
println!("Model: {}", model.model_id());
println!("Provider: {}", model.provider());
Ok(())
}
use llm_kit_cerebras::{CerebrasProvider, CerebrasProviderSettings};
use llm_kit_provider::LanguageModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create provider with settings
let settings = CerebrasProviderSettings::new("https://api.cerebras.ai/v1")
.with_api_key("your-api-key");
let provider = CerebrasProvider::new(settings);
let model = provider.chat_model("llama-3.3-70b");
println!("Model: {}", model.model_id());
Ok(())
}
Set your Cerebras API key as an environment variable:
export CEREBRAS_API_KEY=your-api-key
export CEREBRAS_BASE_URL=https://api.cerebras.ai/v1 # Optional
use llm_kit_cerebras::CerebrasClient;
let provider = CerebrasClient::new()
.api_key("your-api-key")
.base_url("https://api.cerebras.ai/v1")
.header("Custom-Header", "value")
.name("my-cerebras-provider")
.build();
The CerebrasClient builder supports:
.api_key(key) - Set the API key (or use CEREBRAS_API_KEY env var).base_url(url) - Set custom base URL (default: https://api.cerebras.ai/v1).name(name) - Set provider name (default: cerebras).header(key, value) - Add a single custom header.headers(map) - Add multiple custom headers.build() - Build the providerCerebras offers high-performance language models powered by Wafer-Scale Engines. For the complete list and latest information, see the Cerebras Models Overview.
llama3.1-8b - Llama 3.1 8B parameter modelllama-3.3-70b - Llama 3.3 70B parameter modelgpt-oss-120b - GPT-OSS 120B parameter modelqwen-3-32b - Qwen 3 32B parameter modelqwen-3-235b-a22b-instruct-2507 - Qwen 3 235B instruct modelqwen-3-235b-a22b-thinking-2507 - Qwen 3 235B reasoning model with exposed thought processzai-glm-4.6 - ZAI GLM 4.6 modelYou can use predefined model constants:
use llm_kit_cerebras::chat::models;
let model = provider.chat_model(models::LLAMA_3_3_70B);
let reasoning_model = provider.chat_model(models::QWEN_3_235B_THINKING);
Cerebras supports OpenAI-compatible structured outputs with JSON schema validation:
use llm_kit_core::{GenerateText, prompt::Prompt};
use serde_json::json;
let result = GenerateText::new(model, Prompt::text("Extract user info"))
.response_format(json!({
"type": "json_schema",
"json_schema": {
"name": "user_info",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
},
"required": ["name", "age"]
}
}
}))
.execute()
.await?;
Cerebras offers thinking models (e.g., qwen-3-235b-a22b-thinking-2507) that expose their reasoning process:
use llm_kit_cerebras::chat::models;
use llm_kit_core::{GenerateText, prompt::Prompt, output::Output};
let model = provider.chat_model(models::QWEN_3_235B_THINKING);
let result = GenerateText::new(model, Prompt::text("Solve this logic puzzle..."))
.execute()
.await?;
// Process reasoning and answer separately
for output in &result.content {
match output {
Output::Reasoning { text, .. } => {
println!("💭 Reasoning: {}", text);
}
Output::Text { text, .. } => {
println!("📝 Answer: {}", text);
}
_ => {}
}
}
See the examples/ directory for complete examples:
chat.rs - Basic chat completion using provider traitsstream.rs - Streaming responses using provider traitschat_tool_calling.rs - Tool calling with provider traitsstream_tool_calling.rs - Streaming with tools using provider traitsRun examples with:
export CEREBRAS_API_KEY=your-api-key
cargo run --example chat -p llm-kit-cerebras
cargo run --example stream -p llm-kit-cerebras
For user-facing examples using llm-kit-core, see the root examples/ directory:
cargo run --example cerebras_basic_chat
cargo run --example cerebras_streaming_chat
cargo run --example cerebras_tool_calling
cargo run --example cerebras_reasoning
Licensed under:
Contributions are welcome! Please see the Contributing Guide for more details.