Skip to content

/v1/responses: emit fields the openai-python SDK marks required - #61

Merged
FMXExpress merged 1 commit into
mainfrom
claude/pr61-responses-required-fields
May 28, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/pr61-responses-required-fields

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

TL;DR

Your client wasn't choking on a malformed response — it was choking on missing required fields. PR #57 shipped a /v1/responses handler, but the response object omitted three fields the openai-python SDK's Pydantic Response model marks as required (no default). Pydantic raises ValidationError → SDK throws → client says it "chokes."

Verified against the SDK source

src/openai/types/responses/response.py declares these as required (no default value):

id, created_at, model, object, output,
parallel_tool_calls : bool          ← missing in PR #57
tool_choice         : ToolChoice    ← missing in PR #57
tools               : List[Tool]    ← missing in PR #57

PasClaw was emitting 5 of 8. Pydantic doesn't tolerate missing required fields, period.

What this PR ships

BuildResponsesObject now emits all three 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 them the same for Optional[X] = None today, but the SDK has shipped stricter checks in the past and explicit null keeps the wire shape stable):

"error": null, "incomplete_details": null, "instructions": null,
"metadata": null, "temperature": null, "top_p": null,
"max_output_tokens": null, "previous_response_id": null,
"reasoning": null, "service_tier": null, "truncation": null, "user": null

text is emitted as {"format": {"type": "text"}} — the Responses-API formatting config. Absence has been observed to fail validation in some SDK builds.

Secondary fix: ResponseError schema inside a Response object

The RunToolLoop=false branch was synthesizing an error as {message, type} — that's the HTTP error envelope shape (which the rest of the gateway uses correctly elsewhere). The error field embedded inside a Response object is a different schema: ResponseError uses {code, message}. Fixed; the wrapper envelope on bare HTTP errors stays unchanged.

- ErrObj.PutStr('message', 'tool loop failed');
- ErrObj.PutStr('type',    'server_error');
+ ErrObj.PutStr('code',    'server_error');
+ ErrObj.PutStr('message', 'tool loop failed');

Test plan

  • openai-python ≥ 2.0 with client.responses.create(model=..., input="hi") against PasClaw — Pydantic parse succeeds, no ValidationError
  • response.output_text returns the model's reply text
  • response.status == "completed"
  • Streaming request (stream=True) still returns the documented unsupported_streaming error — no regression
  • Failure path (kill provider mid-request) returns a 502 with the embedded ResponseError now matching {code, message} schema

Other 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

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
@FMXExpress
FMXExpress merged commit 850c56e into main May 28, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1344 to 1345
ErrObj.PutStr('code', 'server_error');
ErrObj.PutStr('message', 'tool loop failed');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants