Skip to content

feat: expose HTTP response headers on non-streaming responses#178

Draft
bborn wants to merge 1 commit intoanthropics:mainfrom
bborn:bruno/response-headers-access
Draft

feat: expose HTTP response headers on non-streaming responses#178
bborn wants to merge 1 commit intoanthropics:mainfrom
bborn:bruno/response-headers-access

Conversation

@bborn
Copy link
Copy Markdown

@bborn bborn commented Apr 14, 2026

Summary

Fixes #110

  • Adds _status and _headers accessors to BaseModel, making HTTP response metadata available on non-streaming API responses
  • Modifies base_client.rb to set these accessors after coercing the response model
  • Uses respond_to? guard so non-BaseModel return types are unaffected

This mirrors the existing pattern on streaming responses (which already expose .status and .headers via BaseStream).

Usage

response = client.messages.create(
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }]
)

response._status  #=> 200
response._headers #=> {"anthropic-ratelimit-requests-remaining" => "4", "request-id" => "req_abc123", ...}

Test plan

  • Added test/anthropic/resources/messages/response_headers_test.rb with tests for header and status access on non-streaming responses
  • Verified existing streaming tests still pass
  • Verified existing type/model tests still pass

🤖 Generated with Claude Code

Add `_status` and `_headers` accessors to BaseModel so that
non-streaming API responses expose the HTTP status code and headers
(rate limits, request IDs, etc.) — matching the existing pattern
on streaming responses.

Closes anthropics#110

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bborn bborn requested a review from a team as a code owner April 14, 2026 22:29
@bborn bborn marked this pull request as draft April 14, 2026 22:31
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.

Can't access response HTTP headers

1 participant