litellm/tests/integration/routing
mika-lt c74b785396
fix(router,files,batches)!: never resend a file or batch create the provider may already have (#51315)
* fix(files,batches): never resend a timed-out file or batch create

A file upload or batch create that hit the caller's timeout was sent again by the OpenAI SDK's retries and then by the router's retries and same-group fallbacks, so Azure and OpenAI kept up to 3 billed copies the caller never heard about. Creates now go out with SDK retries off, and the router re-raises a timed-out create instead of retrying or falling back

* fix(router): stop resending a create that times out on a retry or a fallback

A file or batch create that timed out after it was sent is no longer retried
or sent to the next order fallback, wherever the timeout happens. A connect
or pool timeout means the request never left LiteLLM, so it is still retried
and sent to a fallback like a connection error

* fix(files,batches): resend a create only when a resend cannot make a duplicate

File and batch creates sent without the router lost every SDK retry on this branch. They now go out with SDK retries off, and LiteLLM resends them itself only when a resend cannot create a second object. That is when the provider answered with a status the SDK would retry (x-should-retry wins, else 408, 409, 429 or 5xx), or when the request never left (a connect error, connect timeout or pool timeout). The budget is the client's own max_retries, and the wait comes from calculate_retry_after. The router uses the same "timed out after send" check, so the two layers cannot disagree

The httpx handler now chains the httpx error as the cause of litellm.Timeout, so a connect timeout on an Anthropic, Bedrock, Mistral or xAI upload is retried again like on main. A timed-out create through a model group keeps the "No fallback was attempted" note, and the router logs one info line when it stops

The proxy create-file and create-batch routes add x-should-retry false to a create that timed out after it was sent, so OpenAI and Anthropic SDK callers do not resend it. Status and body stay the same

Uploading a file to every deployment now waits for all of them and raises the after-send timeout when there is one, so a fast 429 from one deployment can no longer hide it and trigger a resend to the slow one

Tests cover the resend rules for sync and async on OpenAI and Azure, the Anthropic upload retries, the fallback note and log, the proxy header, the multi-deployment upload, and the aiohttp timeout classes

* fix(router,files,batches)!: do not resend a create the provider may already have made

A file or batch create is no longer resent by the SDK, the router's retries, or a router fallback when the provider may already have it. That covers a timeout after the request was sent, a connection that dropped after it was sent, a 504, and any answer that says x-should-retry: false. Creates on the httpx handler (Mistral and Bedrock batches, Gemini, Vertex AI and Manus uploads) now keep the transport error as the cause of the provider error, so the router sees the timeout too

A create that cannot have made anything is still resent, and a proxy write timeout or a refused egress proxy now count as that. A real 408 answer, 500, 502 and 503 keep the same handling as before

The proxy create-file and create-batch routes answer such a failure with x-should-retry: false and add a sentence to the error message that tells the caller to list their files or batches before they send it again

BREAKING CHANGE: a 504 on a file or batch create is no longer resent by the SDK or retried by the router unless the answer says x-should-retry: true

* fix(router,files,batches): keep retries and fallbacks after a create the provider rejected

Anthropic sends x-should-retry: false on every 4xx, so a model group upload with a bad key on its
first deployment stopped there with a 401 and a note saying the file may already exist. A 4xx other
than 408 now counts as nothing created, whatever the header says, so the router retries and falls
back the way it did before and the proxy adds no note or header to it

* fix(files,batches): number each resent create and keep stream timeouts as litellm.Timeout

Each resend of a file or batch create now carries its attempt number in
x-stainless-retry-count and keeps the caller's extra headers, the way the
SDK numbered its own resends. The httpx handler's timeout keeps base's
shape, so a Gemini stream that times out at open still raises
litellm.Timeout, and the create check follows the timeout's context to the
httpx error instead. A proxy integration test counts upstream POSTs for a
timed-out /v1/files and /v1/batches create on the default transport.

* fix(files,batches): stop resending a group upload that one deployment already created

A group upload where some deployments created the file and another failed now counts as a create that may exist, so the router does not resend it and the caller gets the notice. A failed GET never counts as may exist, and a write error or a local protocol error is resent, since the body never fully arrived. The notice now says to check the newest files or batches

* fix(router): keep the provider error when a group upload partly fails

A group upload where some deployments created the file and another failed now raises the failing deployment's own error, with a marker in its cause chain that says the file may exist. The caller gets the provider's message and the router's note again, instead of a generic error that showed the deployment's URL

* fix(router): keep the no-fallback note on every provider error from a create that may exist

A group upload that one Anthropic, Vertex AI, Gemini or Manus deployment rejected lost the router's note, since the note was added only to OpenAI errors

* fix(router): leave out the no-fallback note when a create stops after an order fallback

A create that fails at a later order level after an earlier level fell back now ends without
the "No fallback was attempted" note, since a fallback did run. The proxy's notice that the
provider may already hold the file or batch still comes through

* test: allowlist the bounded _cause_chain recursion in the recursion detector

* fix(router): keep retrying a create whose retry never connected, and keep the caller's create headers

The router's retry loop overwrote a retry error's __context__ with the hop's first error, which dropped the httpx ConnectTimeout behind an http-handler litellm.Timeout. The second attempt then read as a create that may already exist, so an Anthropic upload that never connected stopped retrying and skipped a healthy order fallback. The first error now goes at the end of the context chain

A create's extra_headers sent as a list are passed through unchanged again instead of being dropped, and a caller's own retry-count header in any case is no longer sent next to ours

Also applies cargo fmt to call.rs for the rust-lint job

* fix(files): treat a failed read as no create, whatever error wraps it

A GET that failed with an openai.APIStatusError no longer counts as a create that may already exist, so reads stay retryable. Tests now record the resend wait instead of timing it, and the duplicate Anthropic file fixture is gone

* fix(router,files): keep a create that may exist after a redirect or a fallback from being sent again

A gateway that takes an upload, answers 303 and fails the followed GET with a 504 now counts as a create that may exist, since the check reads the request the redirect started from

A fallbacks hop whose create may exist now ends the walk and is the error the caller gets, and a weighted failover whose create may exist skips the regular fallbacks

* test(router): mark the create-may-exist fallback tests with rstest

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 07:20:51 +00:00
..
_prompt_cache_pin_support.py fix(router): keep the prompt caching affinity pin alive as long as the prefix's cache_control ttl (#46084) 2026-10-14 21:10:09 -07:00
_reasoning_effort_levels_support.py test(routing): audit #46601 (#48910) 2026-10-28 15:42:51 -07:00
either_role.json test(integration): add read-replica routing harness to the CircleCI integration suite (#42692) 2026-09-24 00:25:03 -07:00
test_advisor_failure_cooldown.py test(integration): regression tests for July provider translation, routing and streaming bugs (#42693) 2026-09-23 09:51:06 -07:00
test_anthropic_overloaded_cooldown_owned_proxy.py fix(anthropic): answer an upstream Anthropic 529 as 529 overloaded_error on /v1/messages (#46063) 2026-11-03 17:37:09 -08:00
test_audit_any_sweep_chaos.py test(integration): give chaos and timing tests a harness API and gate raw signals (#46031) 2026-10-12 05:27:33 -07:00
test_auto_router_management.py test(auto_router): verify total_spend in session integration responses (#51283) 2026-11-16 12:11:26 -08:00
test_azure_passthrough_spend_row.py fix(vllm): write spend log rows for /vllm passthrough calls to router models (#45733) 2026-10-14 12:40:48 -07:00
test_base_model_context_window_owned_proxy.py fix(router): count pre-call context-window tokens with each deployment's tokenizer (#49764) 2026-11-25 03:04:19 +00:00
test_batch_mode_deployments_wire.py fix(router): send managed batch uploads to batch deployments when a chat deployment has a lower order (#50971) 2026-11-10 18:35:19 -08:00
test_caller_credential_failure_cooldown.py fix(router): keep one caller's own bad credential from cooling down a shared deployment (#53431) 2026-11-21 17:09:29 -08:00
test_comma_separated_models_stream.py fix(proxy): reject comma-separated models with stream=true as 400 (#52264) 2026-11-17 13:29:32 -08:00
test_complexity_router_codex_compaction.py fix(complexity_router): keep the held user_turn route for Codex compaction requests (#48627) 2026-10-27 13:33:32 -07:00
test_complexity_router_databricks_classifier.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_complexity_router_llm_classifier.py refactor(types): replace Any with proven types in 7 files (#43844) 2026-10-02 02:47:47 -07:00
test_create_timeout_sends_once_wire.py fix(router,files,batches)!: never resend a file or batch create the provider may already have (#51315) 2026-11-25 07:20:51 +00:00
test_customer_org_and_key_model_limits_borrow_idle_capacity.py feat(dynamic_rate_limiter): customer organizations and keys borrow idle model capacity and split class shares (#51705) 2026-11-15 12:05:58 -08:00
test_declared_provider_bare_model_routes.py test(integration): hand every harness server a port from one per-worker block (#46761) 2026-10-15 16:56:40 -07:00
test_deployment_mode_routing_wire.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_deployment_num_retries_generic_routes_wire.py fix(router): retry a /v1/messages stream the provider drops before the first content chunk (#44276) 2026-10-05 22:53:39 +00:00
test_dynamic_limiter_prometheus_metrics_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_dynamic_rate_limiter_borrower_regains_share_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_encrypted_content_affinity_no_peer.py fix(router): serve Responses turns from a sibling when the encrypted content origin has no boundary peer (#43015) 2026-09-24 17:31:43 -07:00
test_end_user_region_routing.py fix(router): drop the deployment rpm filter from enable_pre_call_checks (#48873) 2026-10-28 12:13:56 -07:00
test_enforce_model_rate_limits_daily_limits.py feat(router): add deployment rpd and tpd daily limits to enforce_model_rate_limits (#48875) 2026-10-28 15:52:44 -07:00
test_fallback_hop_foreign_encrypted_reasoning.py fix(router): keep encrypted reasoning when a fallback hops between same-key deployments with no api_base (#49396) 2026-11-02 05:47:04 -08:00
test_fallback_on_gemini_malformed_empty_response.py fix(vertex_ai): fail Gemini malformed replies with no output so retries and fallbacks run (#53231) 2026-11-21 09:49:27 -08:00
test_fallback_on_saturation.py feat(proxy): router_settings.fallback_on_saturation walks key and team fallbacks before a model saturates, replacing team model_preferences (#51439) 2026-11-13 05:57:18 +00:00
test_fallback_rate_limit_check.py fix(router): re-check and reserve per-model rate limits on fallback targets (#50994) 2026-11-10 16:36:10 -08:00
test_fallback_retry_header_contracts.py test: move 76 live top-level tests to offline unit and integration coverage (#45352) 2026-10-08 10:33:35 -07:00
test_fallback_settles_serving_model.py fix(rate-limit): settle a fallback's tokens on the model group that served it (#51082) 2026-11-10 18:36:55 -08:00
test_include_fallback_errors_wire.py fix(proxy): send the streamed Responses fallback metadata as a typed Responses event (#50804) 2026-11-10 21:29:32 +00:00
test_key_max_parallel_requests.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_key_router_settings_image_generation.py test(images): include cache and SVG fields in image routing fixture (#52898) 2026-11-19 18:37:10 +00:00
test_key_tpm_reservation.py test(integration): regression tests for July provider translation, routing and streaming bugs (#42693) 2026-09-23 09:51:06 -07:00
test_least_busy_concurrent_decisions.py fix(least-busy): reserve the picked deployment so a burst of requests spreads out (#47484) 2026-11-05 00:30:12 +00:00
test_least_busy_concurrent_vertex_passthrough.py fix(proxy): reserve least-busy picks on Vertex pass-through calls (#53588) 2026-11-23 04:21:20 +00:00
test_messages_stream_retry_budget_sources_owned_proxy.py fix(anthropic): answer an upstream Anthropic 529 as 529 overloaded_error on /v1/messages (#46063) 2026-11-03 17:37:09 -08:00
test_model_capability_flags.py fix: keep model capability flags out of provider requests (#46647) 2026-10-15 14:30:10 +00:00
test_non_chat_model_endpoint_gate.py feat(router): opt in to non-chat deployment filtering (#46257) 2026-10-29 08:33:36 -07:00
test_observed_routing.py test(routing): expect the relayed provider code on context window errors (#54111) 2026-11-24 08:21:22 +00:00
test_openrouter_catalog_limits_wire.py fix(openrouter): report the context window and output cap from OpenRouter's catalog (#54046) 2026-11-24 04:37:30 -08:00
test_otpm_default_reservation_fraction.py test(routing): wait for the held stream itself before sending the requests beside it (#53519) 2026-11-22 02:56:41 +00:00
test_payment_required_cooldown.py fix(router): keep a lone deployment warm under router allowed_fails unless the policy names the exception (#48644) 2026-10-27 15:12:53 -07:00
test_payment_required_mapping.py fix(exceptions): map upstream 402 to PaymentRequiredError and cool down 402 deployments (#44879) 2026-10-06 20:35:13 -07:00
test_pdf_document_pre_call_checks_owned_proxy.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_per_model_rate_limit_fallbacks.py test(integration): give chaos and timing tests a harness API and gate raw signals (#46031) 2026-10-12 05:27:33 -07:00
test_per_model_rate_limit_fallbacks_lifecycle.py test(integration): give chaos and timing tests a harness API and gate raw signals (#46031) 2026-10-12 05:27:33 -07:00
test_pre_call_response_format_filter.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_priority_class_share_light_team_not_starved.py fix(dynamic_rate_limiter): charge tokens used while the model was idle against a team's class share (#51952) 2026-11-15 16:49:47 -08:00
test_priority_class_share_splits_among_active_teams.py feat(dynamic_rate_limiter): customer organizations and keys borrow idle model capacity and split class shares (#51705) 2026-11-15 12:05:58 -08:00
test_priority_model_tpm_enforcement.py test(integration): regression tests for July provider translation, routing and streaming bugs (#42693) 2026-09-23 09:51:06 -07:00
test_priority_rate_limit_headers.py fix(dynamic_rate_limiter): keep counting and reporting priority requests after a priority pool's tokens run out (#52081) 2026-11-16 22:00:36 +00:00
test_priority_scheduler_queue_cleanup.py test(router): audit #47498 (#48799) 2026-10-28 04:36:50 -07:00
test_prompt_cache_pin_memory_routes.py fix(router): keep the prompt caching affinity pin alive as long as the prefix's cache_control ttl (#46084) 2026-10-14 21:10:09 -07:00
test_prompt_cache_pin_ttl.py test(routing): expect /v1/responses to pin the served deployment for an hour after #50321 (#50474) 2026-11-07 00:08:05 +00:00
test_prompt_cache_pin_ttl_chaos.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_prompt_cache_pin_with_message_logging_off.py fix(router): write the prompt caching pin when turn_off_message_logging is on (#50276) 2026-11-05 15:59:57 -08:00
test_prompt_caching_affinity_tool_call_marks.py fix(router): pin /v1/responses requests for prompt caching affinity (#50321) 2026-11-06 12:56:54 -08:00
test_ptu_shares.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_ptu_shares_regex_timing.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_rate_limit_fallback_headers.py fix(proxy): check pre-call fallback access with the saved model_group_alias, never the one the client sent (#52077) 2026-11-16 22:02:42 +00:00
test_realtime_turn_limits_redis_real_io.py fix(realtime): enforce TPM limits during realtime sessions (#53689) 2026-11-24 05:15:04 -08:00
test_reasoning_effort_levels_chaos.py feat(router)!: apply each deployment's reasoning_effort_levels on every provider and route (#46601) 2026-10-20 04:34:55 +00:00
test_reasoning_effort_levels_wire.py fix(bedrock)!: keep Claude's thinking when response_format json_schema is set (#49696) 2026-11-05 04:07:11 +00:00
test_redis_increment_with_floor.py ci(circleci): test Redis behavior against local Redis and print short tracebacks (#44062) 2026-10-01 13:00:54 -07:00
test_redis_recovery.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_rerank_cancel_on_disconnect.py fix(proxy): honor cancel_on_disconnect on the rerank endpoints (#51252) 2026-11-14 03:59:22 -05:00
test_responses_stream_same_group_retry.py fix(responses): forward lifecycle events once output starts (#52858) 2026-11-19 17:49:23 +00:00
test_responses_websocket_turn_admission.py fix(proxy): refund a Responses WebSocket's key TPM reservation when the socket closes (#51086) 2026-11-23 23:05:26 -08:00
test_router_strategies_count_async_requests_once.py fix(logging)!: fire one CustomLogger failure hook per async call outside the async flag list (#47124) 2026-10-20 15:19:14 -07:00
test_silent_model_shadow_wire.py test(router): audit #41368 (#48794) 2026-10-28 05:14:59 -07:00
test_stale_cost_map_boot.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_tag_routing_prefix.py fix(router)!: only prefixed caller tags route once tag_routing_prefix is set (#47428) 2026-10-20 00:12:28 -07:00
test_team_model_limit_borrows_idle_capacity.py feat(dynamic_rate_limiter): customer organizations and keys borrow idle model capacity and split class shares (#51705) 2026-11-15 12:05:58 -08:00
test_team_tag_routing.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_team_wildcard_precedence.py test(routing): a team's wildcard serves its keys before a proxy-wide wildcard of the same pattern (#48501) 2026-10-26 17:54:32 -07:00
test_usage_based_routing_redis_reads.py test(integration): repair tests that merged changes left stale (#50782) 2026-11-10 01:08:35 +00:00
test_user_config_routing.py feat(openai)!: honor per-deployment workload identity on non-chat routes (#39966) 2026-10-16 22:25:15 +00:00
test_video_poll_routing_wire.py fix(videos)!: keep model_id in proxy video ids so per-model keys resolve on status/content (#44614) 2026-10-20 05:42:59 +00:00
test_vllm_passthrough_spend_row.py fix(vllm): write spend log rows for /vllm passthrough calls to router models (#45733) 2026-10-14 12:40:48 -07:00
test_vllm_passthrough_stream_relay.py fix(vllm): write spend log rows for /vllm passthrough calls to router models (#45733) 2026-10-14 12:40:48 -07:00
test_vllm_passthrough_stream_usage_settings.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_web_search_deployment_filter_owned_proxy.py fix(router): drop supports_web_search false deployments for Anthropic web_search_* and Gemini googleSearch tools (#50275) 2026-11-06 01:58:17 +00:00
test_wildcard_model_listing.py fix(providers): route Azure Responses past dated api versions, count Grok reasoning tokens on azure_ai, refresh provider sets after register_model, fix gpt-6.1-sol Azure rows (#46377) 2026-10-16 15:23:46 -07:00