Skip to content

Commit 1fe233c

Browse files
committed
feat: default to CommandCode Provider API with dynamic model catalog
- Chat now calls the official POST /provider/v1/chat/completions with native OpenAI bodies (COMMANDCODE_UPSTREAM_MODE=provider default); Claude models and legacy mode keep the /alpha/generate tunnel - Dynamic model catalog refreshed from public /provider/v1/models at startup, filling the five unpublished context windows with live values - Credential env name compatibility (COMMAND_CODE_API_KEY, CMD_API_KEY) and COMMANDCODE_ZDR -> x-cmd-zdr: 1 zero-data-retention header - Billing, routing, and balance alerts stay on /alpha with no CLI - Dashboard shows the summed current balance next to credentials - Version scheme now tracks the CommandCode CLI version with a letter suffix (1.14.0.a)
1 parent 6a1b8b3 commit 1fe233c

24 files changed

Lines changed: 1473 additions & 269 deletions

.env.example

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# CommandCode upstream
2+
# Default COMMANDCODE_UPSTREAM_MODE=provider calls the official Provider API
3+
# (POST /provider/v1/chat/completions) for non-Claude models. Claude models and
4+
# COMMANDCODE_UPSTREAM_MODE=alpha use the legacy /alpha/generate tunnel.
5+
COMMANDCODE_UPSTREAM_MODE=provider
26
# Single-key mode: set this explicitly in production.
3-
# If omitted, the bridge reads ~/.commandcode/auth.json.
7+
# Recognized names in order: COMMAND_CODE_API_KEY, COMMANDCODE_API_KEY, CMD_API_KEY.
8+
# If omitted, the bridge also reads ~/.commandcode/auth.json.
49
COMMANDCODE_API_KEY=
5-
# Multi-key mode (optional): id=key pairs. Takes precedence over COMMANDCODE_API_KEY.
10+
# Multi-key mode (optional): id=key pairs. Takes precedence over the single key.
611
# COMMANDCODE_API_KEYS=primary=cmd_key_one,secondary=cmd_key_two
712
# Or point to a JSON file: {"credentials":[{"id":"primary","apiKey":"...","weight":1}]}
813
COMMANDCODE_CREDENTIALS_FILE=
@@ -18,6 +23,8 @@ COMMANDCODE_ALLOW_UNKNOWN_MODELS=false
1823
COMMANDCODE_CLI_VERSION=1.14.0
1924
COMMANDCODE_TIMEOUT_MS=300000
2025
COMMANDCODE_EMPTY_VISIBLE_RESPONSE_POLICY=error_on_length
26+
# Send x-cmd-zdr: 1 (zero data retention) on Provider API requests.
27+
COMMANDCODE_ZDR=false
2128

2229
# Balance alerts are opt-in and disabled by default. When enabled, alerts are logged
2330
# and optionally POSTed to COMMANDCODE_BALANCE_ALERT_WEBHOOK_URL.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ release/env.production
1212
*.tgz
1313
.DS_Store
1414
npm-debug.log*
15+
.commandcode/
16+
.omo/
17+
.senpi/
18+
.tmp/

README.ko.md

Lines changed: 74 additions & 68 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 74 additions & 68 deletions
Large diffs are not rendered by default.

README.zh.md

Lines changed: 74 additions & 68 deletions
Large diffs are not rendered by default.

