Add baidu qianfan model provider
This commit is contained in:
291
docs/providers/qianfan.md
Normal file
291
docs/providers/qianfan.md
Normal file
@@ -0,0 +1,291 @@
|
||||
---
|
||||
summary: "Use DeepSeek-V3.2 in OpenClaw"
|
||||
read_when:
|
||||
- You want a single API key for many LLMs
|
||||
- You need Baidu Qianfan setup guidance
|
||||
title: "Qianfan"
|
||||
---
|
||||
|
||||
# Baidu 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
|
||||
|
||||
1. A Baidu Cloud account with Qianfan API access
|
||||
2. An API key from the Qianfan console
|
||||
3. OpenClaw installed on your system
|
||||
|
||||
## Getting Your API Key
|
||||
|
||||
1. Visit the [Qianfan Console](https://console.bce.baidu.com/qianfan/ais/console/apiKey)
|
||||
2. Create a new application or select an existing one
|
||||
3. Generate an API key (format: `bce-v3/ALTAK-...`)
|
||||
4. Copy the API key for use with OpenClaw
|
||||
|
||||
## Installation
|
||||
|
||||
### Install OpenClaw
|
||||
|
||||
```bash
|
||||
# Using npm
|
||||
npm install -g openclaw
|
||||
|
||||
# Using pnpm
|
||||
pnpm add -g openclaw
|
||||
|
||||
# Using bun
|
||||
bun add -g openclaw
|
||||
```
|
||||
|
||||
### Verify Installation
|
||||
|
||||
```bash
|
||||
openclaw --version
|
||||
```
|
||||
|
||||
## Configuration Methods
|
||||
|
||||
### Method 1: Environment Variable (Recommended)
|
||||
|
||||
Set the `QIANFAN_API_KEY` environment variable:
|
||||
|
||||
```bash
|
||||
# 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:
|
||||
|
||||
```bash
|
||||
echo 'export QIANFAN_API_KEY="bce-v3/ALTAK-your-api-key-here"' >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
### Method 2: Interactive Onboarding
|
||||
|
||||
Run the onboarding wizard:
|
||||
|
||||
```bash
|
||||
openclaw onboard --auth-choice qianfan-api-key
|
||||
```
|
||||
|
||||
Follow the prompts to enter your API key.
|
||||
|
||||
### Method 3: Non-Interactive Setup
|
||||
|
||||
For CI/CD or scripted setups:
|
||||
|
||||
```bash
|
||||
openclaw onboard \
|
||||
--non-interactive \
|
||||
--accept-risk \
|
||||
--auth-choice token \
|
||||
--token-provider qianfan \
|
||||
--token "bce-v3/ALTAK-your-api-key-here"
|
||||
```
|
||||
|
||||
### Method 4: Configuration File
|
||||
|
||||
Configure manually via `openclaw.json`:
|
||||
|
||||
```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
|
||||
|
||||
```bash
|
||||
# Using default QIANFAN model
|
||||
openclaw chat
|
||||
|
||||
# Explicitly specify QIANFAN model
|
||||
openclaw chat --model qianfan/deepseek-v3.2
|
||||
```
|
||||
|
||||
### Send a Single Message
|
||||
|
||||
```bash
|
||||
openclaw message send "Hello, qianfan!"
|
||||
```
|
||||
|
||||
### Use in Agent Mode
|
||||
|
||||
```bash
|
||||
openclaw agent --model qianfan/deepseek-v3.2
|
||||
```
|
||||
|
||||
### Check Configuration Status
|
||||
|
||||
```bash
|
||||
# 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:
|
||||
|
||||
```json
|
||||
{
|
||||
"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":
|
||||
|
||||
1. Verify the environment variable is set:
|
||||
|
||||
```bash
|
||||
echo $QIANFAN_API_KEY
|
||||
```
|
||||
|
||||
2. Re-run onboarding:
|
||||
|
||||
```bash
|
||||
openclaw onboard --auth-choice qianfan-api-key
|
||||
```
|
||||
|
||||
3. Check auth profiles:
|
||||
```bash
|
||||
cat ~/.openclaw/auth-profiles.json
|
||||
```
|
||||
|
||||
### Authentication Errors
|
||||
|
||||
If you receive authentication errors:
|
||||
|
||||
1. Verify your API key format starts with `bce-v3/ALTAK-`
|
||||
2. Check that your Qianfan application has the necessary permissions
|
||||
3. Ensure your API key hasn't expired
|
||||
|
||||
### Connection Issues
|
||||
|
||||
If you can't connect to the Qianfan API:
|
||||
|
||||
1. Check your network connection
|
||||
2. Verify the API endpoint is accessible:
|
||||
|
||||
```bash
|
||||
curl -I https://qianfan.baidubce.com/v2
|
||||
```
|
||||
|
||||
3. Check if you're behind a proxy and configure accordingly
|
||||
|
||||
### Model Not Found
|
||||
|
||||
If the model isn't recognized:
|
||||
|
||||
1. Ensure you're using the correct model reference format: `qianfan/<model-id>`
|
||||
2. Check available models in your config
|
||||
3. 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
|
||||
|
||||
1. **Secure your API key**: Never commit API keys to version control
|
||||
2. **Use environment variables**: Prefer `QIANFAN_API_KEY` over config file storage
|
||||
3. **Monitor usage**: Track your Qianfan API usage in the console
|
||||
4. **Handle rate limits**: Implement appropriate retry logic for production use
|
||||
5. **Test locally first**: Verify your configuration before deploying
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [OpenClaw Configuration](/configuration)
|
||||
- [Model Providers](/models/providers)
|
||||
- [Agent Setup](/agents)
|
||||
- [Qianfan API Documentation](https://cloud.baidu.com/doc/qianfan-api/s/3m7of64lb)
|
||||
@@ -300,6 +300,7 @@ export function resolveEnvApiKey(provider: string): EnvApiKeyResult | null {
|
||||
venice: "VENICE_API_KEY",
|
||||
mistral: "MISTRAL_API_KEY",
|
||||
opencode: "OPENCODE_API_KEY",
|
||||
qianfan: "QIANFAN_API_KEY",
|
||||
};
|
||||
const envVar = envMap[normalized];
|
||||
if (!envVar) {
|
||||
|
||||
@@ -76,6 +76,17 @@ const OLLAMA_DEFAULT_COST = {
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const QIANFAN_BASE_URL = "https://qianfan.baidubce.com/v2";
|
||||
export const QIANFAN_DEFAULT_MODEL_ID = "deepseek-v3.2";
|
||||
const QIANFAN_DEFAULT_CONTEXT_WINDOW = 98304;
|
||||
const QIANFAN_DEFAULT_MAX_TOKENS = 32768;
|
||||
const QIANFAN_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
interface OllamaModel {
|
||||
name: string;
|
||||
modified_at: string;
|
||||
@@ -394,6 +405,24 @@ async function buildOllamaProvider(): Promise<ProviderConfig> {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildQianfanProvider(): ProviderConfig {
|
||||
return {
|
||||
baseUrl: QIANFAN_BASE_URL,
|
||||
api: "openai-completions",
|
||||
models: [
|
||||
{
|
||||
id: QIANFAN_DEFAULT_MODEL_ID,
|
||||
name: "DEEPSEEK V3.2",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: QIANFAN_DEFAULT_COST,
|
||||
contextWindow: QIANFAN_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: QIANFAN_DEFAULT_MAX_TOKENS,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export async function resolveImplicitProviders(params: {
|
||||
agentDir: string;
|
||||
}): Promise<ModelsConfig["providers"]> {
|
||||
@@ -461,6 +490,13 @@ export async function resolveImplicitProviders(params: {
|
||||
providers.ollama = { ...(await buildOllamaProvider()), apiKey: ollamaKey };
|
||||
}
|
||||
|
||||
const qianfanKey =
|
||||
resolveEnvApiKeyVarName("qianfan") ??
|
||||
resolveApiKeyFromProfiles({ provider: "qianfan", store: authStore });
|
||||
if (qianfanKey) {
|
||||
providers.qianfan = { ...buildQianfanProvider(), apiKey: qianfanKey };
|
||||
}
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export function registerOnboardCommand(program: Command) {
|
||||
.option("--mode <mode>", "Wizard mode: local|remote")
|
||||
.option(
|
||||
"--auth-choice <choice>",
|
||||
"Auth: setup-token|token|chutes|openai-codex|openai-api-key|openrouter-api-key|ai-gateway-api-key|moonshot-api-key|kimi-code-api-key|synthetic-api-key|venice-api-key|gemini-api-key|zai-api-key|xiaomi-api-key|apiKey|minimax-api|minimax-api-lightning|opencode-zen|skip",
|
||||
"Auth: setup-token|token|chutes|openai-codex|openai-api-key|openrouter-api-key|ai-gateway-api-key|moonshot-api-key|kimi-code-api-key|synthetic-api-key|venice-api-key|gemini-api-key|zai-api-key|xiaomi-api-key|qianfan-api-key|apiKey|minimax-api|minimax-api-lightning|opencode-zen|skip",
|
||||
)
|
||||
.option(
|
||||
"--token-provider <id>",
|
||||
@@ -79,6 +79,7 @@ export function registerOnboardCommand(program: Command) {
|
||||
.option("--gemini-api-key <key>", "Gemini API key")
|
||||
.option("--zai-api-key <key>", "Z.AI API key")
|
||||
.option("--xiaomi-api-key <key>", "Xiaomi API key")
|
||||
.option("--qianfan-api-key <key>", "QIANFAN API key")
|
||||
.option("--minimax-api-key <key>", "MiniMax API key")
|
||||
.option("--synthetic-api-key <key>", "Synthetic API key")
|
||||
.option("--venice-api-key <key>", "Venice API key")
|
||||
@@ -130,6 +131,7 @@ export function registerOnboardCommand(program: Command) {
|
||||
geminiApiKey: opts.geminiApiKey as string | undefined,
|
||||
zaiApiKey: opts.zaiApiKey as string | undefined,
|
||||
xiaomiApiKey: opts.xiaomiApiKey as string | undefined,
|
||||
qianfanApiKey: opts.qianfanApiKey as string | undefined,
|
||||
minimaxApiKey: opts.minimaxApiKey as string | undefined,
|
||||
syntheticApiKey: opts.syntheticApiKey as string | undefined,
|
||||
veniceApiKey: opts.veniceApiKey as string | undefined,
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
} from "./google-gemini-model-default.js";
|
||||
import {
|
||||
applyAuthProfileConfig,
|
||||
applyQianfanConfig,
|
||||
applyQianfanProviderConfig,
|
||||
applyKimiCodeConfig,
|
||||
applyKimiCodeProviderConfig,
|
||||
applyMoonshotConfig,
|
||||
@@ -30,6 +32,7 @@ import {
|
||||
applyXiaomiConfig,
|
||||
applyXiaomiProviderConfig,
|
||||
applyZaiConfig,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
@@ -37,6 +40,7 @@ import {
|
||||
VENICE_DEFAULT_MODEL_REF,
|
||||
VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
XIAOMI_DEFAULT_MODEL_REF,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMoonshotApiKey,
|
||||
@@ -96,6 +100,8 @@ export async function applyAuthChoiceApiProviders(
|
||||
authChoice = "venice-api-key";
|
||||
} else if (params.opts.tokenProvider === "opencode") {
|
||||
authChoice = "opencode-zen";
|
||||
} else if (params.opts.tokenProvider === "qianfan") {
|
||||
authChoice = "qianfan-api-key";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,5 +649,61 @@ export async function applyAuthChoiceApiProviders(
|
||||
return { config: nextConfig, agentModelOverride };
|
||||
}
|
||||
|
||||
if (authChoice === "qianfan-api-key") {
|
||||
let hasCredential = false;
|
||||
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "qianfan") {
|
||||
setQianfanApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
|
||||
if (!hasCredential) {
|
||||
await params.prompter.note(
|
||||
[
|
||||
"Get your API key at: https://console.bce.baidu.com/qianfan/ais/console/apiKey",
|
||||
"API key format: bce-v3/ALTAK-...",
|
||||
].join("\n"),
|
||||
"QIANFAN",
|
||||
);
|
||||
}
|
||||
const envKey = resolveEnvApiKey("qianfan-api-key");
|
||||
if (envKey) {
|
||||
const useExisting = await params.prompter.confirm({
|
||||
message: `Use existing QIANFAN_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
|
||||
initialValue: true,
|
||||
});
|
||||
if (useExisting) {
|
||||
setQianfanApiKey(envKey.apiKey, params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
}
|
||||
if (!hasCredential) {
|
||||
const key = await params.prompter.text({
|
||||
message: "Enter QIANFAN API key",
|
||||
validate: validateApiKeyInput,
|
||||
});
|
||||
setQianfanApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "qianfan:default",
|
||||
provider: "qianfan",
|
||||
mode: "api_key",
|
||||
});
|
||||
{
|
||||
const applied = await applyDefaultModelChoice({
|
||||
config: nextConfig,
|
||||
setDefaultModel: params.setDefaultModel,
|
||||
defaultModel: QIANFAN_DEFAULT_MODEL_REF,
|
||||
applyDefaultConfig: applyQianfanConfig,
|
||||
applyProviderConfig: applyQianfanProviderConfig,
|
||||
noteDefault: QIANFAN_DEFAULT_MODEL_REF,
|
||||
noteAgentModel,
|
||||
prompter: params.prompter,
|
||||
});
|
||||
nextConfig = applied.config;
|
||||
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
|
||||
}
|
||||
return { config: nextConfig, agentModelOverride };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
|
||||
"opencode-zen": "opencode",
|
||||
"qwen-portal": "qwen-portal",
|
||||
"minimax-portal": "minimax-portal",
|
||||
"qianfan-api-key": "qianfan",
|
||||
};
|
||||
|
||||
export function resolvePreferredProviderForAuthChoice(choice: AuthChoice): string | undefined {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { buildXiaomiProvider, XIAOMI_DEFAULT_MODEL_ID } from "../agents/models-config.providers.js";
|
||||
import type { ModelApi } from "../config/types.models.js";
|
||||
import {
|
||||
buildQianfanProvider,
|
||||
buildXiaomiProvider,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
XIAOMI_DEFAULT_MODEL_ID,
|
||||
} from "../agents/models-config.providers.js";
|
||||
import {
|
||||
buildSyntheticModelDefinition,
|
||||
SYNTHETIC_BASE_URL,
|
||||
@@ -20,6 +26,8 @@ import {
|
||||
} from "./onboard-auth.credentials.js";
|
||||
import {
|
||||
buildMoonshotModelDefinition,
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
@@ -505,3 +513,80 @@ export function applyAuthProfileConfig(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function applyQianfanProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
models[QIANFAN_DEFAULT_MODEL_REF] = {
|
||||
...models[QIANFAN_DEFAULT_MODEL_REF],
|
||||
alias: models[QIANFAN_DEFAULT_MODEL_REF]?.alias ?? "QIANFAN",
|
||||
};
|
||||
|
||||
const providers = { ...cfg.models?.providers };
|
||||
const existingProvider = providers.qianfan;
|
||||
const defaultProvider = buildQianfanProvider();
|
||||
const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
|
||||
const defaultModels = defaultProvider.models ?? [];
|
||||
const hasDefaultModel = existingModels.some((model) => model.id === QIANFAN_DEFAULT_MODEL_ID);
|
||||
const mergedModels =
|
||||
existingModels.length > 0
|
||||
? hasDefaultModel
|
||||
? existingModels
|
||||
: [...existingModels, ...defaultModels]
|
||||
: defaultModels;
|
||||
const {
|
||||
apiKey: existingApiKey,
|
||||
baseUrl: existingBaseUrl,
|
||||
api: existingApi,
|
||||
...existingProviderRest
|
||||
} = (existingProvider ?? {}) as Record<string, unknown> as {
|
||||
apiKey?: string;
|
||||
baseUrl?: string;
|
||||
api?: ModelApi;
|
||||
};
|
||||
const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : undefined;
|
||||
const normalizedApiKey = resolvedApiKey?.trim();
|
||||
providers.qianfan = {
|
||||
...existingProviderRest,
|
||||
baseUrl: existingBaseUrl ?? QIANFAN_BASE_URL,
|
||||
api: existingApi ?? "openai-completions",
|
||||
...(normalizedApiKey ? { apiKey: normalizedApiKey } : {}),
|
||||
models: mergedModels.length > 0 ? mergedModels : defaultProvider.models,
|
||||
};
|
||||
|
||||
return {
|
||||
...cfg,
|
||||
agents: {
|
||||
...cfg.agents,
|
||||
defaults: {
|
||||
...cfg.agents?.defaults,
|
||||
models,
|
||||
},
|
||||
},
|
||||
models: {
|
||||
mode: cfg.models?.mode ?? "merge",
|
||||
providers,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function applyQianfanConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const next = applyQianfanProviderConfig(cfg);
|
||||
const existingModel = next.agents?.defaults?.model;
|
||||
return {
|
||||
...next,
|
||||
agents: {
|
||||
...next.agents,
|
||||
defaults: {
|
||||
...next.agents?.defaults,
|
||||
model: {
|
||||
...(existingModel && "fallbacks" in (existingModel as Record<string, unknown>)
|
||||
? {
|
||||
fallbacks: (existingModel as { fallbacks?: string[] }).fallbacks,
|
||||
}
|
||||
: undefined),
|
||||
primary: QIANFAN_DEFAULT_MODEL_REF,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,3 +178,15 @@ export async function setOpencodeZenApiKey(key: string, agentDir?: string) {
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
});
|
||||
}
|
||||
|
||||
export function setQianfanApiKey(key: string, agentDir?: string) {
|
||||
upsertAuthProfile({
|
||||
profileId: "qianfan:default",
|
||||
credential: {
|
||||
type: "api_key",
|
||||
provider: "qianfan",
|
||||
key,
|
||||
},
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,6 +15,18 @@ export const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const KIMI_CODING_MODEL_ID = "k2p5";
|
||||
export const KIMI_CODING_MODEL_REF = `kimi-coding/${KIMI_CODING_MODEL_ID}`;
|
||||
|
||||
export const QIANFAN_BASE_URL = "https://qianfan.baidubce.com/v2";
|
||||
export const QIANFAN_DEFAULT_MODEL_ID = "deepseek-v3.2";
|
||||
export const QIANFAN_DEFAULT_MODEL_REF = `ernie/${QIANFAN_DEFAULT_MODEL_ID}`;
|
||||
export const QIANFAN_DEFAULT_CONTEXT_WINDOW = 98304;
|
||||
export const QIANFAN_DEFAULT_MAX_TOKENS = 32768;
|
||||
export const QIANFAN_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
// Pricing: MiniMax doesn't publish public rates. Override in models.json for accurate costs.
|
||||
export const MINIMAX_API_COST = {
|
||||
input: 15,
|
||||
@@ -91,3 +103,15 @@ export function buildMoonshotModelDefinition(): ModelDefinitionConfig {
|
||||
maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildQianfanModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: QIANFAN_DEFAULT_MODEL_ID,
|
||||
name: "ERNIE 5.0",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: QIANFAN_DEFAULT_COST,
|
||||
contextWindow: QIANFAN_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: QIANFAN_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ export {
|
||||
export { VENICE_DEFAULT_MODEL_ID, VENICE_DEFAULT_MODEL_REF } from "../agents/venice-models.js";
|
||||
export {
|
||||
applyAuthProfileConfig,
|
||||
applyQianfanConfig,
|
||||
applyQianfanProviderConfig,
|
||||
applyKimiCodeConfig,
|
||||
applyKimiCodeProviderConfig,
|
||||
applyMoonshotConfig,
|
||||
@@ -37,6 +39,7 @@ export {
|
||||
export {
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
setAnthropicApiKey,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMinimaxApiKey,
|
||||
@@ -54,10 +57,14 @@ export {
|
||||
ZAI_DEFAULT_MODEL_REF,
|
||||
} from "./onboard-auth.credentials.js";
|
||||
export {
|
||||
buildQianfanModelDefinition,
|
||||
buildMinimaxApiModelDefinition,
|
||||
buildMinimaxModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
DEFAULT_MINIMAX_BASE_URL,
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_ID,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MINIMAX_API_BASE_URL,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { buildTokenProfileId, validateAnthropicSetupToken } from "../../auth-tok
|
||||
import { applyGoogleGeminiModelDefault } from "../../google-gemini-model-default.js";
|
||||
import {
|
||||
applyAuthProfileConfig,
|
||||
applyQianfanConfig,
|
||||
applyKimiCodeConfig,
|
||||
applyMinimaxApiConfig,
|
||||
applyMinimaxConfig,
|
||||
@@ -22,6 +23,7 @@ import {
|
||||
applyXiaomiConfig,
|
||||
applyZaiConfig,
|
||||
setAnthropicApiKey,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMinimaxApiKey,
|
||||
@@ -214,6 +216,29 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
return applyXiaomiConfig(nextConfig);
|
||||
}
|
||||
|
||||
if (authChoice === "qianfan-api-key") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
provider: "qianfan",
|
||||
cfg: baseConfig,
|
||||
flagValue: opts.qianfanApiKey,
|
||||
flagName: "--qianfan-api-key",
|
||||
envVar: "QIANFAN_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
setQianfanApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "qianfan:default",
|
||||
provider: "qianfan",
|
||||
mode: "api_key",
|
||||
});
|
||||
return applyQianfanConfig(nextConfig);
|
||||
}
|
||||
|
||||
if (authChoice === "openai-api-key") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
provider: "openai",
|
||||
|
||||
@@ -33,6 +33,7 @@ export type AuthChoice =
|
||||
| "github-copilot"
|
||||
| "copilot-proxy"
|
||||
| "qwen-portal"
|
||||
| "qianfan-api-key"
|
||||
| "skip";
|
||||
export type GatewayAuthChoice = "token" | "password";
|
||||
export type ResetScope = "config" | "config+creds+sessions" | "full";
|
||||
@@ -74,6 +75,7 @@ export type OnboardOptions = {
|
||||
syntheticApiKey?: string;
|
||||
veniceApiKey?: string;
|
||||
opencodeZenApiKey?: string;
|
||||
qianfanApiKey?: string;
|
||||
gatewayPort?: number;
|
||||
gatewayBind?: GatewayBind;
|
||||
gatewayAuth?: GatewayAuthChoice;
|
||||
|
||||
Reference in New Issue
Block a user