Skip to content

add with_raw_response to responses.parse for OpenAI and AsyncOpenAI#1351

Merged
Barrett Pyke (barrettpyke) merged 1 commit intomainfrom
barrettpyke/fix-parse-cached-metric
Feb 6, 2026
Merged

add with_raw_response to responses.parse for OpenAI and AsyncOpenAI#1351
Barrett Pyke (barrettpyke) merged 1 commit intomainfrom
barrettpyke/fix-parse-cached-metric

Conversation

@barrettpyke
Copy link
Contributor

@barrettpyke Barrett Pyke (barrettpyke) commented Feb 6, 2026

Context

If you use client.responses.parse through the AI Proxy and include the x-bt-use-cache header it's supposed to add a metric called cached that indicates the request was either a HIT or MISS. client.responses.create does this because it includes the raw response headers but client.responses.parse does not.

Description

Copied the pattern already present for create and added with_raw_response.

Steps to Reproduce:

  1. Run the following code:
init_logger(project="barrett-onboarding")

client = wrap_openai(
    AsyncOpenAI(
        base_url="https://staging-api.braintrust.dev/v1/proxy",
        api_key=os.getenv("BRAINTRUST_API_KEY"),
        default_headers={"x-bt-use-cache": "always"},
    )
)


async def main():
    resp = await client.responses.parse(
        model="gpt-5-mini-2025-08-07",
        instructions="you're a storyteller",
        input="tell me a story",
        prompt_cache_key="user",
    )


if __name__ == "__main__":
    asyncio.run(main())
  1. Navigate to the named project.
  2. Open the Logs.
  3. Open the trace that was sent.

Testing

Tested the change locally with the above repro script.

@barrettpyke Barrett Pyke (barrettpyke) merged commit 10e2d22 into main Feb 6, 2026
65 checks passed
@barrettpyke Barrett Pyke (barrettpyke) deleted the barrettpyke/fix-parse-cached-metric branch February 6, 2026 22:32
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