Skip to content

OpenAI client silently ignores MaxCompletionTokens #291

Description

@maragubot

The OpenAI chat client never applies req.MaxCompletionTokens. In clients/openai/chat_complete.go, the openai.ChatCompletionNewParams struct (around line 274) sets Model, Messages, ToolChoice, Temperature, ReasoningEffort, and ResponseFormat, but never sets a max-tokens field. So when a caller sets MaxCompletionTokens on the request:

  • it is not sent to the OpenAI API, so the requested output cap has no effect, and
  • the ai.max_completion_tokens span attribute is not recorded (unlike the Anthropic and Google clients).

By contrast:

Client Sends max to API? Records ai.max_completion_tokens?
Anthropic Always (default 16384) Always
Google Only when the request sets it Only when the request sets it
OpenAI Never Never

Expected

The OpenAI client should set MaxCompletionTokens (the Chat Completions max_completion_tokens field) on the params when req.MaxCompletionTokens != nil, and record the ai.max_completion_tokens span attribute, matching Google's conditional behaviour.

Notes

Found during the observability review on PR #288. The docs/observability.md catalogue added there documents the current (pre-fix) behaviour accurately; this issue tracks the functional fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions