Raise a gave-up transport status from OpenAI and Cohere embeddings, OpenAI image generation and `GoogleModel` batch methods as `ModelHTTPError`
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Closes #13313
Why we make these changes
A retrying transport re-raises HTTPStatusError for the status it gave up on, and openai, cohere and google.genai let it through unwrapped. The chat model classes map it since #11934, and #13312 does the same for Google embeddings, image generation and count_tokens. Four more call sites let the raw exception escape, which contradicts docs/embeddings.md and docs/image-generation.md:
| Call site | Before | After |
|---|---|---|
OpenAIEmbeddingModel.embed | raw httpx2.HTTPStatusError | categorized ModelHTTPError |
OpenAIImageGenerationModel.generate (images.generate and images.edit) | raw httpx2.HTTPStatusError | categorized ModelHTTPError |
CohereEmbeddingModel.embed / count_tokens | raw httpx.HTTPStatusError | categorized ModelHTTPError |
GoogleModel.batch_create / batch_status / batch_results / batch_cancel | raw httpx2.HTTPStatusError | categorized ModelHTTPError, with Gemini's RetryInfo wait |
Each arm copies an existing one: models/openai/_errors.py::map_api_errors for OpenAI, models/cohere.py::_map_api_errors for Cohere (cohere takes a legacy httpx client), and models/google.py::_map_api_error's branch for the batch methods.
The batch input-file deletes are best effort, but a gave-up status on one escaped: on Google and OpenAI it aborted batch_results for a batch that succeeded, and on a refused batch_create it replaced the refusal. The deletes now suppress it, as they already suppress connection errors.
[!WARNING]
Compatibility impact: Existing code that catches a raw httpx2.HTTPStatusError (or, from Cohere embeddings, httpx.HTTPStatusError) from any of the call sites above will no longer catch it. It is now raised as a ModelHTTPError with its error category, with the httpx/httpx2 exception as its __cause__. A gave-up status on a batch input-file delete no longer raises at all.
Why this can ship in a minor release: It fixes a bug. docs/embeddings.md and docs/image-generation.md document ModelAPIError subclasses for these failures, and chat model requests already raise them, so the raw exceptions were undocumented. except ModelAPIError and the error categories are unaffected.
Migration: Catch ModelHTTPError or an error category such as ModelRateLimitError, or ModelAPIError for all of them.
New public surface
None.
User-visible behavior
model = OpenAIEmbeddingModel('text-embedding-3-small', provider=provider)
await model.embed(['hi'], input_type='query') # the transport gave up on a 429 with `Retry-After: 7`
# before: httpx2.HTTPStatusError
# after: ModelRateLimitError (a ModelHTTPError) with status_code=429, retry_after=7.0
[!NOTE]
Deliberate scope: with a validate_response that rejects every 4xx, an OpenAI image moderation_blocked 400 raises ModelRequestRejectedError, not the ContentFilterError the SDK-seen path raises. The transport closes the rejected response unread (#13315), so the error code isn't readable here. Tracked in #13330.
Verification
Each test below fails on main and passes here; for the same statuses seen by the SDK, and for each provider's chat model, outputs are byte-identical to main. No recording: the transport raises HTTPStatusError itself, so there is no response to record.
- Embeddings:
openai-transport-gave-upandcohere-transport-gave-upcases,test_cohere_count_tokens_transport_gave_up - Image generation:
test_openai_image_generation_gave_up_status_error(generateandedit) - Google batch:
test_gemini_batch_status_the_transport_gave_up_on(all four methods),transport-gave-updelete case,test_gemini_refused_job_raises_its_refusal_when_deleting_its_input_file_fails - OpenAI batch:
transport-gave-updelete case,test_a_refused_batch_raises_its_refusal_when_deleting_its_input_file_fails
What changes for existing users
A status a retrying transport gave up on now raises the documented ModelHTTPError category from these call sites, and no longer aborts a batch's best-effort input-file delete; every other input behaves as before.
Follow-ups, out of scope here: #13328 (batch_create leaves its input file after a gave-up 4xx), #13329 (OpenAI image generation's SDK-seen status error is uncategorized, the counterpart of #13314), #13330 (the moderation gap above), #13349 (a gave-up long-decode continuation request in GoogleModel.request_stream, reported by @v0ropaev).
PR decisions
2026-11-13 · fix shape: copy the existing gave-up arms · iter -
- Decision: OpenAI embeddings/images and Cohere use _model_errors.transport_status_error as models/openai/_errors.py::map_api_errors and models/cohere.py::_map_api_errors do; Google adds httpx2.HTTPStatusError to models/google.py::_map_api_errors, reaching _map_api_error's branch with google_retry_after
- Why: Manager-settled; validator applied exactly these arms to a copy: every leak became the categorized error, controls and SDK-seen outputs byte-identical to main
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · fold: best-effort input-file delete tolerates a gave-up status (D2) · iter -
- Decision: Add httpx2.HTTPStatusError to both _google_batch.py delete suppress tuples (batch_results, batch_create), failing test first next to test_gemini_batch_results_survive_failing_to_delete_the_input_file
- Why: A gave-up status on the delete aborts batch_results for a job that succeeded (validator repro B)
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · fold: OpenAI batch delete gap reproduced · iter -
- Decision: models/openai/_batch.py suppress(APIError) misses a gave-up httpx2.HTTPStatusError; reproduced (local-notes/readiness/repro_openai_batch_delete.py: delete gives up with 503 -> batch_results raises ModelUnavailableError; connect error on the delete -> results returned), so it folds
- Why: Manager rule: reproduce first, fold only if it reproduces
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · split: batch_create input file after gave-up 4xx + OpenAI image SDK-seen arm uncategorized · iter -
- Decision: File two follow-ups via /file-followup-issue after the PR opens, no routing labels, no assignee: (1) batch_create leaves the uploaded file after a gave-up 4xx (repro C), deleting is a design question; (2) OpenAI image APIStatusError arm builds an uncategorized ModelHTTPError, OpenAI counterpart of #13314
- Why: Manager-settled split; manager routes them
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · sequencing with #13312 · iter -
- Decision: Start from main; do not open the PR until https://github.com/pydantic/pydantic-ai/pull/13312 merges; then merge upstream/main and reuse its _gave_up helper (add an httpx variant for Cohere) instead of a second helper
- Why: Same family, overlapping test helper and models/google.py
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · tests: placement and no recording · iter -
- Decision: Embeddings as Case rows in tests/test_embeddings_error_categories.py; OpenAI images next to tests/test_images.py::test_openai_image_edit_status_error; batch in tests/models/test_google_batch.py; docstrings say no recording because the transport raises, so there is no response to record
- Why: Manager-settled
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · D1 deliberator: deployed agent unavailable · iter -
- Decision: The manager-only deliberator agent is not deployed in this worktree; dispatched a fresh opus general-purpose agent instructed to follow /home/agent/pydantic/ai/manager/.claude/agents/deliberator.md verbatim
- Why: Closest faithful substitute; reported to the manager
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · D1 verdict: OpenAI image gave-up arm copies the arm verbatim (Option A) · iter -
- Decision: images/openai.py gets the plain transport_status_error arm; a gave-up moderation_blocked 400 raises ModelRequestRejectedError, not ContentFilterError; no test pins moderation_blocked -> ModelRequestRejectedError
- Why: Deliberator DECIDE: AsyncHTTPX2TenacityTransport closes the rejected response unread (issue 13315), so over a real socket the body is None and a moderation_blocked match could never fire; all 7 sibling gave-up arms categorize by status only, incl. Azure content_filter in _chat_model.py; PR 11934 set that shape
- Source: https://github.com/pydantic/pydantic-ai/pull/11934 https://github.com/pydantic/pydantic-ai/issues/13315
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · D1 accepted; third follow-up approved · iter -
- Decision: Manager accepted D1 Option A. After the PR opens, file three follow-ups via /file-followup-issue with no assignee and no labels (manager routes all three): repro C cleanup, OpenAI image SDK-seen arm uncategorized, OpenAI image moderation_blocked behind a 4xx-rejecting transport (blocked by 13315). PR body keeps one deliberate-scope line on the moderation gap
- Why: Manager reply to the D1 report (local-notes/dispatch-20261113T003144Z.md)
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · repro C wording: transport's own retry · iter -
- Decision: The follow-up says the second batchGenerateContent send is the retrying transport's own retry, which the SDK's retry_options attempts=1 can't reach; OpenAI batch_create's with_options(max_retries=0) has the same shape by code reading only
- Why: Repro C sets stop_after_attempt(2) on the transport; manager agreed with the pushback
- Source: https://github.com/pydantic/pydantic-ai/issues/13313
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · pre-push review 1 of 3 at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f · iter -
- Decision: reserved; dispatching (haiku, claude -p from detached policy-base checkout 75ef1a9bd, read-only tools, no fan-out)
- Why: tree 2fd0f4559caa8bf3235c798188a0bc5cd786e9f5; scope 75ef1a9bd..4ce9517f1 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/gave-up-status-siblings
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · compatibility impact label and warning · iter -
- Decision: Apply the compatibility impact label and a [!WARNING] section (impact, why minor, migration), as https://github.com/pydantic/pydantic-ai/pull/13312 does for the same change class
- Why: agent_docs/api-design.md: 'Treat previously valid user code that now needs modification as a compatibility impact'; code catching the raw httpx/httpx2 HTTPStatusError no longer catches it
- Source: https://github.com/pydantic/pydantic-ai/pull/13312
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · pre-push review 1 of 3 at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f · iter -
- Decision: no findings: fresh haiku reviewer returned current at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f
- Why: reviewed tree 2fd0f4559caa8bf3235c798188a0bc5cd786e9f5; full branch scope 75ef1a9bd..4ce9517f1; headless claude -p in detached policy-base 75ef1a9bd, read-only tools, no fan-out
- Source: https://github.com/pydantic/pydantic-ai/tree/gave-up-status-siblings
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · defer: batch_create input file after a gave-up 4xx · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/13328 instead of fixing here; no assignee, no labels (manager routes)
- Why: Out of scope for this PR — own design decision: an earlier attempt may have created the job
- Source: https://github.com/pydantic/pydantic-ai/issues/13328
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · defer: OpenAI image SDK-seen status error uncategorized · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/13329 instead of fixing here; no assignee, no labels (manager routes)
- Why: Out of scope for this PR — changes the class raised for inputs that already raise ModelHTTPError on main
- Source: https://github.com/pydantic/pydantic-ai/issues/13329
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · defer: OpenAI image moderation_blocked behind a 4xx-rejecting transport · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/13330 instead of fixing here, blocked by 13315; no assignee, no labels (manager routes)
- Why: Out of scope for this PR — depends on the shared transport fix in 13315
- Source: https://github.com/pydantic/pydantic-ai/issues/13330
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · douwebot applied at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f · iter -
- Decision: Applied the douwebot label after CI (run 43345966808) and PR Review Checks succeeded on the head
- Why: Merge bar for size: M needs a clean douwebot approval; diff touches no guarded path
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · douwebot optional body finding: defer to #13328 · iter -
- Decision: douwebot APPROVED 4ce9517f1 with one Optional finding in the review body (batch_create skips the cleanup on a gave-up status); deferred to https://github.com/pydantic/pydantic-ai/issues/13328 with a PR reply and a pointer on the issue; gate reads failure 'Douwebot has discussion findings on this head.'
- Why: Manager split: deleting on a gave-up 4xx is a design question (an earlier attempt may have created the job); review_gates.py blocks any review-body finding, resolved or not, so the gate needs a manager decision
- Source: https://github.com/pydantic/pydantic-ai/pull/13327#issuecomment-6842215881
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · gate gap filed: douwebot body finding blocks the clean-approval gate · iter -
- Decision: Filed https://github.com/pydantic/pydantic-ai/issues/13337 (immediate route: assignee dsfaccini, label pydanty:skip) with #13327 at 4ce9517f1 as the example; pointer on PR 13099; enqueue held for David's gate waiver
- Why: review_gates.py::douwebot_approval fails any APPROVED body != APPROVAL_BODY; publish_douwebot_review.py moved the out-of-diff Optional finding into the body after an HTTP 422 (run 43352226317 log)
- Source: https://github.com/pydantic/pydantic-ai/issues/13337
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · step-7 second opinion: pydanty:review-lite · iter -
- Decision: David picked pydanty:review-lite as the additional review surface for #13327
- Why: Manager relay of David's pick (local-notes/dispatch-20261113T024527Z.md); same surface #13312 got
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · pydanty review-lite triage at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f · iter -
- Decision: Both required actions declined, no push: (1) 3xx APIStatusError branch in images/openai.py is pre-existing (b84a7c9149, lax no cover like embeddings/openai.py), outside 13313 scope; (2) uname -p ResourceWarning in test_openai_batch.py reproduces with main's versions of all changed files, tracked in 12444 (_batch_group reads client.default_headers). Reply posted, 👎 reacted, pointer on 12444, pydanty CHANGES_REQUESTED 5885549534 dismissed via the tracked helper
- Why: Root AGENTS.md scope rule; pushing-commits step 2: a flake not caused by this PR is cited by its issue, fixed here only with a claim and in scope; CI run 43345966808 passed on the head
- Source: https://github.com/pydantic/pydantic-ai/pull/13327#issuecomment-6843025987
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · final metadata check at 4ce9517f14a9d63c6ec7dfef257fb806ad96600f · iter -
- Decision: current: fresh haiku checker (policy base db141af6d) confirmed title, labels, attribution, closing line, template sections and decisions mirror; its 4 corrections (bare #N to full URLs) dropped
- Why: Each cited only a local session memory, not a rule in pushing-commits-to-the-repo, root AGENTS.md or the PR template (skill 'Before handing the PR back' step 5); GitHub links #N in PR bodies
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · fold: 5th gave-up site, GeminiStreamedResponse._get_event_iterator · iter -
- Decision: Add httpx2.HTTPStatusError to the except tuple in models/google.py::GeminiStreamedResponse._get_event_iterator so a long-decode continuation hop the retrying transport gave up on maps through _map_api_error; streaming test first; credit v0ropaev for report and repro
- Why: Manager fold under the pr-orchestrator fold bar: same root cause, same fix shape, changes output only for inputs that already fail, PR not at the merge bar
- Source: https://github.com/pydantic/pydantic-ai/issues/13313#issuecomment-6843505850
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · adversarial verification of the fold at f6882ab75 · iter -
- Decision: Fresh opus agent following the adversarial-verifier definition (no such agent type in this worktree): 1 counterexample. FallbackModel or ModelFallback with fallback_on naming httpx2.HTTPStatusError, and a first long-decode request with no events, falls back on main and fails with ModelRateLimitError on f6882ab75 (reproduced). Control: a first streamed request that gives up already maps and doesn't fall back on main (reproduced). Push held for the manager
- Why: Contradicts part of the fold bar's premise 'changes output only for inputs that already fail'; same class as the PR's declared compatibility impact
- Source: https://github.com/pydantic/pydantic-ai/issues/13313#issuecomment-6843505850
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · split, not fold: 5th gave-up site · iter -
- Decision: Drop f6882ab75 (never pushed; head stays 4ce9517f1) and file GeminiStreamedResponse._get_event_iterator as its own follow-up, no labels, no assignee; reply once to v0ropaev; pointer on #13327
- Why: Manager reversal: the verifier's fallback_on=(httpx2.HTTPStatusError,) counterexample fails the fold bar's third condition, 'changes output only for inputs that already fail on main', so the fold rule says split
- Source: https://github.com/pydantic/pydantic-ai/issues/13313#issuecomment-6843505850
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
- Supersedes: fold: 5th gave-up site, GeminiStreamedResponse._get_event_iterator
2026-11-13 · defer: long-decode stream continuation site · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/13349 instead of fixing here; no labels, no assignee (manager routes); credited v0ropaev; reply https://github.com/pydantic/pydantic-ai/issues/13313#issuecomment-6847543678; pointer https://github.com/pydantic/pydantic-ai/pull/13327#issuecomment-6847544186
- Why: Out of scope for this PR — the fix changes the outcome of a fallback_on=(httpx2.HTTPStatusError,) setup that works on main; open decision recorded in the issue
- Source: https://github.com/pydantic/pydantic-ai/issues/13349
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · gate: merge main and re-run douwebot, no waiver · iter -
- Decision: David picked (b) merge main and re-run douwebot, no waiver, on 2026-11-13
- Why: Standing rule from David: never waive the douwebot gate; when it fails, push the fix and re-run douwebot
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · exempt delta: main merge at 29748823f54afb2b3328555bfe13ee8cea044eb7 · iter -
- Decision: No pre-push review dispatch (budget 1 of 3 used): target-branch merge of upstream/main 357ca4ec4 with no conflict resolution, chained from reviewed SHA 4ce9517f14a9d63c6ec7dfef257fb806ad96600f
- Why: git diff main...4ce9517f1 and git diff main...HEAD carry identical added/removed lines (only blob index hashes and one hunk offset in tests/test_images.py differ, from #13356/#13335 touching the same files elsewhere); targeted tests over the touched files plus test_long_decode.py pass; pyright 0 errors; no pyproject/uv.lock change
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · douwebot applied at 29748823f54afb2b3328555bfe13ee8cea044eb7 · iter -
- Decision: Applied the douwebot label after CI (run 43485048384) and PR Review Checks succeeded on the merged head
- Why: David's pick (b): merge main and re-run douwebot, no waiver
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · douwebot approval at 29748823f54afb2b3328555bfe13ee8cea044eb7 · iter -
- Decision: douwebot APPROVED (review 5896545218, run 43488463303) with a clean body and one inline Optional finding on test_gemini_refused_job_raises_its_refusal_when_deleting_its_input_file_fails; skipped as net-neutral, replied with evidence, 👎, thread resolved; no push
- Why: test_gemini_refused_job_deletes_its_input_file[refused] already asserts the refused job's delete runs; the flagged test fails on main; a push restarts CI/PRC/douwebot for no added coverage (manager: don't push just to clear such a nit)
- Source: https://github.com/pydantic/pydantic-ai/pull/13327#discussion_r4567465274
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · merge bar met at 29748823f54afb2b3328555bfe13ee8cea044eb7 · iter -
- Decision: CI run 43485048384 success, PR Review Checks success, Gate: clean douwebot approval success (19:09:11Z, after a PR body edit re-triggered PR Review Gates per #13322), 0 unresolved threads, mergeStateStatus CLEAN; enqueue is the manager's
- Why: pushing-commits-to-the-repo Merge bar for size: M
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
2026-11-13 · manager enqueued #13327 · iter -
- Decision: Manager enqueued #13327 at 2026-11-13T19:11:22Z on head 29748823f54afb2b3328555bfe13ee8cea044eb7; the re-enqueue is the manager's
- Why: Manager relay; pushing-commits 'Who merges': a maintainer enqueues at the merge bar
- Source: https://github.com/pydantic/pydantic-ai/pull/13327
- Session: f11a33e0-9f19-4f84-a466-194d8c19ab2e
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.