Skip to content

[Bug]: Alibaba Token Plan ignores Singapore baseUrl and forces Beijing endpoint at runtime #200

Closed

Description

@Jin-Doh

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

  1. Configure the built-in provider id alibaba-token-plan with a Singapore
    Token Plan API key.

  2. 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"
          ]
        }
      }
    }
  3. 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
      }'
  4. Observe HTTP 200 from Alibaba Cloud.

  5. Start OpenCodex:

    ocx start
  6. Call the same model through OpenCodex:

    codex \
      -m "alibaba-token-plan/qwen3.6-flash" \
      "Reply with exactly OK"
  7. Observe:

    Unexpected status 401 Unauthorized:
    Provider error 401:
    {
      "error": {
        "message": "Invalid API-key provided.",
        "type": "invalid_request_error",
        "code": "invalid_api_key"
      }
    }
    
  8. Rename the provider to an unregistered custom id:

    alibaba-token-plan-sg
    
  9. Keep the same base URL, key, adapter, and model.

  10. Call:

    codex \
      -m "alibaba-token-plan-sg/qwen3.6-flash" \
      "Reply with exactly OK"
  11. 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: true

In 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:

  1. Add allowBaseUrlOverride: true to alibaba-token-plan.
  2. Add explicit Beijing and Singapore endpoint choices.
  3. Add separate regional provider presets.
  4. 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 200

Area

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

  1. added
    bug
    on Jul 21, 2026
  2. Jin-Doh commented on Jul 21, 2026

    @Jin-Doh
    Author

    @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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions