(
attempt_payload: dict[str, Any],
*,
fallback_from: str | None = None,
record_successful_fallback: bool = True,
)
| 4899 | _set_header(debug_headers, "x-uncommon-route-reasoning", reasoning) |
| 4900 | |
| 4901 | def _apply_attempt( |
| 4902 | attempt_payload: dict[str, Any], |
| 4903 | *, |
| 4904 | fallback_from: str | None = None, |
| 4905 | record_successful_fallback: bool = True, |
| 4906 | ) -> None: |
| 4907 | nonlocal selected_model, provider_entry, upstream_body, target_chat_url |
| 4908 | nonlocal transport_body, fwd_headers, transport_decision, native_anthropic_transport |
| 4909 | nonlocal cache_plan, resolved_model, route_method, fallback_reason |
| 4910 | nonlocal reasoning, route_reasoning, main_estimated_cost, estimated_cost |
| 4911 | nonlocal served_quality_value, served_quality_floor_value, served_quality_target_value, capability_lane_value |
| 4912 | |
| 4913 | selected_model = attempt_payload["selected_model"] |
| 4914 | provider_entry = attempt_payload["provider_entry"] |
| 4915 | upstream_body = attempt_payload["upstream_body"] |
| 4916 | target_chat_url = attempt_payload["target_chat_url"] |
| 4917 | transport_body = attempt_payload["transport_body"] |
| 4918 | fwd_headers = attempt_payload["headers"] |
| 4919 | transport_decision = attempt_payload["transport_decision"] |
| 4920 | native_anthropic_transport = attempt_payload["native_anthropic_transport"] |
| 4921 | cache_plan = attempt_payload["cache_plan"] |
| 4922 | resolved_model = attempt_payload["resolved_model"] |
| 4923 | main_estimated_cost, estimated_cost = _estimated_total_cost_for(selected_model) |
| 4924 | lane = request_capability_lane(routing_features) |
| 4925 | capability_lane_value = capability_lane_value or lane.value |
| 4926 | served_quality_value = model_served_quality( |
| 4927 | selected_model, |
| 4928 | lane, |
| 4929 | _routing_config.model_capabilities.get(selected_model), |
| 4930 | ).value |
| 4931 | |
| 4932 | if fallback_from is not None: |
| 4933 | route_method = "fallback" |
| 4934 | fallback_reason = f"{fallback_from} unavailable -> {resolved_model}" |
| 4935 | reasoning = f"fallback: {fallback_reason}" |
| 4936 | route_reasoning = reasoning |
| 4937 | if record_successful_fallback: |
| 4938 | _mapper.record_alias(fallback_from, resolved_model) |
| 4939 | if record_successful_fallback and request_id: |
| 4940 | _feedback.rebind_request( |
| 4941 | request_id, |
| 4942 | model=selected_model, |
| 4943 | tier=tier_value, |
| 4944 | mode=mode_value, |
| 4945 | ) |
| 4946 | if record_successful_fallback: |
| 4947 | print(f"[route] fallback → {resolved_model} ({fallback_from} unavailable)") |
| 4948 | |
| 4949 | _sync_virtual_debug_headers() |
| 4950 | |
| 4951 | async def _spend_error_for_model(model_name: str) -> JSONResponse | None: |
| 4952 | if not is_virtual: |
no test coverage detected