Repository navigation
Description
Summary
The built-in alibaba-token-plan provider ignores the Singapore baseUrl
persisted in ~/.opencodex/config.json and uses the registry's hardcoded
Beijing endpoint at runtime.
As a result, a valid Singapore Token Plan API key fails through OpenCodex with:
401 invalid_api_key
The same key succeeds with HTTP 200 when it is extracted from
config.json and sent directly to the configured Singapore endpoint.
I expected OpenCodex to use the baseUrl shown in the dashboard and stored in
the config file.
Reproduction
-
Configure the built-in provider id
alibaba-token-planwith a Singapore
Token Plan API key. -
Persist the following provider configuration:
{ "defaultProvider": "alibaba-token-plan", "providers": { "alibaba-token-plan": { "adapter": "openai-chat", "baseUrl": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1", "authMode": "key", "apiKey": "<redacted>", "defaultModel": "qwen3.6-flash", "liveModels": false, "models": [ "qwen3.6-flash" ] } } } -
Extract the exact key stored by OpenCodex and call the Singapore endpoint
directly:stored_key="$( jq -j '.providers["alibaba-token-plan"].apiKey' \ ~/.opencodex/config.json )" curl -i \ 'https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions' \ -H "Authorization: Bearer ${stored_key}" \ -H 'Content-Type: application/json' \ -d '{ "model": "qwen3.6-flash", "messages": [ { "role": "user", "content": "Reply with OK" } ], "stream": false }'
-
Observe HTTP 200 from Alibaba Cloud.
-
Start OpenCodex:
ocx start
-
Call the same model through OpenCodex:
codex \ -m "alibaba-token-plan/qwen3.6-flash" \ "Reply with exactly OK"
-
Observe:
Unexpected status 401 Unauthorized: Provider error 401: { "error": { "message": "Invalid API-key provided.", "type": "invalid_request_error", "code": "invalid_api_key" } } -
Rename the provider to an unregistered custom id:
alibaba-token-plan-sg -
Keep the same base URL, key, adapter, and model.
-
Call:
codex \ -m "alibaba-token-plan-sg/qwen3.6-flash" \ "Reply with exactly OK"
-
Observe that the request succeeds.
The issue also reproduces after a clean reinstall and after changing the local
OpenCodex proxy port.
Resolution
Fixed in commit 9b412d8e (cherry-pick of PR #189 onto dev). The alibaba-token-plan registry entry now includes allowBaseUrlOverride: true, allowing user-configured regional baseUrls (e.g. Singapore) to take precedence over the hardcoded Beijing endpoint. Shipping in the next release.
Suspected root cause
The registry entry for alibaba-token-plan hardcodes the Beijing endpoint:
{
id: "alibaba-token-plan",
label: "Alibaba Token Plan (Beijing)",
baseUrl:
"https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
adapter: "openai-chat",
authKind: "key"
}It does not set:
allowBaseUrlOverride: trueIn routedProviderConfig, the user-provided URL is only selected when the
registry URL is a template or allowBaseUrlOverride is enabled:
const baseUrl =
(registryBaseUrlIsTemplate || registryEntry.allowBaseUrlOverride)
&& userBaseUrlIsResolved
? userBaseUrl
: registryEntry.baseUrl;This appears to make the runtime use the Beijing URL even though the dashboard
and persisted config show the Singapore URL.
Suggested fix
One of the following:
- Add
allowBaseUrlOverride: truetoalibaba-token-plan. - Add explicit Beijing and Singapore endpoint choices.
- Add separate regional provider presets.
- Make the dashboard display the effective runtime URL or reject ignored URL
overrides.
Logs and screenshots
Unexpected status 401 Unauthorized: Provider error 401:
{"error":{"message":"Invalid API-key provided.","type":"invalid_request_error","code":"invalid_api_key"}},
url: http://127.0.0.1:10100/v1/responses
$ jq -j '.providers["alibaba-token-plan"].apiKey // empty' \
~/.opencodex/config.json | wc -c
113
$ stored_key="$(
jq -j '.providers["alibaba-token-plan"].apiKey // empty' \
~/.opencodex/config.json
)"
$ curl -i \
'https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions' \
-H "Authorization: Bearer ${stored_key}" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen3.6-flash",
"messages": [
{
"role": "user",
"content": "Reply with OK"
}
],
"stream": false
}'
HTTP/2 200Area
Provider adapter
Version
2.7.28
OS
macOS 26.5.2 (25F84, arm64)
Config shape
{
"port": 10100,
"hostname": "127.0.0.1",
"defaultProvider": "alibaba-token-plan",
"websockets": false,
"providers": {
"alibaba-token-plan": {
"adapter": "openai-chat",
"baseUrl": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
"authMode": "key",
"apiKey": "<redacted>",
"defaultModel": "qwen3.6-flash",
"liveModels": false,
"models": [
"qwen3.6-flash"
]
}
}
}Checks
- I searched existing issues and docs first.
- I removed secrets, tokens, and personal data from logs and screenshots.
Activity
Jin-Doh commentedon Jul 21, 2026
@lidge-jun
PR #189 addressed this but was reverted in b9b73f7.
Before re-submitting, could you share what prompted the revert so the follow-up avoids the same issue?