Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ CODEX_MODE=1 opencode run "task" # Temporarily enable
- Messages bubble up in OpenCode exactly where SDK errors normally surface.
- Helpful when working inside the OpenCode UI or CLI—users immediately see reset timing.

### CODEX_BASE_URL

**What it does:**
- Overrides the ChatGPT backend URL the plugin talks to (default: `https://chatgpt.com/backend-api`)
- OAuth headers and account info are still attached by the plugin as normal; only the destination host changes
- Useful for routing traffic through a local optimization/logging proxy (e.g. Headroom) that forwards upstream

**Usage:**
```bash
CODEX_BASE_URL=http://127.0.0.1:8787/backend-api opencode run "task"
```

---

## Configuration Files
Expand Down
5 changes: 3 additions & 2 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
/** Plugin identifier for logging and error messages */
export const PLUGIN_NAME = "openai-codex-plugin";

/** Base URL for ChatGPT backend API */
export const CODEX_BASE_URL = "https://chatgpt.com/backend-api";
/** Base URL for ChatGPT backend API. Override with CODEX_BASE_URL to route through a local proxy. */
export const CODEX_BASE_URL =
process.env.CODEX_BASE_URL || "https://chatgpt.com/backend-api";

/** Dummy API key used for OpenAI SDK (actual auth via OAuth) */
export const DUMMY_API_KEY = "chatgpt-oauth";
Expand Down
31 changes: 31 additions & 0 deletions test/constants.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';

describe('CODEX_BASE_URL override', () => {
const originalEnv = process.env.CODEX_BASE_URL;

beforeEach(() => {
delete process.env.CODEX_BASE_URL;
vi.resetModules();
});

afterEach(() => {
if (originalEnv === undefined) {
delete process.env.CODEX_BASE_URL;
} else {
process.env.CODEX_BASE_URL = originalEnv;
}
vi.resetModules();
});

it('defaults to the ChatGPT backend when unset', async () => {
const { CODEX_BASE_URL } = await import('../lib/constants.js');
expect(CODEX_BASE_URL).toBe('https://chatgpt.com/backend-api');
});

it('honors CODEX_BASE_URL when set, for routing through a local proxy', async () => {
process.env.CODEX_BASE_URL = 'http://127.0.0.1:8787/backend-api';
vi.resetModules();
const { CODEX_BASE_URL } = await import('../lib/constants.js');
expect(CODEX_BASE_URL).toBe('http://127.0.0.1:8787/backend-api');
});
});