DeRouter
← 返回收益页

开发者接口

账号托管 API

让你的 app 通过 API 把 Claude 账号接入托管。两种方式:交互式浏览器登录,或批量 sessionKey 导入。

所有接口用 Manager Key(sk-mgr-...)鉴权,每把 key 只能操作自己钱包名下的账号。

Authorization: Bearer sk-mgr-...
01

交互式 OAuth

终端用户在浏览器里登录一次 claude.ai,你不需要拿到用户的 cookie 或 sessionKey。

1authorize → 拿 auth_url + session_id(还没账号)
2用户浏览器打开 auth_url 登录,取 code
3exchange(session_id + code)→ 账号落地

1. authorize

生成 claude.ai 授权链接,交给终端用户在浏览器里打开。

curl -X POST "https://api.derouter.network/api/containers/claude-oauth/authorize" \
  -H "Authorization: Bearer sk-mgr-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"region": "sgp"}'

# => { "auth_url": "https://claude.ai/oauth/authorize?...", "session_id": "3f9a2e1b..." }
# KEEP session_id — you pass it back in step 2 (exchange).
# open auth_url in the END USER's browser (not your server's).
# region picks the egress IP; token is minted from that same IP (revoke-safe).

2. exchange

用用户拿到的 Authorization Code 兑换 token,落地为 hosted container。

curl -X POST "https://api.derouter.network/api/containers/claude-oauth/exchange" \
  -H "Authorization: Bearer sk-mgr-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "3f9a2e1b...",
    "code": "xxxxxxxxxxxxxxxx#yyyyyyyyyyyy"
  }'

# => { "status": "running", "account_id": "2eab80c1-...", "email": "user@example.com", "plan": "max" }
02

Cookie 批量上号

已经持有终端用户 sessionKey 时,直接批量导入,无需浏览器交互。

1. 单个上号

curl -X POST "https://api.derouter.network/api/containers/claude-oauth/cookie-auth" \
  -H "Authorization: Bearer sk-mgr-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session_key": "sk-ant-sid01-…",
    "region": "sgp"
  }'

2. 批量上号

curl -X POST "https://api.derouter.network/api/containers/claude-oauth/bulk-cookies" \
  -H "Authorization: Bearer sk-mgr-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session_keys": [
      { "session_key": "sk-ant-sid01-…", "region": "sgp" }
    ],
    "options": { "default_region": "sgp" }
  }'

# <=50 per batch; email dedup is always on.
# result.status is one of: added | skipped | failed | pending.

3. 批量托管 Codex 账号(refresh token)

curl -X POST "https://api.derouter.network/api/containers/codex/bulk-refresh-tokens" \
  -H "Authorization: Bearer sk-mgr-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "refresh_tokens": [
      { "refresh_token": "rt.1.…", "region": "sgp" }
    ],
    "options": { "default_region": "sgp" }
  }'

# The token is tokens.refresh_token from ~/.codex/auth.json (prefix "rt.").
# ⚠ THE EXCHANGE CONSUMES THE TOKEN. OpenAI rotates it and we keep the new one.
⚠ code 是 Authorization Code,不是 sessionKey,两者不可互换;三种上号方式(交互式 OAuth / 单个 cookie / 批量 cookie)共享同一份钱包配额。