Summary
components.ResponsesRequest fails to marshal when ServiceTier is omitted.
This happens before any HTTP request is sent, during local JSON serialization.
I opened a PR with a minimal reproduction and proposed a fix #300
I saw the contributing guide says this repository contains generated code and does not accept direct code changes, so I am opening this issue as the official report and linking the PR for context.
Reproduction
This code fails when ServiceTier is not explicitly set:
package main
import (
"context"
"fmt"
"log"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Beta.Responses.Send(ctx, components.ResponsesRequest{
Input: openrouter.Pointer(
components.CreateInputsUnionStr("Hey there"),
),
Model: openrouter.Pointer("openai/gpt-4o-mini"),
Stream: openrouter.Bool(true),
}, nil)
if err != nil {
log.Printf("error type: %T", err)
log.Printf("error value: %+v", err)
log.Fatal(err)
}
if res != nil {
defer res.EventStream.Close()
for res.EventStream.Next() {
event := res.EventStream.Value()
delta := event.Data.TextDeltaEvent.GetDelta()
fmt.Print(delta)
}
}
}
Actual behavior
The request fails before reaching the API:
error serializing request body: json: error calling MarshalJSON for type components.ResponsesRequest:
json: error calling MarshalJSON for type json.RawMessage:
invalid character 'a' looking for beginning of value
The same issue also happens with Stream: openrouter.Bool(false), so the problem is not streaming-specific.
A minimal local reproduction is:
req := components.ResponsesRequest{
Input: openrouter.Pointer(
components.CreateInputsUnionStr("Hey there"),
),
Model: openrouter.Pointer("openai/gpt-4o-mini"),
Stream: openrouter.Bool(false),
}
_, err := json.Marshal(req)
This fails with the same serialization error.
Expected behavior
ResponsesRequest should marshal successfully when ServiceTier is omitted.
Since ResponsesRequest.ServiceTier has:
ServiceTier optionalnullable.OptionalNullable[ResponsesRequestServiceTier] `default:"auto" json:"service_tier"`
the generated JSON should either omit service_tier or serialize the default as a valid JSON string:
Root cause
The default value auto appears to be emitted as raw JSON:
That is invalid JSON. It should be emitted as:
This explains why explicitly setting ServiceTier works:
serviceTier := components.ResponsesRequestServiceTierAuto
ServiceTier: optionalnullable.From(&serviceTier)
In that case, the enum value goes through the normal marshaling path and is serialized correctly.
Notes
The linked PR adds a regression test showing the failure and a small patch that prevents non-JSON default tag values from being emitted as raw JSON.
Full test suite passed locally with:
Environment:
github.com/OpenRouterTeam/go-sdk v0.5.0
Go: go1.26.3
OS: macOS amd64
Summary
components.ResponsesRequestfails to marshal whenServiceTieris omitted.This happens before any HTTP request is sent, during local JSON serialization.
I opened a PR with a minimal reproduction and proposed a fix #300
I saw the contributing guide says this repository contains generated code and does not accept direct code changes, so I am opening this issue as the official report and linking the PR for context.
Reproduction
This code fails when
ServiceTieris not explicitly set:Actual behavior
The request fails before reaching the API:
The same issue also happens with
Stream: openrouter.Bool(false), so the problem is not streaming-specific.A minimal local reproduction is:
This fails with the same serialization error.
Expected behavior
ResponsesRequestshould marshal successfully whenServiceTieris omitted.Since
ResponsesRequest.ServiceTierhas:the generated JSON should either omit
service_tieror serialize the default as a valid JSON string:Root cause
The default value
autoappears to be emitted as raw JSON:autoThat is invalid JSON. It should be emitted as:
"auto"This explains why explicitly setting
ServiceTierworks:In that case, the enum value goes through the normal marshaling path and is serialized correctly.
Notes
The linked PR adds a regression test showing the failure and a small patch that prevents non-JSON default tag values from being emitted as raw JSON.
Full test suite passed locally with:
go test ./...Environment: