Skip to content

fix: send max_completion_tokens to Azure OpenAI reasoning models - #31952

Merged
ethanndickson merged 9 commits into
mainfrom
issue-31714-e16j
Dec 2, 2026
Merged

ethanndickson merged 9 commits into
mainfrom
issue-31714-e16j

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Closes #31714
Closes WI-31

Azure OpenAI reasoning models reject max_tokens:

Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.

We pick between max_tokens and max_completion_tokens from the model name, and that check only knew names up to gpt-5, so a gpt-6-luna deployment failed on default settings. To fix, the fantasy bump (coder/fantasy#86, coder/fantasy#87 and coder/fantasy#88) extends the check to gpt-6 through gpt-9. That bump is a full sync with upstream, so it also brings the other chatd changes listed there, which is why a few test expectations move here.

On Azure that name is the deployment name though, which doesn't have to say what model it serves. So the model form now also shows the existing Reasoning Model setting for Azure models, and we obey it. With it on, we send max_completion_tokens and drop temperature and top_p, whatever the deployment is called.

I confirmed against a real Azure gpt-5.4 deployment that it rejects max_tokens and accepts max_completion_tokens, but that test resource has since gone, so I haven't run this exact change against Azure.

This only fixes the max_tokens error. Going by Microsoft's docs, I think GPT-6 chats on Azure will then hit a second error, as on Chat Completions those models only accept tools with the reasoning effort set to none, or not at all. The OpenAI and Bedrock providers use the Responses API, so they aren't affected. I can't reproduce that for the same reason, so it's being tracked separately at CODAGT-1655.

@linear-code

linear-code Bot commented Nov 10, 2026

Copy link
Copy Markdown

CODAGT-1541

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T09:21:49.830237Z 893197b Manual request
🔒 Security Review ✅ Completed 2026-12-02T07:59:13.140559Z 2390ba0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c072f4748f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: ab8e1b1ee6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Base automatically changed from codagt-1430-fantasy-media-label to main November 10, 2026 13:06
@ethanndickson
ethanndickson temporarily deployed to main November 10, 2026 13:06 — with GitHub Actions Inactive
Azure OpenAI providers fell through to the OpenAI-compatible client, which drops every provider_options.openai setting and always speaks Chat Completions with max_tokens. Azure now shares the OpenAI client. An unset use_responses_api defaults to Chat Completions for Azure, because a deployment name does not identify the model, and the admin UI shows Use Responses API and Reasoning Model for Azure.

Fixes #31714
…type

ModelFromConfig checked reasoning_mode against the client name. Azure and
Bedrock OpenAI-format models use the OpenAI client, so the runtime check
let them through. newModel now runs the same check as the API, with the
configured AI provider type, and returns a config error.
ethanndickson added a commit that referenced this pull request Nov 10, 2026
Part of CODAGT-1430
Relates to CODAGT-1541

Stacked on #31743.

This bumps fantasy to pick up coder/fantasy#84 and coder/fantasy#85.

A Chat Completions tool message can only hold text, so fantasy sends
tool result media (images, audio, and now PDFs from #31384) in a `role:
"user"` message right after it. That gives whatever the tool returned
the authority of the user's own words, which Codex flagged on #31383 as
a prompt injection risk for MCP tools that return untrusted files.

coder/fantasy#84 starts that user message with a text part naming the
tool call and saying the content is tool output, not instructions from
the user. It only changes the Chat Completions paths (`openai` without
the Responses API, `openaicompat`, OpenRouter and Vercel); Anthropic and
Responses keep the media inside the tool result. AI Bridge records the
last user message's text as the prompt, so on the step after a tool
returns media, it'll now record the label. I think that's fine for now.

coder/fantasy#85 fixes the output token limit field. The OpenAI provider
sent `max_tokens` unless the model ID looked like a reasoning model, and
reasoning models reject it:

```
Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
```

That breaks any reasoning model whose ID fantasy doesn't recognise, e.g.
an Azure deployment name, which doesn't say what model it serves (Azure
providers start using this client in #31952). The OpenAI provider now
sends `max_completion_tokens` on every Chat Completions request, which
is what OpenAI deprecated `max_tokens` in favour of. `openaicompat`,
OpenRouter and Vercel keep `max_tokens`, so self-hosted servers behind
the OpenAI Compatible provider are unaffected. I've added a test that
checks the field on each route, and the models docs no longer say Max
Completion Tokens is only for reasoning models.
@ethanndickson
ethanndickson temporarily deployed to main November 10, 2026 13:07 — with GitHub Actions Inactive
@ethanndickson
ethanndickson marked this pull request as draft November 10, 2026 14:20
@ethanndickson
ethanndickson marked this pull request as ready for review November 12, 2026 01:19
@ethanndickson
ethanndickson temporarily deployed to main November 12, 2026 01:19 — with GitHub Actions Inactive
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 761fea0e4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 761fea0e4c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ethanndickson
ethanndickson temporarily deployed to main November 12, 2026 01:53 — with GitHub Actions Inactive
Comment thread docs/coder-agents/models.md Resolved
Comment thread docs/coder-agents/models.md Resolved
Comment thread docs/coder-agents/models.md Resolved
@coderagents

coderagents Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Blocking

  • docs/coder-agents/models.md (open) - The Azure note should mention that the Responses route accepts images but not audio or PDFs, since audio tool results are silently dropped when Use Responses API is set to On.
  • docs/coder-agents/models.md (open) - The Azure note should state that the Reasoning Model override is available for Azure, distinct from Reasoning Mode.
  • docs/coder-agents/models.md (open) - The option value On should be bolded for consistency with the UI-element formatting rule. (fixed in 26612e5)
Findings for agents
- id: coverage-1
  persona: coverage
  class: missing
  blocking: true
  file: docs/coder-agents/models.md
  line: 289
  quote: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to On, because the deployment name doesn't identify the model."
  evidence:
    - coderd/x/chatd/chatprovider/chatprovider.go:148-150
    - coderd/x/chatd/media_sanitize.go
  rule: null
  problem: Turning on **Use Responses API** for an Azure model silently drops audio tool-result media, and the note does not mention it.
  fix: Add to the Azure note that the Responses route accepts images but not audio or PDFs.
  verified: true

- id: coverage-2
  persona: coverage
  class: missing
  blocking: true
  file: docs/coder-agents/models.md
  line: 289
  quote: "Azure OpenAI uses the same options as OpenAI except Reasoning Mode."
  evidence:
    - site/src/api/chatModelOptionsGenerated.json:90
  rule: null
  problem: The **Reasoning Model** override is now exposed for Azure, but the Azure note still says Azure uses the same options as OpenAI except Reasoning Mode.
  fix: Clarify that the **Reasoning Model** override is available for Azure, distinct from Reasoning Mode.
  verified: true

- id: language-1
  persona: language
  class: rule
  blocking: true
  file: docs/coder-agents/models.md
  line: 289
  quote: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to On, because the deployment name doesn't identify the model."
  evidence:
    - docs/coder-agents/platform-controls/virtual-desktop.md:65
  rule: docs/.style/style-guide/formatting.md#bold-for-ui-elements
  problem: The option value **On** is literal UI text and should be bolded.
  fix: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to **On**, because the deployment name doesn't identify the model."
  verified: true

Automated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong.

@ethanndickson
ethanndickson temporarily deployed to main November 12, 2026 03:28 — with GitHub Actions Inactive
@ethanndickson
ethanndickson temporarily deployed to main November 13, 2026 06:01 — with GitHub Actions Inactive
@ethanndickson
ethanndickson temporarily deployed to main November 13, 2026 06:07 — with GitHub Actions Inactive
@ethanndickson
ethanndickson temporarily deployed to main November 13, 2026 06:40 — with GitHub Actions Inactive

@coderagents coderagents Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated doc-check review of the latest commit, generated by Coder Agents.

Comment thread docs/coder-agents/models.md Outdated
The **OpenAI Compatible** type is a catch-all for any service that exposes an OpenAI-compatible chat completions endpoint.
Use it to connect to self-hosted models, internal gateways, or third-party proxies like LiteLLM.

Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Newcomer) The paragraph says which models use the Azure OpenAI type, but it doesn't tell the reader how to check a deployment against that rule. Point them to the model each deployment serves, which the note below says the deployment name doesn't show.

Suggested change
Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models.
Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models. Check the model that each deployment serves before you choose a type, because the deployment name doesn't show it.

Bump the fantasy fork to its sync with upstream v0.48.3 (coder/fantasy#86),
whose Chat Completions reasoning check knows gpt-6 through gpt-9. Azure
OpenAI models now also obey the Reasoning Model setting, and the model
form shows it for them, as a deployment name does not have to say what
model it serves.

This replaces the earlier approach of routing Azure OpenAI through the
OpenAI client.
@ethanndickson ethanndickson changed the title fix: route Azure OpenAI through the OpenAI client fix: send max_completion_tokens to Azure OpenAI reasoning models Dec 1, 2026
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: cea3e57714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: cea3e57714

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

coder/fantasy#87 stops treating model IDs that contain -chat as
non-reasoning models and recognizes chat-latest, so Azure OpenAI
deployments named like gpt-5.1-chat or gpt-chat-latest get
max_completion_tokens.
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2390ba084a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2390ba084a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…that offer it

The OpenAI-compatible client obeyed a stored reasoning model override for
every provider type it serves, although the model form offers the setting
only for OpenAI, Bedrock and Azure OpenAI. A value stored through the API
for a Google, OpenRouter, Vercel or OpenAI Compatible model is ignored
again, as on main.
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 989f13ba0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…names

coder/fantasy#88 lets a reasoning marker win over gpt-3, gpt-4 and
chatgpt- on Chat Completions, so Azure OpenAI deployments named like
chatgpt-5 get max_completion_tokens. It also narrows the oss and
computer-use markers to gpt-oss and a leading computer-use, so they no
longer match third-party model IDs.
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 893197b8c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson
ethanndickson merged commit b4d485b into main Dec 2, 2026
38 checks passed
@ethanndickson
ethanndickson deleted the issue-31714-e16j branch December 2, 2026 09:37
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 2, 2026

This branch had an error being deployed

1 failed and 1 inactive (outdated) deployments
docs-preview — 893197b8 Deployed Dec 2, 2026 by ethanndickson via cleanup #629
main — d5cd6370 Deployed Nov 13, 2026 by ethanndickson via cla #255788
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure OpenAI returned an unexpected error: 'max_tokens' is not supported with this model

2 participants