Analyzed GitHub issue and related code.
UnderstandUpdated documentation with correct URL format.
EditCommented on issue explaining user error and fix.
VerifyAnalyze GitHub issue(s): https://github.com/badlogic/pi-mono/issues/956
For each issue:
Read the issue in full, including all comments and linked issues/PRs.
For bugs:
For feature requests:
Do NOT implement unless explicitly asked. Analyze and propose only.
Let me read the relevant OpenAI provider code and understand how base URLs are handled:
Let me check the OpenAI models configuration to see what the default baseUrl looks like:
Now I understand the issue. Let me verify the OpenAI SDK behavior and check if there's any documentation for the models.json format:
Let me check how the OpenAI response streaming handles error cases:
Let me check the OpenAI completions provider as well to see how it handles baseURL:
Users with OpenAI projects configured for US data residency get a 401 error:
"Attempted to access resource with incorrect regional hostname. Please make your request to us.api.openai.com"
The user attempted to fix this by setting baseUrl in models.json, but used the wrong URL format.
User error with missing path suffix. The user configured:
{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com" } }}But the correct configuration requires the /v1 path:
{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com/v1" } }}OpenAI models have baseUrl: "https://api.openai.com/v1" by default. When the user overrides without /v1, the OpenAI SDK hits https://us.api.openai.com/chat/completions which returns an HTML error page. The streaming code then displays HTML fragments as text (the itle></head> and /center> garbage the user saw).
Two-part solution:
1. Documentation update (essential): Add explicit example for OpenAI regional endpoints in docs/models.md
2. Environment variable support (nice-to-have): Support OPENAI_BASE_URL like the official OpenAI SDK does, allowing users to set OPENAI_BASE_URL=https://us.api.openai.com/v1 as an alternative to models.json
| File | Change |
|---|---|
packages/coding-agent/docs/models.md | Add "OpenAI Regional Endpoints" section with correct example |
packages/ai/src/providers/openai-responses.ts | Check OPENAI_BASE_URL env var in createClient() |
packages/ai/src/providers/openai-completions.ts | Check OPENAI_BASE_URL env var in createClient() |
packages/coding-agent/src/cli/args.ts | Document OPENAI_BASE_URL in env vars section |
packages/ai/README.md | Document OPENAI_BASE_URL environment variable |
For openai-responses.ts and openai-completions.ts, modify createClient():
return new OpenAI({ apiKey, baseURL: model.baseUrl || process.env.OPENAI_BASE_URL, dangerouslyAllowBrowser: true, defaultHeaders: headers,});Actually, the logic should be: env var overrides model.baseUrl when provider is "openai":
const baseURL = model.provider === "openai" && process.env.OPENAI_BASE_URL ? process.env.OPENAI_BASE_URL : model.baseUrl;For docs/models.md, add under "Overriding Built-in Providers":
### OpenAI Regional Endpoints
For OpenAI projects with data residency requirements (US, EU), override the base URL.Note: The `/v1` path suffix is required.
```json{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com/v1" } }}Or set the environment variable: OPENAI_BASE_URL=https://us.api.openai.com/v1
just update docs, then comment on the issue telling the user what they did wrong and how to fix it
Now let me comment on the issue:
Done. I've:
Updated docs/models.md: Added "OpenAI Regional Endpoints" subsection under "Overriding Built-in Providers" with the correct URL format (https://us.api.openai.com/v1)
Commented on issue #956: Explained that the missing /v1 suffix caused the SDK to hit an HTML page instead of the API, with the correct configuration example
{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com" } }}{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com/v1" } }}return new OpenAI({ apiKey, baseURL: model.baseUrl || process.env.OPENAI_BASE_URL, dangerouslyAllowBrowser: true, defaultHeaders: headers,});const baseURL = model.provider === "openai" && process.env.OPENAI_BASE_URL ? process.env.OPENAI_BASE_URL : model.baseUrl;### OpenAI Regional Endpoints
For OpenAI projects with data residency requirements (US, EU), override the base URL.Note: The `/v1` path suffix is required.
```json{ "providers": { "openai": { "baseUrl": "https://us.api.openai.com/v1" } }}