[Bug]: provider doubao with no base_url sends the Doubao API key to api.openai.com instead of the Ark endpoint

Author: sxh313Created Sep 28, 2026Updated Sep 28, 2026

What happened?

A doubao configuration without base_url does not fail, and does not reach Volcengine: it silently sends the user's Doubao API key to OpenAI's host and then reports OpenAI's error. The README's own provider line (README.md:159, trae-cli run "…" --provider doubao --model doubao-seed-1.6) works only if the reader also exported DOUBAO_BASE_URL two lines earlier in a generic env block (README.md:107-108), and the failure that follows points at the wrong service entirely — the user goes looking for a bad Doubao key while the request that was rejected was sent to api.openai.com.

trae_agent/utils/llm_clients/doubao_client.py:42-46

python
class DoubaoClient(OpenAICompatibleClient):
    """Doubao client wrapper that maintains compatibility while using the new architecture."""

    def __init__(self, model_config: ModelConfig):
        super().__init__(model_config, DoubaoProvider())

DoubaoProvider.create_client (:18-22) passes base_url straight into openai.OpenAI(...), and the OpenAI SDK's contract for base_url=None is "use https://api.openai.com/v1". So an unset base_url is not an error for this provider — it is a redirect to a third party.

Its sibling does this correctly. trae_agent/utils/llm_clients/openrouter_client.py:65-74:

python
class OpenRouterClient(OpenAICompatibleClient):
    def __init__(self, model_config: ModelConfig):
        if (
            model_config.model_provider.base_url is None
            or model_config.model_provider.base_url == ""
        ):
            model_config.model_provider.base_url = "https://openrouter.ai/api/v1"

Two providers, both OpenAI-compatible, both documented in the same README section, one with a default endpoint and one without. ollama_client.py:32-38 defaults to http://localhost:11434/v1. doubao is the odd one out, and the cost of the omission is not a clear error — it is a wrong-host request carrying a live credential.

Reproduction

No real key, no network: httpx.MockTransport captures the URL the SDK composes and whether an Authorization header went with it. Run against main (e839e55), openai==1.86.0, Python 3.12:

doubao: base_url=None (main's behaviour)
    -> POST https://api.openai.com/v1/chat/completions
    auth-header=SENT  (AuthenticationError)
doubao: no trailing slash
    -> POST https://ark.cn-beijing.volces.com/api/v3/chat/completions
    auth-header=SENT  (AuthenticationError)
doubao: trailing slash (README:108)
    -> POST https://ark.cn-beijing.volces.com/api/v3/chat/completions
    auth-header=SENT  (AuthenticationError)
openrouter default
    -> POST https://openrouter.ai/api/v1/chat/completions
    auth-header=SENT  (AuthenticationError)

The same check at the client level, which is what a test can assert without a transport:

$ python -c "…DoubaoClient(ModelConfig(… base_url=None, model='doubao-seed-1.6')).client.base_url"
doubao      -> https://api.openai.com/v1/
openrouter  -> https://openrouter.ai/api/v1/

This shape is normal, not adversarial: the repository's own doubao fixtures in tests/utils/test_config.py:157-166 and :182-191 carry api_key, model, max_tokens, temperature, top_p, max_retries and no base_url — exactly the config that lands on OpenAI's host today.

For reference, the Azure path in the same directory is explicit about the missing value it cares about (azure_client.py:22-23 raises ValueError("base_url is required for AzureClient")), and config.py:20 documents base_url as optional. So "optional" is the documented contract; what is missing is an endpoint to be optional about.

What did you expect to happen?

DoubaoClient should default base_url to the Ark endpoint the README already publishes (https://ark.cn-beijing.volces.com/api/v3) when it is unset or empty, the way OpenRouterClient defaults its own, and leave an explicitly configured base_url untouched. Both trailing-slash and bare forms produce the same request URL (measured above), so the literal is not delicate.

Direction

Mirror OpenRouterClient.__init__ in DoubaoClient.__init__ — the same two-condition guard, one default, four lines — and add tests that assert the composed base URL for None, for "", and for an explicitly configured value. No change to DoubaoProvider.create_client, to the OpenRouter default, or to any other provider.

One thing this does not fix, and I want to be explicit rather than have it mistaken for covered: a user can still point doubao (or any OpenAI-compatible provider) at an arbitrary host and have their key sent there. That is how OpenAI-compatible providers work, and the only repo-side mitigation would be a config-time warning about cross-host credentials, which is a maintainer decision and not mine to slip in here.

I'll take this, with tests that need no key and no network.