[Bug]: an Azure provider with no api_version dies inside the SDK, and api_version: "" sends requests with no api-version at all

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

What happened?

Configuring an Azure deployment the way this repository documents providers ends in an error raised inside the openai SDK, pointing at an environment variable that no trae-agent documentation mentions. An empty api_version is worse: it is accepted, and the api-version query parameter then disappears from every request.

trae_agent/utils/llm_clients/azure_client.py:25-29 passes ModelProvider.api_version straight through:

python
return openai.AzureOpenAI(
    azure_endpoint=base_url,
    api_version=api_version,  # may be None, may be ""
    api_key=api_key,
)

ModelProvider.api_version is optional — trae_agent/utils/config.py:26 — even though the same class's own docstring, six lines earlier at trae_agent/utils/config.py:20, states "api_version is required for Azure". Nothing between the config file and this call enforces that.

Measured at e839e55, on a clean checkout, with no credentials and no network (openai.AzureOpenAI only connects on the first request). The rows that go through the SDK were reproduced on both the pinned floor openai>=1.86.0 (pyproject.toml:8) and openai 2.41.1, with identical output; the rows that go through AzureClient were reproduced on openai 1.86.0, the pinned floor:

api_version in config environment result at e839e55
unset nothing set ValueError: Must provide either the 'api_version' argument or the 'OPENAI_API_VERSION' environment variable, raised from azure_client.py:25
unset AZURE_API_VERSION=2024-03-01-preview the same ValueError — the SDK reads only OPENAI_API_VERSION
unset OPENAI_API_VERSION=2024-03-01-preview constructs successfully (the only environment route that works today)
"" nothing set constructs successfully, and the request URL is https://<endpoint>/openai/deployments/dep/chat/completions with request.url.params == {} — no api-version at all
"2024-03-01-preview" — .../chat/completions?api-version=2024-03-01-preview

The "" row is the expensive one: trae_config.json.example:45 shows "api_version": "2024-03-01-preview", so a user who blanks that value in place gets a client that builds without complaint, and the failure moves to the first model call. (What Azure itself answers there is not measured below — this machine has no Azure subscription; what is measured is that the request goes out without the parameter its non-empty control carries.)

Two details make the first error hard to get out of:

  • README.md:94-108 documents <PROVIDER>_API_KEY / <PROVIDER>_BASE_URL environment overrides and trae_agent/utils/config.py:97-98 implements exactly that pair for every provider. api_version is the third provider field and has no such path: git grep -n AZURE_API_VERSION over trae_agent/, docs/ and README.md at e839e55 returns nothing (rc=1). The README's env block also has no AZURE_* line at all, while README.md:20 advertises Azure support.
  • There is no CLI route either. trae_agent/cli.py:129-132 offers --provider, --model, --model-base-url, --api-key, and when the selected provider is not already in the config file, trae_agent/utils/config.py:90-94 constructs the new ModelProvider without api_version. Measured end to end through Config.create(...) + resolve_config_values(provider="azure", ...): provider=azure base_url='https://demo.openai.azure.com' api_key set=True api_version=None, and the next thing that happens is the SDK ValueError above. So trae-agent run -p azure works only through a variable name the SDK happens to know, not one this project documents.

Meanwhile trae_agent/cli.py:687 prints API Version Not set for that exact configuration, so the provider panel confirms the broken state without naming the field that caused it.

What did you expect to happen?

  • api_version should be honoured from the configuration, and — consistent with <PROVIDER>_API_KEY / <PROVIDER>_BASE_URL — from AZURE_API_VERSION as well.
  • When it is missing, or present but empty, the failure should be a trae-agent error naming the api_version provider field, raised where the existing base_url check already lives (azure_client.py:22-23), instead of an SDK error naming a variable the docs do not use — and instead of a silently parameter-less request.
  • An empty string should not be forwarded to the SDK as if it were a version.

Traceback

Traceback (most recent call last):
  File "<stdin>", line 15, in <module>
  File ".../trae_agent/utils/llm_clients/azure_client.py", line 53, in __init__
    super().__init__(model_config, AzureProvider())
  File ".../trae_agent/utils/llm_clients/openai_compatible_base.py", line 71, in __init__
    self.client = provider_config.create_client(self.api_key, self.base_url, self.api_version)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../trae_agent/utils/llm_clients/azure_client.py", line 25, in create_client
    return openai.AzureOpenAI(
           ^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/openai/lib/azure.py", line 203, in __init__
    raise ValueError(
ValueError: Must provide either the `api_version` argument or the `OPENAI_API_VERSION` environment variable

Captured by constructing AzureClient with api_version=None and an azure_endpoint of https://demo.openai.azure.com; the ... prefixes are my local checkout paths.

What is your system, Python, dependency version?

  • OS: Windows 11 (10.0.26200) — reproduced with no OS-specific code involved
  • Python: 3.12.13 (uv-managed)
  • Dependency: openai 1.86.0 (the floor in pyproject.toml:8) and openai 2.41.1, identical behaviour
  • Commit: e839e559ac61bdd0e057c375dd1dee391fee797d

Additional information that you believe is relevant to this bug

openai/lib/azure.py resolves the version as api_version if api_version is not None else os.environ.get("OPENAI_API_VERSION"), then raises only if the result is still None — so "" is treated as a version and survives to default_query={"api-version": ""}, which httpx then drops from the URL. That is why the two rows of the table above fail in two completely different ways.

The fix looks like three lines in azure_client.py, next to the base_url guard that is already there, plus tests; trae_agent/utils/llm_clients/azure_client.py is touched by no open pull request. I have it ready and will file it against this issue.