.with_raw_response or .with_streaming_response.
with_raw_response
The.with_raw_response prefix returns an APIResponse object that provides access to the raw HTTP response while still eagerly reading the response body:
Available properties
TheAPIResponse object provides:
headers: HTTP response headersstatus_code: HTTP status codeurl: Request URLmethod: HTTP methodhttp_version: HTTP protocol versionelapsed: Time taken for the requesthttp_request: The original httpx Request objecthttp_response: The underlying httpx Response objectretries_taken: Number of retries made (0 if no retries)
Parsing the response
Call.parse() to get the typed object that the method would normally return:
with_streaming_response
The.with_streaming_response prefix allows you to stream the response body instead of reading it all at once. This requires a context manager and is useful for large responses:
Streaming methods
The streaming response provides several iteration methods:Async usage
Both features work with async clients using the same interface:Use cases
Raw responses are useful when you need:- Custom headers: Access response headers for rate limits, request IDs, etc.
- Status codes: Check specific HTTP status codes
- Retry information: See how many retries were attempted
- Memory efficiency: Stream large responses instead of loading into memory
- Progress tracking: Process streaming responses in chunks