Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ed16ad3
feat(proxy): add Anthropic Claude SDK messages endpoint
azkore Feb 26, 2026
0eec346
feat(anthropic): pool Claude SDK clients for SDK transport
azkore Feb 26, 2026
5dfe32c
feat(anthropic): add dual SDK and API message routes
azkore Feb 26, 2026
446d5b1
fix(oauth): ignore synthetic Anthropic seed in login shortcut
azkore Feb 26, 2026
b002435
feat(anthropic): add dashboard credential import and claude labels
azkore Feb 26, 2026
5dfb155
feat(anthropic): require explicit email on credential import
azkore Feb 26, 2026
5f97d47
chore(anthropic): add diagnostics and session-safe SDK pooling
azkore Feb 26, 2026
0f45847
fix(anthropic-api): refresh revoked OAuth token on 403
azkore Feb 26, 2026
29c493e
fix(usage): skip Anthropic accounts in OpenAI usage refresh
azkore Feb 26, 2026
033e76c
chore(anthropic-sdk): disable pooling by default
azkore Feb 26, 2026
0867e92
feat(anthropic): make /claude API-first and move SDK to /claude-sdk
azkore Feb 26, 2026
d96c155
fix(ci): resolve typing issues and use non-secret test tokens
azkore Feb 26, 2026
1dbca36
chore(ci): apply Ruff formatting for Anthropic/OAuth files
azkore Feb 26, 2026
7bc4288
feat(ui): separate Anthropic accounts with badges and row tint
azkore Feb 26, 2026
525cd89
feat(ui): use provider icons and remove internal id disambiguation
azkore Feb 26, 2026
88024d2
fix(ci): unblock lint and frontend coverage gate
azkore Feb 26, 2026
d9e5857
fix(pricing): update Anthropic model rates and aliases
azkore Feb 27, 2026
2c86959
fix(anthropic-usage): align token totals with codex-lb conventions
azkore Feb 27, 2026
d712b5e
Merge remote-tracking branch 'origin/main' into claude
azkore Feb 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@ CODEX_LB_DATABASE_SQLITE_PRE_MIGRATE_BACKUP_MAX_FILES=5
# Upstream ChatGPT base URL (no /codex suffix)
CODEX_LB_UPSTREAM_BASE_URL=https://chatgpt.com/backend-api

# Anthropic SDK runtime
# Optional explicit Claude CLI path when auto-discovery via PATH is not enough
# CODEX_LB_ANTHROPIC_SDK_CLI_PATH=/usr/local/bin/claude
# Optional default session ID for SDK conversation continuity
# CODEX_LB_ANTHROPIC_SDK_DEFAULT_SESSION_ID=codex-lb-default
CODEX_LB_ANTHROPIC_SDK_POOL_ENABLED=false

# Anthropic direct API runtime (/claude/v1/messages)
CODEX_LB_ANTHROPIC_API_BASE_URL=https://api.anthropic.com
CODEX_LB_ANTHROPIC_API_VERSION=2023-06-01
# CODEX_LB_ANTHROPIC_API_BETA=
CODEX_LB_ANTHROPIC_API_TIMEOUT_SECONDS=300
CODEX_LB_ANTHROPIC_API_DETECT_CLI_HEADERS=true
CODEX_LB_ANTHROPIC_API_SYSTEM_PROMPT_INJECTION_MODE=minimal
CODEX_LB_ANTHROPIC_OAUTH_TOKEN_URL=https://console.anthropic.com/v1/oauth/token
CODEX_LB_ANTHROPIC_OAUTH_CLIENT_ID=9d1c250a-e61b-44d9-88ed-5944d1962f5e

# Anthropic usage (5h/7d)
CODEX_LB_ANTHROPIC_USAGE_BASE_URL=https://api.anthropic.com
CODEX_LB_ANTHROPIC_USAGE_BETA=oauth-2025-04-20
CODEX_LB_ANTHROPIC_USAGE_REFRESH_ENABLED=true

# Anthropic auth discovery (Linux-only POC)
CODEX_LB_ANTHROPIC_CREDENTIALS_DISCOVERY_ENABLED=true
# CODEX_LB_ANTHROPIC_CREDENTIALS_FILE=~/.claude/.credentials.json
# CODEX_LB_ANTHROPIC_CREDENTIALS_HELPER_COMMAND=
# Explicit override (if set, used before discovery)
# CODEX_LB_ANTHROPIC_USAGE_BEARER_TOKEN=sk-ant-oat01-...
CODEX_LB_ANTHROPIC_AUTO_DISCOVER_ORG=false
CODEX_LB_ANTHROPIC_CREDENTIALS_CACHE_SECONDS=60
CODEX_LB_ANTHROPIC_DEFAULT_ACCOUNT_ID=anthropic_default
CODEX_LB_ANTHROPIC_DEFAULT_ACCOUNT_EMAIL=anthropic@local
CODEX_LB_ANTHROPIC_DEFAULT_PLAN_TYPE=pro

# Timeouts (seconds)
CODEX_LB_UPSTREAM_CONNECT_TIMEOUT_SECONDS=30
CODEX_LB_STREAM_IDLE_TIMEOUT_SECONDS=300
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,57 @@ print(response.choices[0].message.content)

</details>

## Anthropic Messages Mode (POC)

`codex-lb` serves two Anthropic-compatible routes:

- `POST /claude/v1/messages` (direct OAuth-backed API proxy to `api.anthropic.com/v1/messages`)
- `POST /claude-sdk/v1/messages` (local Claude SDK runtime via `claude-agent-sdk`)

Start the server (OpenAI routes and both Anthropic routes are enabled):

```bash
uv run fastapi run app/main.py --host 0.0.0.0 --port 2455
```

Prerequisites:

```bash
claude /login
uv sync
```

Usage windows source (Linux-only auto-discovery + optional overrides):

- Set `CODEX_LB_ANTHROPIC_USAGE_REFRESH_ENABLED=true` to enable 5h/7d usage ingestion.
- Auto-discovery from local Claude credentials (`claude login`) is enabled by default for 5h/7d usage ingestion.
- Usage polling calls Anthropic OAuth usage API (`/api/oauth/usage`) with the configured OAuth beta header.
- You can override usage auth explicitly with:

```bash
export CODEX_LB_ANTHROPIC_USAGE_BEARER_TOKEN="sk-ant-oat01-..."
```

Example request (API route):

```bash
curl -sS http://127.0.0.1:2455/claude/v1/messages \
-H 'content-type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role":"user","content":"Hello"}]
}'
```

Notes:

- `/claude/v1/messages` sends requests directly to `api.anthropic.com/v1/messages` using discovered or configured OAuth credentials.
- `/claude-sdk/v1/messages` runs generation through the local Claude SDK runtime.
- API compatibility for `/claude/v1/messages` includes request normalization and optional CLI header/system-prompt parity helpers.
- OpenAI compatibility routes (`/v1/responses`, `/v1/chat/completions`) stay available in the same server instance.

## API Key Authentication

API key auth is **disabled by default** — the proxy is open to any client. Enable it in **Settings → API Key Auth** on the dashboard.
Expand Down
Loading