5.9 KiB
| summary | read_when | title | ||
|---|---|---|---|---|
| Use Qianfan's unified API to access many models in OpenClaw |
|
Qianfan |
Qianfan Provider Guide
Qianfan is Baidu's MaaS platform, provides a unified API that routes requests to many models behind a single endpoint and API key. It is OpenAI-compatible, so most OpenAI SDKs work by switching the base URL.
Prerequisites
- A Baidu Cloud account with Qianfan API access
- An API key from the Qianfan console
- OpenClaw installed on your system
Getting Your API Key
- Visit the Qianfan Console
- Create a new application or select an existing one
- Generate an API key (format:
bce-v3/ALTAK-...) - Copy the API key for use with OpenClaw
Installation
Install OpenClaw
# Using npm
npm install -g openclaw
# Using pnpm
pnpm add -g openclaw
# Using bun
bun add -g openclaw
Verify Installation
openclaw --version
Configuration Methods
Method 1: Environment Variable (Recommended)
Set the QIANFAN_API_KEY environment variable:
# Bash/Zsh
export QIANFAN_API_KEY="bce-v3/ALTAK-your-api-key-here"
# Fish
set -gx QIANFAN_API_KEY "bce-v3/ALTAK-your-api-key-here"
# PowerShell
$env:QIANFAN_API_KEY = "bce-v3/ALTAK-your-api-key-here"
Add to your shell profile (~/.bashrc, ~/.zshrc, etc.) for persistence:
echo 'export QIANFAN_API_KEY="bce-v3/ALTAK-your-api-key-here"' >> ~/.bashrc
source ~/.bashrc
Method 2: Interactive Onboarding
Run the onboarding wizard:
openclaw onboard --auth-choice qianfan-api-key
Follow the prompts to enter your API key.
Method 3: Configuration File
Configure manually via openclaw.json:
{
"models": {
"providers": {
"qianfan": {
"baseUrl": "https://qianfan.baidubce.com/v2",
"api": "openai-completions",
"apiKey": "bce-v3/ALTAK-your-api-key-here",
"models": [
{
"id": "deepseek-v3.2",
"name": "DeepSeek-V3.2",
"reasoning": true,
"input": ["text"],
"contextWindow": 98304,
"maxTokens": 32768
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "qianfan/deepseek-v3.2"
}
}
}
}
Usage
Start a Chat Session
# Using default QIANFAN model
openclaw chat
# Explicitly specify QIANFAN model
openclaw chat --model qianfan/deepseek-v3.2
Send a Single Message
openclaw message send "Hello, qianfan!"
Use in Agent Mode
openclaw agent --model qianfan/deepseek-v3.2
Check Configuration Status
# View current configuration
openclaw config get
# Check provider status
openclaw channels status --probe
Model Details
| Property | Value |
|---|---|
| Provider | qianfan |
| Model ID | deepseek-v3.2 |
| Model Reference | qianfan/deepseek-v3.2 |
| Context Window | 98,304 tokens |
| Max Output Tokens | 32,768 tokens |
| Reasoning | Yes |
| Input Types | Text |
Available Models
The default model is deepseek-v3.2. You can configure additional models in your config file:
{
"models": {
"providers": {
"qianfan": {
"models": [
{
"id": "deepseek-v3",
"name": "DeepSeek-V3",
"reasoning": false,
"input": ["text"],
"contextWindow": 131072,
"maxTokens": 16384
},
{
"id": "ernie-x1.1",
"name": "ERNIE-X1.1",
"reasoning": true,
"input": ["text"],
"contextWindow": 65536,
"maxTokens": 65536
}
]
}
}
}
}
Troubleshooting
API Key Not Found
If you see "No API key found for provider qianfan":
-
Verify the environment variable is set:
echo $QIANFAN_API_KEY -
Re-run onboarding:
openclaw onboard --auth-choice qianfan-api-key -
Check auth profiles:
cat ~/.openclaw/auth-profiles.json
Authentication Errors
If you receive authentication errors:
- Verify your API key format starts with
bce-v3/ALTAK- - Check that your Qianfan application has the necessary permissions
- Ensure your API key hasn't expired
Connection Issues
If you can't connect to the Qianfan API:
-
Check your network connection
-
Verify the API endpoint is accessible:
curl -I https://qianfan.baidubce.com/v2 -
Check if you're behind a proxy and configure accordingly
Model Not Found
If the model isn't recognized:
- Ensure you're using the correct model reference format:
qianfan/<model-id> - Check available models in your config
- Verify the model ID matches what's available in Qianfan
API Reference
Endpoint
https://qianfan.baidubce.com/v2
Authentication
The API uses bearer token authentication with your Qianfan API key.
Request Format
OpenClaw uses the OpenAI-compatible API format (openai-completions), which Qianfan supports.
Best Practices
- Secure your API key: Never commit API keys to version control
- Use environment variables: Prefer
QIANFAN_API_KEYover config file storage - Monitor usage: Track your Qianfan API usage in the console
- Handle rate limits: Implement appropriate retry logic for production use
- Test locally first: Verify your configuration before deploying