docs/ARCHITECTURE.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ CommandCode Bridge
1717
├─ model alias/allowlist resolver
1818
├─ CommandCode credential router
1919
├─ CommandCode billing/usage snapshot cache
20-
├─ OpenAI → CommandCode converter
20+
├─ Provider API client (native OpenAI, default)
21+
├─ CommandCode /alpha client (Claude + legacy mode)
22+
├─ OpenAI → CommandCode converter (alpha path only)
2123
├─ CommandCode upstream HTTP client
22-
├─ CommandCode stream parser
23-
└─ CommandCode → OpenAI response converter
24+
├─ CommandCode stream parser (alpha path only)
25+
└─ CommandCode → OpenAI response converter (alpha path only)
2426
2527
2628
CommandCode API
27-
└─ POST /alpha/generate
29+
├─ POST /provider/v1/chat/completions (Provider API, non-Claude)
30+
└─ POST /alpha/generate (Claude + alpha mode)
2831
2932
30-
DeepSeek V4 Pro
33+
DeepSeek V4 Pro / Flash etc.
3134
```
3235

3336
## Request Flow
@@ -65,15 +68,18 @@ DeepSeek V4 Pro
6568

6669
## Upstream Compatibility
6770

68-
CommandCode's `/alpha/generate` requires `params.stream: true`. The bridge therefore always calls upstream streaming, even for OpenAI non-streaming clients.
71+
Provider mode (default) calls the official `POST /provider/v1/chat/completions` with a native OpenAI body and streams the provider's OpenAI SSE through with the public model id; `stream: false` requests are answered with a single JSON completion. Claude model ids are served through `POST /alpha/generate` because the Provider API exposes Claude only via the Anthropic `/messages` format. Legacy `alpha` mode keeps the old tunnel: `/alpha/generate` requires `params.stream: true`, so the bridge always calls upstream streaming there, even for OpenAI non-streaming clients.
72+
73+
The Provider API emits token usage in the final chunk with no opt-in required; `x-cmd-zdr: 1` is sent when `COMMANDCODE_ZDR` is enabled. Billing and usage snapshots (`/alpha/whoami`, `/alpha/billing/*`, `/alpha/usage/summary`) are shared by both modes and remain the routing and balance-alert data source.
6974

7075
## Error Strategy
7176

7277
- Invalid OpenAI request → HTTP 400 OpenAI-style error.
7378
- Disallowed model → HTTP 400 OpenAI-style error.
7479
- Missing upstream API key → HTTP 500 configuration error.
75-
- CommandCode HTTP failure → HTTP 502 with upstream status and sanitized body; selected credential cooldown/disable rules are applied.
76-
- CommandCode stream `error` event → fail over first if no visible output has been emitted and another credential is available; otherwise map to HTTP 502 or SSE error frame plus `[DONE]`.
80+
- Provider API HTTP failure → upstream status and OpenAI-style error body forwarded (for example `403 upgrade_required` or `429 rate_limit_error`); credential cooldown/disable rules are applied.
81+
- `/alpha` HTTP failure → HTTP 502 with upstream status and sanitized body.
82+
- `/alpha` stream `error` event → fail over first if no visible output has been emitted and another credential is available; otherwise map to HTTP 502 or SSE error frame plus `[DONE]`.
7783
- No available upstream credential → HTTP 503 OpenAI-style upstream error.
7884
- Unknown server failure → HTTP 500 generic error.
7985

docs/DEPLOYMENT.ko.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,20 @@ npm run smoke
388388

389389
### CommandCode upstream 옵션
390390

391-
| 변수 | 기본값 | 설명 |
392-
| ---------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
393-
| `COMMANDCODE_API_KEY` | 미설정 | single upstream CommandCode API key입니다. 비워두면 일반 CommandCode auth file을 읽을 수 있습니다. |
394-
| `COMMANDCODE_API_KEYS` | 미설정 | multi-key용 comma-separated `id=key` 목록입니다. 예: `primary=...,secondary=...`. single-key보다 우선합니다. |
395-
| `COMMANDCODE_CREDENTIALS` | 미설정 | JSON credential 배열/객체 또는 comma-separated multi-key 목록입니다. 구조화된 배포 시스템에서 유용합니다. |
396-
| `COMMANDCODE_CREDENTIALS_FILE` | 미설정 | JSON credentials 파일 경로입니다. upstream credential source 중 최우선입니다. 복잡한 multi-key에는 이 방식을 권장합니다. |
397-
| `COMMANDCODE_API_BASE` | `https://api.commandcode.ai` | upstream CommandCode API base URL입니다. 테스트나 upstream 변경 대응 외에는 바꾸지 마십시오. |
398-
| `COMMANDCODE_DEFAULT_MODEL` | `deepseek/deepseek-v4-pro` | `model: "default"` 요청이 실제로 사용할 upstream model입니다. |
399-
| `COMMANDCODE_ALLOWED_MODELS` | Pro + Flash | 허용할 model ID 목록입니다. 이 목록 밖 요청은 unknown model 허용 옵션을 켜지 않는 한 거부됩니다. |
400-
| `COMMANDCODE_ALLOW_UNKNOWN_MODELS` | `false` | 임의 model ID를 upstream으로 통과시킵니다. 운영에서는 권장하지 않습니다. |
401-
| `COMMANDCODE_CLI_VERSION` | `1.14.0` | 테스트된 CommandCode CLI 동작과 맞추기 위해 upstream에 보내는 version header입니다. |
402-
| `COMMANDCODE_TIMEOUT_MS` | `300000` | upstream generation timeout입니다. |
391+
| 변수 | 기본값 | 설명 |
392+
| ---------------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
393+
| `COMMANDCODE_API_KEY` | 미설정 | single upstream CommandCode API key입니다. `COMMAND_CODE_API_KEY`, `CMD_API_KEY`도 인식합니다. 비워두면 일반 CommandCode auth file을 읽을 수 있습니다. |
394+
| `COMMANDCODE_API_KEYS` | 미설정 | multi-key용 comma-separated `id=key` 목록입니다. 예: `primary=...,secondary=...`. single-key보다 우선합니다. |
395+
| `COMMANDCODE_CREDENTIALS` | 미설정 | JSON credential 배열/객체 또는 comma-separated multi-key 목록입니다. 구조화된 배포 시스템에서 유용합니다. |
396+
| `COMMANDCODE_CREDENTIALS_FILE` | 미설정 | JSON credentials 파일 경로입니다. upstream credential source 중 최우선입니다. 복잡한 multi-key에는 이 방식을 권장합니다. |
397+
| `COMMANDCODE_UPSTREAM_MODE` | `provider` | `provider`는 비-Claude 모델을 공식 Provider API(`/provider/v1/chat/completions`)로 호출합니다. `alpha`는 모든 모델을 legacy `/alpha/generate` 터널로 강제합니다. |
398+
| `COMMANDCODE_ZDR` | `false` | Provider API 요청에 `x-cmd-zdr: 1`(zero data retention)을 보냅니다. |
399+
| `COMMANDCODE_API_BASE` | `https://api.commandcode.ai` | upstream CommandCode API base URL입니다. 테스트나 upstream 변경 대응 외에는 바꾸지 마십시오. |
400+
| `COMMANDCODE_DEFAULT_MODEL` | `deepseek/deepseek-v4-pro` | `model: "default"` 요청이 실제로 사용할 upstream model입니다. |
401+
| `COMMANDCODE_ALLOWED_MODELS` | Pro + Flash | 허용할 model ID 목록입니다. 이 목록 밖 요청은 unknown model 허용 옵션을 켜지 않는 한 거부됩니다. |
402+
| `COMMANDCODE_ALLOW_UNKNOWN_MODELS` | `false` | 임의 model ID를 upstream으로 통과시킵니다. 운영에서는 권장하지 않습니다. |
403+
| `COMMANDCODE_CLI_VERSION` | `1.14.0` | 테스트된 CommandCode CLI 동작과 맞추기 위해 upstream에 보내는 version header입니다. |
404+
| `COMMANDCODE_TIMEOUT_MS` | `300000` | upstream generation timeout입니다. |
403405

404406
Credential JSON 파일 예시:
405407

docs/DEPLOYMENT.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,20 @@ npm run smoke
389389

390390
### CommandCode upstream options
391391

392-
| Variable | Default | Description |
393-
| ---------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
394-
| `COMMANDCODE_API_KEY` | unset | Single upstream CommandCode API key. If unset, the bridge can read the normal CommandCode auth file. |
395-
| `COMMANDCODE_API_KEYS` | unset | Comma-separated multi-key `id=key` list, for example `primary=...,secondary=...`. Takes precedence over single-key mode. |
396-
| `COMMANDCODE_CREDENTIALS` | unset | JSON credential array/object or comma-separated multi-key list. Useful for structured deployment systems. |
397-
| `COMMANDCODE_CREDENTIALS_FILE` | unset | Path to a JSON credentials file. Highest upstream credential precedence. Recommended for complex multi-key setups. |
398-
| `COMMANDCODE_API_BASE` | `https://api.commandcode.ai` | Upstream CommandCode API base URL. Change only for testing or if CommandCode changes endpoint base. |
399-
| `COMMANDCODE_DEFAULT_MODEL` | `deepseek/deepseek-v4-pro` | Upstream model used by `model: "default"`. |
400-
| `COMMANDCODE_ALLOWED_MODELS` | Pro + Flash | Comma-separated allowlist. Requests outside this list are rejected unless unknown models are allowed. |
401-
| `COMMANDCODE_ALLOW_UNKNOWN_MODELS` | `false` | Allows arbitrary model IDs to pass through. Not recommended for production. |
402-
| `COMMANDCODE_CLI_VERSION` | `1.14.0` | Version header sent upstream to match the tested CommandCode CLI behavior. |
403-
| `COMMANDCODE_TIMEOUT_MS` | `300000` | Upstream generation timeout. |
392+
| Variable | Default | Description |
393+
| ---------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
394+
| `COMMANDCODE_API_KEY` | unset | Single upstream CommandCode API key. Also recognized: `COMMAND_CODE_API_KEY`, `CMD_API_KEY`. If unset, the bridge can read the normal CommandCode auth file. |
395+
| `COMMANDCODE_API_KEYS` | unset | Comma-separated multi-key `id=key` list, for example `primary=...,secondary=...`. Takes precedence over single-key mode. |
396+
| `COMMANDCODE_CREDENTIALS` | unset | JSON credential array/object or comma-separated multi-key list. Useful for structured deployment systems. |
397+
| `COMMANDCODE_CREDENTIALS_FILE` | unset | Path to a JSON credentials file. Highest upstream credential precedence. Recommended for complex multi-key setups. |
398+
| `COMMANDCODE_UPSTREAM_MODE` | `provider` | `provider` calls the official Provider API for non-Claude models; `alpha` forces the legacy `/alpha/generate` tunnel for every model. |
399+
| `COMMANDCODE_ZDR` | `false` | Sends `x-cmd-zdr: 1` (zero data retention) on Provider API requests. |
400+
| `COMMANDCODE_API_BASE` | `https://api.commandcode.ai` | Upstream CommandCode API base URL. Change only for testing or if CommandCode changes endpoint base. |
401+
| `COMMANDCODE_DEFAULT_MODEL` | `deepseek/deepseek-v4-pro` | Upstream model used by `model: "default"`. |
402+
| `COMMANDCODE_ALLOWED_MODELS` | Pro + Flash | Comma-separated allowlist. Requests outside this list are rejected unless unknown models are allowed. |
403+
| `COMMANDCODE_ALLOW_UNKNOWN_MODELS` | `false` | Allows arbitrary model IDs to pass through. Not recommended for production. |
404+
| `COMMANDCODE_CLI_VERSION` | `1.14.0` | Version header sent upstream to match the tested CommandCode CLI behavior. |
405+
| `COMMANDCODE_TIMEOUT_MS` | `300000` | Upstream generation timeout. |
404406

405407
Credential file shape:
406408

docs/PRD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CommandCode Bridge PRD
22

3-
> Product Requirement Document for an OpenAI-compatible HTTP proxy over CommandCode's `/alpha/generate` endpoint.
3+
> Product Requirement Document for an OpenAI-compatible HTTP proxy over CommandCode's official Provider API (`/provider/v1`), with the legacy `/alpha/generate` tunnel retained for Claude models and billing.
44
55
## Mission
66

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commandcode-bridge",
3-
"version": "1.14.0",
3+
"version": "1.14.0.a",
44
"description": "OpenAI-compatible HTTP bridge for CommandCode's DeepSeek V4 Pro API path.",
55
"type": "module",
66
"license": "MIT",

0 commit comments

Comments
 (0)