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.
The OpenAI chat client never applies
req.MaxCompletionTokens. Inclients/openai/chat_complete.go, theopenai.ChatCompletionNewParamsstruct (around line 274) setsModel,Messages,ToolChoice,Temperature,ReasoningEffort, andResponseFormat, but never sets a max-tokens field. So when a caller setsMaxCompletionTokenson the request:ai.max_completion_tokensspan attribute is not recorded (unlike the Anthropic and Google clients).By contrast:
ai.max_completion_tokens?Expected
The OpenAI client should set
MaxCompletionTokens(the Chat Completionsmax_completion_tokensfield) on the params whenreq.MaxCompletionTokens != nil, and record theai.max_completion_tokensspan attribute, matching Google's conditional behaviour.Notes
Found during the observability review on PR #288. The
docs/observability.mdcatalogue added there documents the current (pre-fix) behaviour accurately; this issue tracks the functional fix.