Calling the Responses API with a missing/default "type" in a reasoning input item results in an obscure error:
error unmarshaling json response body: json: cannot unmarshal string into Go value of type int64
These kinds of errors are pretty hard to narrow down for something that's presumably a misuse of the SDK. At the very least, it should give me an error about the missing type field before the API request gets sent out.
I'm new to Go and couldn't tell you exactly why this is happening. Below is what deepseek found.
Root cause: BadRequestResponseErrorData.Code is typed as int64 but the server can return string error codes for validation errors.
The full chain of events:
- A
ResponsesRequest with an InputsReasoning item that omits the Type field serializes to "type": "" (the zero value of InputsTypeReasoning).
- The server rejects this with HTTP 400 and a JSON body like:
{"error": {"code": "invalid_type", "message": "..."}}
- In responses.go:248-261, the SDK tries to unmarshal the 400 body into
sdkerrors.BadRequestResponseError, which contains components.BadRequestResponseErrorData (models/components/badrequestresponseerrordata.go:12):
type BadRequestResponseErrorData struct {
Code int64 `json:"code"` // <-- int64, but server sends a string!
Message string `json:"message"`
Metadata optionalnullable.OptionalNullable[map[string]any] `json:"metadata,omitzero"`
}
- Go's
json.Unmarshal fails with json: cannot unmarshal string into Go value of type int64 because the server returned "code": "invalid_type" (a string) but the struct expects int64.
- This is wrapped by
UnmarshalJsonFromResponseBody into the final error: error unmarshaling json response body: json: cannot unmarshal string into Go value of type int64
The mismatch: The Responses API's own embedded error field (ResponsesErrorField at models/components/responseserrorfield.go:51) correctly uses string-typed Code:
type ResponsesErrorField struct {
Code Code `json:"code"` // Code is a string type with enum values
Message string `json:"message"`
}
But the HTTP-level error data structs (for 4xx/5xx responses) all incorrectly type Code as int64, even though the server can return string codes (like "invalid_type", "invalid_prompt", etc.) for validation errors.
Calling the Responses API with a missing/default "type" in a reasoning input item results in an obscure error:
error unmarshaling json response body: json: cannot unmarshal string into Go value of type int64These kinds of errors are pretty hard to narrow down for something that's presumably a misuse of the SDK. At the very least, it should give me an error about the missing type field before the API request gets sent out.
I'm new to Go and couldn't tell you exactly why this is happening. Below is what deepseek found.
Root cause:
BadRequestResponseErrorData.Codeis typed as int64 but the server can return string error codes for validation errors.The full chain of events:
ResponsesRequestwith anInputsReasoningitem that omits the Type field serializes to"type": ""(the zero value ofInputsTypeReasoning).{"error": {"code": "invalid_type", "message": "..."}}sdkerrors.BadRequestResponseError, which containscomponents.BadRequestResponseErrorData(models/components/badrequestresponseerrordata.go:12):json.Unmarshalfails withjson: cannot unmarshal string into Go value of type int64because the server returned"code": "invalid_type"(a string) but the struct expects int64.UnmarshalJsonFromResponseBodyinto the finalerror: error unmarshaling json response body: json: cannot unmarshal string into Go value of type int64The mismatch: The Responses API's own embedded error field (
ResponsesErrorFieldat models/components/responseserrorfield.go:51) correctly uses string-typed Code:But the HTTP-level error data structs (for 4xx/5xx responses) all incorrectly type Code as int64, even though the server can return string codes (like "invalid_type", "invalid_prompt", etc.) for validation errors.