Examples
All examples live in examples/.
Setup
# Copy and fill in your API keys
cp .env.example .env
# Run any example
cargo run --example <name>OpenAI
examples/openai.rs — Chat · Streaming · Responses API · Embeddings
cargo run --example openaiCovers five scenarios in one shot:
- Basic chat (
gpt-4o) - Streaming (
with_stream(true)) with real-time token output - Responses API (
invoke_responses) - Responses streaming (
invoke_responses_stream) - Embeddings (
text-embedding-3-small) — returns vector size
OPENAI_API_KEY=sk-...
OPENAI_BASE_URL=https://api.openai.com/v1 # optional overrideAnthropic Claude
examples/anthropic.rs — System messages · Streaming
cargo run --example anthropic- Chat with a
systemmessage (persona: speaks like a pirate) - Streaming response for a long-form question
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_BASE_URL=https://api.anthropic.com # optionalGoogle Gemini
examples/google.rs — Chat · Streaming · Native Thinking
cargo run --example google- Basic chat with Gemini 1.5 Flash
- Streaming chat
- Reasoning / thinking mode (
with_enable_thinking(true)) — exposes separatereasoning_content
examples/google_tools_thinking.rs — Tools + Thinking combined
cargo run --example google_tools_thinkingFull 3-step flow: tool call request → mock tool execution → tool result → final answer, all with enable_thinking active. Uses Gemini 3 Flash Preview / 2.0.
GOOGLE_API_KEY=...
GOOGLE_REGION=global # or cn
GOOGLE_MODEL=gemini-3-flash-previewexamples/list_google_models.rs — List available models
cargo run --example list_google_modelsAliyun DashScope (Qwen)
examples/aliyun.rs — Chat · Streaming · Reasoning
cargo run --example aliyun- Basic chat (
qwen-max) - Streaming chat
- Reasoning / thinking mode (
qwen-plus+with_enable_thinking(true))
ALIYUN_API_KEY=sk-...
ALIYUN_BASE_URL=https://dashscope.aliyuncs.com # optionalZhipu GLM
examples/zhipu.rs — Multi-region · Chat · Streaming
cargo run --example zhipuSupports domestic (cn / bigmodel.cn) and global (global / z.ai) endpoints via ZHIPU_REGION. Optional proxy via ZHIPU_PROXY.
ZHIPU_API_KEY=...
ZHIPU_REGION=cn # or global
ZHIPU_MODEL=glm-4.5-flash
ZHIPU_PROXY=http://127.0.0.1:7890 # optionalexamples/zhipu_tools.rs — Tool Calling (GLM-5, Global)
cargo run --example zhipu_toolsFull 2-step tool call flow with reasoning output before the tool call decision.
examples/zhipu_thinking.rs — Reasoning / Thinking (GLM-5)
cargo run --example zhipu_thinkingUses with_enable_thinking(true) for step-by-step maths reasoning; displays reasoning_content separately from the final answer.
examples/zhipu_vision.rs — Image Understanding (GLM-4V)
cargo run --example zhipu_visionSends a URL image + text question using MessageBlock::image_url(...). Works with glm-4v and glm-5.
Moonshot (Kimi)
examples/moonshot.rs — Multi-region · Chat · Streaming
cargo run --example moonshotSelects endpoint via MOONSHOT_REGION (cn → api.moonshot.cn, global → api.moonshot.ai).
MOONSHOT_API_KEY=sk-...
MOONSHOT_REGION=cn
MOONSHOT_MODEL=kimi-k2.5examples/moonshot_tools.rs — Tool Calling
cargo run --example moonshot_tools2-step weather tool flow: request tool → parse typed args → return result → final answer.
examples/moonshot_thinking.rs — Reasoning / Thinking
cargo run --example moonshot_thinkingLogic puzzle solved with with_enable_thinking(true); reasoning_any() extracts the chain-of-thought across multiple field spellings (reasoning_content, reasoning, thought, thinking).
DeepSeek
examples/deepseek.rs — Basic Chat
cargo run --example deepseekMinimal example using LlmClient::openai(key, base_url) pointed at api.deepseek.com. DeepSeek uses the OpenAI wire format.
DEEPSEEK_API_KEY=sk-...
DEEPSEEK_BASE_URL=https://api.deepseek.com # optionalMinimax
examples/minimax.rs — Multi-region · Chat · Streaming
cargo run --example minimaxUses openai_compatible builder, selects global endpoint by default. Minimax M2.5 via OpenAI-compatible API.
MINIMAX_API_KEY=...
MINIMAX_REGION=global
MINIMAX_MODEL=MiniMax-M2.5Tencent Hunyuan
examples/tencent.rs — Chat · Streaming (TC3-HMAC-SHA256)
cargo run --example tencent --features tencentRequires the tencent Cargo feature. Native Tencent Cloud API v3 signing (SecretId + SecretKey).
TENCENT_SECRET_ID=AKID...
TENCENT_SECRET_KEY=...
TENCENT_BASE_URL=hunyuan.tencentcloudapi.comOllama (Local Models)
examples/ollama.rs — Model listing · Chat · Streaming
cargo run --example ollamaNo API key required. Connects to http://localhost:11434 by default.
- List locally pulled models
- Chat with
llama3 - Streaming chat
Make sure Ollama is running and the model is pulled:
ollama pull llama3Cross-Provider Examples
examples/tool_calling.rs — Full 2-step Tool Call (OpenAI)
cargo run --example tool_callingThe reference tool-calling example. Defines a get_current_weather function, sends it via OpenAI gpt-4o-mini, executes the mock tool, and returns the result for a final answer.
examples/multi_modal.rs — Image Analysis + Embeddings (OpenAI)
cargo run --example multi_modalCombines multi-modal streaming (image URL → MessageBlock::image_url(...)) with embeddings in a single run.
examples/check_reasoning_formats.rs — Reasoning Field Inspection
cargo run --example check_reasoning_formatsInspects all reasoning-related field variants (reasoning_content, reasoning, thought, thinking) across multiple providers to verify extraction.
examples/real_world_connectivity_test.rs — Batch Connectivity Test
cargo run --example real_world_connectivity_testTests every configured provider in sequence and prints a pass/fail summary. Useful as a smoke test before deployment.
Environment Variables Reference
| Provider | Variable(s) |
|---|---|
| OpenAI | OPENAI_API_KEY, OPENAI_BASE_URL |
| Anthropic | ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL |
GOOGLE_API_KEY, GOOGLE_REGION, GOOGLE_MODEL, GOOGLE_BASE_URL | |
| Aliyun | ALIYUN_API_KEY, ALIYUN_BASE_URL |
| Zhipu | ZHIPU_API_KEY, ZHIPU_REGION, ZHIPU_MODEL, ZHIPU_PROXY |
| Moonshot | MOONSHOT_API_KEY, MOONSHOT_REGION, MOONSHOT_MODEL |
| DeepSeek | DEEPSEEK_API_KEY, DEEPSEEK_BASE_URL |
| Minimax | MINIMAX_API_KEY, MINIMAX_REGION, MINIMAX_MODEL |
| Tencent | TENCENT_SECRET_ID, TENCENT_SECRET_KEY, TENCENT_BASE_URL |
| Ollama | (none — defaults to localhost:11434) |
