Skip to content

feat: return raw bytes from call_runner for non-JSON responses - #51

Open
rickstaa wants to merge 1 commit into
ja/live-runnerfrom
rs/call-runner-raw-bytes
Open

feat: return raw bytes from call_runner for non-JSON responses#51
rickstaa wants to merge 1 commit into
ja/live-runnerfrom
rs/call-runner-raw-bytes

Conversation

@rickstaa

@rickstaa rickstaa commented Jul 29, 2026

Copy link
Copy Markdown
Member

Closes the last gap after #25: the buffered call_runner path required every response to be a JSON object, so binary-returning apps (an image, say — the hf-inference text-to-image API returns raw image/jpeg bytes) forced a base64-in-JSON shim into every runner and client. Streaming already handled bytes (stream=Trueaiter_bytes()); this brings the buffered path to parity, mirroring the familiar requests model (r.json() / r.content vs iter_content).

What

  • http.request_data() — same request semantics and error mapping as request_json, but returns (body_bytes, content_type) without assuming JSON. request_json is now a thin wrapper over it (fetch + parse), behavior unchanged.
  • call_runner (non-stream): JSON content types parse into result.data exactly as before (including the strict object check and session_id pickup). Any other content type returns result.raw (bytes) + result.content_type instead of raising "expected JSON object".
  • LiveRunnerCallResult: new optional raw and content_type fields; content_type is also set on JSON results.
  • Payment path untouched: the 402 challenge raises on status before any body handling, so paid calls work identically for JSON and binary responses.

Compatibility

Strictly additive: every response that succeeded before behaves identically. The only changed case is one that previously raised — a non-JSON content type — which now succeeds with bytes. One edge note: a server returning JSON with a non-JSON content type (e.g. bare text/plain) now lands in raw instead of being parsed; aiohttp's json_response (what the examples use) always sets application/json.

Why

With this, a runner that fronts a bytes-returning API needs no transform at all — the example-apps api-proxy can drop its base64 envelope, and a runner can literally be a stock nginx proxy_pass (See livepeer/runner-app-examples#45).

Tested

tests/test_call_runner_raw.py (5 cases against a live aiohttp server): JSON unchanged incl. session_id, binary → raw + content_type, invalid JSON with JSON content type still raises, JSON array still rejected, HTTP errors still raise. Full suite passes (14).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed72cebc-560d-4b89-befe-2049936651fb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant