Crush API Key 配置

Crush API Key 怎么填:crushrc 配置

把下面这段贴进 crushrc,换上你自己的 API Key,Crush 就能用 Claude 等模型了,按量付费。

~/.config/crush/crushrccrushrc
config
# ~/.config/crush/crushrc
provider add aicodewith --type openai-compat \
  --base-url "https://api.aicodewith.ai/v1" \
  --api-key "sk-***"
model add aicodewith/claude-haiku-4-5-20251001 --name "Claude Haiku 4.5"
model add aicodewith/gpt-5.5 --name "GPT-5.5"
model add aicodewith/deepseek-flash --name "DeepSeek Flash"

配置步骤

一键长期设置 Key

登录后会填入你本人的 Key。复制并在终端执行一次,写入这个工具实测过的配置位置;换终端也还在。

bash
mkdir -p "$(dirname "$HOME/.config/crush/crushrc")"
cat > "$HOME/.config/crush/crushrc" << 'EOF'
# ~/.config/crush/crushrc
provider add aicodewith --type openai-compat \
  --base-url "https://api.aicodewith.ai/v1" \
  --api-key "sk-***"
model add aicodewith/claude-haiku-4-5-20251001 --name "Claude Haiku 4.5"
model add aicodewith/gpt-5.5 --name "GPT-5.5"
model add aicodewith/deepseek-flash --name "DeepSeek Flash"
EOF

没登录时只显示占位符。登录后会自动填你的 Key。 去控制台取 Key

复制成功只表示命令已复制到剪贴板。还要在终端执行,或把 Key 贴进工具设置。 获取 API Key 教程

以下步骤在 Linux(bash)实测。macOS 和 Windows 的写法还没实测,暂不列出。

  1. 还没装 Crush?先安装(装过可跳过)

    运行 npm i -g @charmland/crush,再运行 crush --version,打印出版本号就装好了。

    安装 Crush:npm i -g @charmland/crush。装完后 crush --version 会画出它的像素标志,并打印 crush version v0.98.1
  2. 把配置贴进 crushrc,换上你的 API Key

    打开 ~/.config/crush/crushrc,贴入页首那段配置,把 sk-*** 换成你的 API Key(获取 API Key)。--api-key 后面要直接写 Key,不要写 "$AICODEWITH_API_KEY",这样新开终端也不会丢。

    在 ~/.config/crush/crushrc 里把 --api-key 写成你的 Key(图中已打码为 sk-***)
  3. 新开终端,测试 Crush

    新开一个终端,运行 crush run --quiet -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK",看到 OK 就说明 Crush 能用你的 API Key 了。

    验证:关掉终端、新开一个,运行 crush run --quiet -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK",回复 OK 即配置好
  4. 没看到 OK?对着报错找

    把终端里的报错和下面的常见报错对一下,每条都写了原因和改法。

  5. Crush 换模型:-m 后面换名字

    运行时 -m 后面写 aicodewith/ 加 crushrc 里 model add 过的模型名,例如 aicodewith/deepseek-flash。Model ID 见模型与价格。

常见报错

没设 Key:Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.

出现什么

Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.
原因
crushrc 里 --api-key 写的是 "$AICODEWITH_API_KEY",新开的终端里没有这个变量
怎么改
按第 2 步把 --api-key 后面直接写成你的 Key

回到第 2 步:把配置贴进 crushrc →

没设 Key:crushrc 里 --api-key 引用 "$AICODEWITH_API_KEY",新终端里没有这个变量。运行 crush run --quiet -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK",红色 ERROR 标签下的原始报错:Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.

Key 填错:Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.

出现什么

Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.
原因
--api-key 里的 Key 填错了,报错和没设 Key 一样
怎么改
从控制台重新复制 Key,替换 --api-key 引号里的内容

回到第 2 步:把配置贴进 crushrc →

Key 填错:grep -n sk-wrong ~/.config/crush/crushrc 显示第 3 行是 --api-key "sk-wrong";运行 crush run --quiet -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK",红色 ERROR 标签下的原始报错:Agent processing failed: failed to start agent processing stream: unauthorized: {"error":"请在请求中提供有效的 API Key。"}.(和没设 Key 时相同)

403 Forbidden

出现什么

403 Forbidden(提示文字因网络环境而异,如 Request not allowed 或 Country, region, or territory not supported)
原因
命令里没写 -m aicodewith/<模型>,Crush 会去请求默认的 Anthropic 接口(api.anthropic.com)
怎么改
加上 -m aicodewith/deepseek-flash(或配置里的其他模型)即可

回到第 3 步:新开终端,测试 Crush →

常见报错:漏掉 -m aicodewith/<模型> 时,Crush 会去请求默认的 Anthropic 接口(api.anthropic.com),返回 403 Forbidden(提示文字因网络环境而异,如 Request not allowed 或 Country, region, or territory not supported)。加上 -m aicodewith/deepseek-flash(或配置里的其他模型)即可

常见问题

Crush 怎么用自己的 API Key?

在 ~/.config/crush/crushrc 里用 provider add 添加 openai-compat 提供商,--base-url 填 https://api.aicodewith.ai/v1,--api-key 直接写你的 Key。新开终端也能用。

provider 类型选 openai 还是 openai-compat?

选 openai-compat。openai 留给直连 OpenAI 的情况。

Crush 的 crushrc 放在哪里?

全局是 ~/.config/crush/crushrc;项目里的 .crushrc 或 crushrc 优先。

Crush 提示 unauthorized 怎么办?

crushrc 里的 --api-key 是空的或填错了,改法见上面的常见报错。

参考来源

相关链接