Repository navigation
/v1/responses: emit fields the openai-python SDK marks required - #61
Conversation
PR #57 added the /v1/responses endpoint but the response object omitted three fields the openai-python SDK's Pydantic Response model marks as required (no default value): parallel_tool_calls : bool tool_choice : ToolChoice (string or object) tools : List[Tool] When any required field is absent, Pydantic raises ValidationError on response parse — which from the client's perspective looks like "server returned a 200 but the SDK chokes on the JSON." The underlying request reached PasClaw and the tool loop ran fine; the shape on the wire was the problem. Verified against github.com/openai/openai-python src/openai/types/responses/response.py: the four required fields are id, created_at, model, object, output, parallel_tool_calls, tool_choice, tools. PasClaw was emitting four of those (id, created_at, model, object, output) and missing the other three. Adding them with safe defaults: parallel_tool_calls := false tool_choice := "auto" tools := [] That alone unsticks the SDK. To future-proof against the trend toward stricter validators in the openai-python release schedule, the remaining Optional fields are also emitted as explicit `null` rather than absent keys. Pydantic treats Optional[X] = None the same for missing-or-null today, but the SDK has shipped stricter checks in the past and explicit null keeps the wire shape stable. The fields covered: error, incomplete_details, instructions, metadata, temperature, top_p, max_output_tokens, previous_response_id, reasoning, service_tier, truncation, user. `text` is emitted as `{"format": {"type": "text"}}` — the Responses API formatting config; absence has been observed to fail validation in some SDK builds. Separately fixed the failure path on RunToolLoop=false: the synthesized error object was emitting `{message, type}` (the HTTP error envelope shape) when it should be `{code, message}` — the ResponseError schema embedded inside a Response object uses `code`, not `type`. The wrapper HTTP envelope still uses `type` (and is unchanged); this fix is only on the in-Response-object error. Test plan: - openai-python client.responses.create(model=..., input="...") against a PasClaw on /v1/responses returns a Response object that round-trips through the SDK's Pydantic validator without ValidationError. - The .output_text accessor returns the model's reply text. - Streaming case unchanged: still returns the documented unsupported_streaming error. https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55a2d52b67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ErrObj.PutStr('code', 'server_error'); | ||
| ErrObj.PutStr('message', 'tool loop failed'); |
There was a problem hiding this comment.
Preserve HTTP error type on the 502 path
In the RunToolLoop failure case this response is still sent with HTTP 502, so clients such as openai-python raise a status error before casting the body to a Response; its error path extracts body.get("error", body) and populates APIError.type from the nested type field. Replacing the HTTP error shape with {code, message} makes exc.type disappear for provider/tool-loop failures, even though the normal gateway error contract elsewhere still uses {message, type}. Either keep type for this non-2xx response or return a 2xx Response object if you want the embedded ResponseError schema.
Useful? React with 👍 / 👎.
TL;DR
Your client wasn't choking on a malformed response — it was choking on missing required fields. PR #57 shipped a
/v1/responseshandler, but the response object omitted three fields the openai-python SDK's PydanticResponsemodel marks as required (no default). Pydantic raisesValidationError→ SDK throws → client says it "chokes."Verified against the SDK source
src/openai/types/responses/response.pydeclares these as required (no default value):PasClaw was emitting 5 of 8. Pydantic doesn't tolerate missing required fields, period.
What this PR ships
BuildResponsesObjectnow emits all three with safe defaults:That alone unsticks the SDK. To future-proof against the trend toward stricter validators in the openai-python release schedule, the remaining
Optionalfields are also emitted as explicitnullrather than absent keys (Pydantic treats them the same forOptional[X] = Nonetoday, but the SDK has shipped stricter checks in the past and explicit null keeps the wire shape stable):textis emitted as{"format": {"type": "text"}}— the Responses-API formatting config. Absence has been observed to fail validation in some SDK builds.Secondary fix:
ResponseErrorschema inside a Response objectThe
RunToolLoop=falsebranch was synthesizing an error as{message, type}— that's the HTTP error envelope shape (which the rest of the gateway uses correctly elsewhere). Theerrorfield embedded inside aResponseobject is a different schema:ResponseErroruses{code, message}. Fixed; the wrapper envelope on bare HTTP errors stays unchanged.Test plan
openai-python≥ 2.0 withclient.responses.create(model=..., input="hi")against PasClaw — Pydantic parse succeeds, noValidationErrorresponse.output_textreturns the model's reply textresponse.status == "completed"stream=True) still returns the documentedunsupported_streamingerror — no regression{code, message}schemaOther clients
If your client isn't
openai-python, this PR still fixes the most likely cause. JS / Go / Rust SDKs follow similar deserialization rules — three missing required fields would also have tripped them. If you're still seeing the choke after this lands, paste a sample of the failing request body + the SDK's error and I'll dig further.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code