Skip to content

spawn 子 agent 报 401: OpenRouter API key 未传递给 litellm #281

Description

@arelchan

Bug 描述

使用 spawn 创建子 agent 时,子 agent 调用 litellm → OpenRouter 时报 401 User not found,无法正常执行任务。

根因分析

  1. Raven 主进程从 config.jsonproviders.openrouter.apiKey 读取 API key,主会话正常
  2. spawn 出的子 agent 通过 litellm 调用 LLM
  3. litellm环境变量 OPENROUTER_API_KEY 读取 API key
  4. 当前环境没有设置 OPENROUTER_API_KEY 环境变量
  5. litellm 带着空 key 发请求 → OpenRouter 返回 401 User not found

复现步骤

raven config 中 provider 设置为 openrouter
执行任意 spawn 操作
→ 子 agent 立即报错: 401 User not found

日志

~/.raven/workspace/sessions/sub/2064bdc3.jsonl:

{"role": "assistant", "content": "Error calling LLM: litellm.AuthenticationError: AuthenticationError: OpenrouterException - {\"error\":{\"message\":\"User not found.\",\"code\":401}}"}

建议修复

spawn 子进程时,应该将 providers.<provider>.apiKey 注入为对应 provider 的环境变量:

  • OpenRouter → OPENROUTER_API_KEY
  • Anthropic → ANTHROPIC_API_KEY
  • OpenAI → OPENAI_API_KEY

临时 workaround

export OPENROUTER_API_KEY=$(raven config show | python3 -c "import json,sys; print(json.load(sys.stdin)['providers']['openrouter']['apiKey'])")

环境

  • Raven v0.1.10 / macOS arm64 / Python 3.12.13
  • Provider: OpenRouter (deepseek-v4-pro)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions