Fix ResponsesRequest marshaling when service_tier is omitted#300
Fix ResponsesRequest marshaling when service_tier is omitted#300ell-hol wants to merge 4 commits into
Conversation
19c9125 to
0a9def0
Compare
There was a problem hiding this comment.
⚠️ APPROVE unavailable on this installation — the maintainer GitHub App lackspull_requests: writeon OpenRouterTeam, so the verdict below is posted as COMMENT. Event-level approval must be added out-of-band.
Perry's Review
Fixes a marshal error when ResponsesRequest.ServiceTier (an OptionalNullable enum) is left unset: the default tag value "auto" was emitted as raw bytes, which is not valid JSON. The fix calls json.Valid before using the tag value and quotes it when needed.
Verdict: ✅ LGTM
Details
Risk: 🟡 Medium — bug fix in a shared marshaling utility called by all three marshal paths; well-isolated with a regression test
CI: no checks configured
Findings: none — the fix is correct; one unresolved prior suggestion thread (companion test for other OptionalNullable[EnumType] defaults) is resolved on approval
Codex: disabled (small tier)
Research: skipped (small tier)
Security: no concerns — categories 1–8 not applicable to JSON serialization utility
Test coverage: regression test added in models/components/responsesrequest_test.go covering the exact failure path; verifies valid JSON output and that service_tier is serialized as the string "auto"
Unresolved threads: 1 open prior Perry suggestion — resolved on approval
Scope: first review (full)
Review: tier=small · model=claude-sonnet-latest · score=0.6
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 ./...