Fix ResponsesRequest marshaling when service_tier is omitted#300
Fix ResponsesRequest marshaling when service_tier is omitted#300ell-hol wants to merge 2 commits into
Conversation
19c9125 to
0a9def0
Compare
There was a problem hiding this comment.
⚠️ APPROVE unavailable on this installation — the maintainer GitHub App is not
configured, so the verdict below is posted as COMMENT. Event-level approval
(for branch-protection / review requirements) must be added out-of-band.
Perry's Review
Fixes invalid JSON marshaling for ResponsesRequest.ServiceTier: when the field is unset, the default:"auto" tag now correctly produces "auto" (quoted) rather than bare auto (invalid JSON).
Verdict: ✅ LGTM
Details
Risk: 🟢 Low
CI: no checks recorded (0 checks)
Findings: none
Security: no concerns
Test coverage: new test TestResponsesRequestMarshalWithoutServiceTier directly exercises the fixed path — constructs ResponsesRequest without ServiceTier, marshals, verifies both json.Valid and presence of "service_tier":"auto". Only one other OptionalNullable[EnumType] with a string default: tag exists in the codebase (ResponsesRequest.ServiceTier) and it is covered.
Unresolved threads: 1 prior Perry suggestion (companion test for ChatRequest.ServiceTier) — field is *ChatRequestServiceTier (plain pointer), already handled by the Kind==String branch; suggestion stands as optional documentation.
Scope: first review (full)
Review: tier=small · model=claude-sonnet-latest · score=?
Summary
This fixes a local JSON serialization error when using
Beta.Responses.Sendwithout explicitly settingServiceTier.I found the issue while testing the Responses API streaming path with this request:
This failed before any HTTP request was sent:
The same failure happens with
Stream: openrouter.Bool(false), so the issue is not specific to streaming. It happens during local request serialization.Root cause
ResponsesRequest.ServiceTierhas this struct tag:When
ServiceTieris omitted, the SDK applies the default valueauto.Before this patch, the default value could fall through to:
That means the default was serialized as raw JSON:
autoBut
autois not valid JSON. Sinceservice_tieris a string-like enum, the serialized JSON value must be:"auto"This explains why explicitly setting
ServiceTierworked:In that case, the enum value goes through the normal marshaling path and is correctly serialized as
"auto".Behavior before
This failed:
with:
Behavior after
The same request now marshals successfully.
The default
service_tieris emitted as valid JSON:{ "input": "Hey there", "model": "openai/gpt-4o-mini", "service_tier": "auto", "stream": false }Fix
The default marshaling logic now checks whether the default tag value is already valid JSON.
If it is valid JSON, it is preserved as-is. This keeps existing defaults such as
true,false,null, and numeric values working the same way.If it is not valid JSON, it is serialized as a JSON string. This fixes string-like defaults such as
auto.Test
Added a regression test covering
ResponsesRequestwithout an explicitServiceTier.go test ./models/components -run TestResponsesRequestMarshalWithoutServiceTier -vFull test suite passes:
go test ./...