Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
add codex base url override
Raine Virtacef1d3d695f0
diff --git a/README.md b/README.mdindex 511ae71..2c3c4d6 100644--- a/README.md+++ b/README.md@@ -458,7 +458,8 @@ directory the auth tokens use, deliberately not `~/Library`) and at"userAgent": "claude-code-proxy/dev","model": "gpt-5.4","effort": "medium",- "serviceTier": "fast"+ "serviceTier": "fast",+ "baseUrl": "https://chatgpt.com/backend-api/codex/responses"},"kimi": {"userAgent": "KimiCLI/1.37.0",@@ -472,22 +473,23 @@ directory the auth tokens use, deliberately not `~/Library`) and at}```-| Variable | Config key | Default | Purpose |-| ------------------------ | ------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------- |-| `PORT` | `port` | `18765` | Proxy listen port |-| `XDG_STATE_HOME` | — | `~/.local/state` | Base dir for `proxy.log` |-| `CCP_LOG_STDERR` | `log.stderr` | unset | Also mirror log lines to stderr |-| `CCP_LOG_VERBOSE` | `log.verbose` | unset | Log full request/response bodies + every SSE event |-| `CCP_KIMI_OAUTH_HOST` | `kimi.oauthHost` | `https://auth.kimi.com` | Override Kimi's OAuth host (debugging only) |-| `CCP_KIMI_BASE_URL` | `kimi.baseUrl` | `https://api.kimi.com/coding/v1` | Override Kimi's API base URL |-| `CCP_CODEX_MODEL` | `codex.model` | unset | Force all Codex requests to this model (`gpt-5.2`, `gpt-5.3-codex`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.5`) |-| `CCP_CODEX_EFFORT` | `codex.effort` | unset | Force all Codex requests to this reasoning effort (`none`, `low`, `medium`, `high`, `xhigh`) |-| `CCP_CODEX_SERVICE_TIER` | `codex.serviceTier` | unset | Force all Codex requests to this service tier (`fast`/`priority`, `flex`; `fast` is sent upstream as `priority`) |-| `CCP_CODEX_ORIGINATOR` | `codex.originator` | `claude-code-proxy` | Override the `originator` header sent to Codex |-| `CCP_CODEX_USER_AGENT` | `codex.userAgent` | `claude-code-proxy/<version>` | Override the `User-Agent` header sent to Codex |-| `CCP_KIMI_USER_AGENT` | `kimi.userAgent` | `KimiCLI/1.37.0` | Override the `User-Agent` header sent to Kimi |-| `CCP_ORIGINATOR` | — | `claude-code-proxy` | Fallback for `CCP_CODEX_ORIGINATOR` |-| `CCP_USER_AGENT` | — | unset | Fallback for `CCP_CODEX_USER_AGENT` and `CCP_KIMI_USER_AGENT` |+| Variable | Config key | Default | Purpose |+| ------------------------ | ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |+| `PORT` | `port` | `18765` | Proxy listen port |+| `XDG_STATE_HOME` | — | `~/.local/state` | Base dir for `proxy.log` |+| `CCP_LOG_STDERR` | `log.stderr` | unset | Also mirror log lines to stderr |+| `CCP_LOG_VERBOSE` | `log.verbose` | unset | Log full request/response bodies + every SSE event |+| `CCP_KIMI_OAUTH_HOST` | `kimi.oauthHost` | `https://auth.kimi.com` | Override Kimi's OAuth host (debugging only) |+| `CCP_KIMI_BASE_URL` | `kimi.baseUrl` | `https://api.kimi.com/coding/v1` | Override Kimi's API base URL |+| `CCP_CODEX_MODEL` | `codex.model` | unset | Force all Codex requests to this model (`gpt-5.2`, `gpt-5.3-codex`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.5`) |+| `CCP_CODEX_EFFORT` | `codex.effort` | unset | Force all Codex requests to this reasoning effort (`none`, `low`, `medium`, `high`, `xhigh`) |+| `CCP_CODEX_SERVICE_TIER` | `codex.serviceTier` | unset | Force all Codex requests to this service tier (`fast`/`priority`, `flex`; `fast` is sent upstream as `priority`) |+| `CCP_CODEX_BASE_URL` | `codex.baseUrl` | `https://chatgpt.com/backend-api/codex/responses` | Override the Codex Responses endpoint |+| `CCP_CODEX_ORIGINATOR` | `codex.originator` | `claude-code-proxy` | Override the `originator` header sent to Codex |+| `CCP_CODEX_USER_AGENT` | `codex.userAgent` | `claude-code-proxy/<version>` | Override the `User-Agent` header sent to Codex |+| `CCP_KIMI_USER_AGENT` | `kimi.userAgent` | `KimiCLI/1.37.0` | Override the `User-Agent` header sent to Kimi |+| `CCP_ORIGINATOR` | — | `claude-code-proxy` | Fallback for `CCP_CODEX_ORIGINATOR` |+| `CCP_USER_AGENT` | — | unset | Fallback for `CCP_CODEX_USER_AGENT` and `CCP_KIMI_USER_AGENT` |A malformed `config.json` is reported on stderr and ignored; defaults are usedin its place. Invalid types for individual keys are warned and skipped withoutdiff --git a/src/cli.ts b/src/cli.tsindex 495349b..68be8a9 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -137,6 +137,9 @@ function printConfigSummary(): void {if (cfg.env.CCP_CODEX_SERVICE_TIER) overrides.push("CCP_CODEX_SERVICE_TIER (env)")else if (fromFile.codex?.serviceTier) overrides.push("codex.serviceTier (config)")+ if (cfg.env.CCP_CODEX_BASE_URL) overrides.push("CCP_CODEX_BASE_URL (env)")+ else if (fromFile.codex?.baseUrl) overrides.push("codex.baseUrl (config)")+if (cfg.env.CCP_LOG_VERBOSE !== undefined) overrides.push("CCP_LOG_VERBOSE (env)")else if (fromFile.log?.verbose) overrides.push("log.verbose (config)")diff --git a/src/config.test.ts b/src/config.test.tsindex 43bf511..de64414 100644--- a/src/config.test.ts+++ b/src/config.test.ts@@ -10,6 +10,7 @@ import {codexModel,codexEffort,codexServiceTier,+ codexBaseUrl,kimiUserAgent,kimiOauthHost,kimiBaseUrl,@@ -45,6 +46,7 @@ describe("config defaults", () => {expect(codexModel()).toBeUndefined()expect(codexEffort()).toBeUndefined()expect(codexServiceTier()).toBeUndefined()+ expect(codexBaseUrl("default-codex-url")).toBe("default-codex-url")expect(kimiUserAgent("default-kimi-ua")).toBe("default-kimi-ua")expect(kimiOauthHost()).toBe("https://auth.kimi.com")expect(kimiBaseUrl()).toBe("https://api.kimi.com/coding/v1")@@ -75,6 +77,19 @@ describe("file overrides default", () => {expect(codexServiceTier()).toBe("fast")})+ it("codex.baseUrl from config.json", () => {+ writeFileSync(+ configPath,+ JSON.stringify({+ codex: { baseUrl: "http://127.0.0.1:2455/backend-api/codex/responses" },+ }),+ )+ setEnv({})+ expect(codexBaseUrl("default")).toBe(+ "http://127.0.0.1:2455/backend-api/codex/responses",+ )+ })+it("kimi.oauthHost from config.json", () => {writeFileSync(configPath,@@ -113,6 +128,15 @@ describe("env overrides file", () => {expect(codexServiceTier()).toBe("fast")})+ it("CCP_CODEX_BASE_URL env wins over config", () => {+ writeFileSync(+ configPath,+ JSON.stringify({ codex: { baseUrl: "http://127.0.0.1:2455/file" } }),+ )+ setEnv({ CCP_CODEX_BASE_URL: "http://127.0.0.1:2455/env" })+ expect(codexBaseUrl("default")).toBe("http://127.0.0.1:2455/env")+ })+it("CCP_USER_AGENT env (generic fallback) is preferred over file", () => {writeFileSync(configPath,diff --git a/src/config.ts b/src/config.tsindex daae3b7..221ba4b 100644--- a/src/config.ts+++ b/src/config.ts@@ -17,6 +17,7 @@ export interface FileConfig {model?: stringeffort?: stringserviceTier?: string+ baseUrl?: string}kimi?: {userAgent?: string@@ -88,13 +89,18 @@ function validate(raw: unknown): FileConfig {return acc as NonNullable<FileConfig[K]>}- const codex = validateStringSection("codex", ["originator", "userAgent", "model", "effort", "serviceTier"], {- originator: "string",- userAgent: "string",- model: "string",- effort: "string",- serviceTier: "string",- })+ const codex = validateStringSection(+ "codex",+ ["originator", "userAgent", "model", "effort", "serviceTier", "baseUrl"],+ {+ originator: "string",+ userAgent: "string",+ model: "string",+ effort: "string",+ serviceTier: "string",+ baseUrl: "string",+ },+ )if (codex) out.codex = codexconst kimi = validateStringSection("kimi", ["userAgent", "oauthHost", "baseUrl"], {@@ -200,6 +206,11 @@ export function codexServiceTier(): string | undefined {return emptyOrUnset(c.env.CCP_CODEX_SERVICE_TIER) ?? emptyOrUnset(c.file.codex?.serviceTier)}+export function codexBaseUrl(defaultValue: string): string {+ const c = getConfig()+ return c.env.CCP_CODEX_BASE_URL ?? c.file.codex?.baseUrl ?? defaultValue+}+export function kimiUserAgent(defaultValue: string): string {const c = getConfig()return (diff --git a/src/providers/codex/client.ts b/src/providers/codex/client.tsindex 73f2f03..9d605f0 100644--- a/src/providers/codex/client.ts+++ b/src/providers/codex/client.ts@@ -1,5 +1,5 @@import { CODEX_API_ENDPOINT, ORIGINATOR as ORIGINATOR_DEFAULT } from "./auth/constants.ts"-import { codexOriginator, codexUserAgent } from "../../config.ts"+import { codexBaseUrl, codexOriginator, codexUserAgent } from "../../config.ts"declare const BUILD_VERSION: string | undefinedconst PROXY_VERSION = typeof BUILD_VERSION === "string" ? BUILD_VERSION : "dev"import { forceRefresh, getAuth } from "./auth/manager.ts"@@ -93,14 +93,16 @@ async function doFetch(headers.set("x-codex-window-id", `${sessionId}:0`)}+ const codexUrl = codexBaseUrl(CODEX_API_ENDPOINT)+log.debug("posting to codex", {- url: CODEX_API_ENDPOINT,+ url: codexUrl,model: body.model,inputCount: body.input.length,toolCount: body.tools?.length ?? 0,})- return fetch(CODEX_API_ENDPOINT, {+ return fetch(codexUrl, {method: "POST",headers,body: JSON.stringify(body),