litellm/tests/test_litellm_rust/responses/data.py
yujonglee 323d3956d6
feat(rust): one typed decline from core up to each host (#47772)
* feat(rust): one typed decline from core up to each host

Rust core says it cannot serve a request with one Decline that travels
unchanged through llms and inference up to the host. The Python bridge
raises RustBridgeDeclined for it in route_failure before the public
exception mapping, so dispatch falls back to legacy Python instead of
failing the call, and the gateway answers 501. Every route collapses
errors after the send with Error::after_send, which keeps a provider
answer and a response fault as they are and nests anything else as the
source of an invalid response, so a billed call can never read as a
decline. Response-side cases that used to decline are now
ErrorDetail::Unhandled response faults.

The rust-error skill documents declined() as the first question both
boundaries ask, and the Python suites pin that a native decline reaches
the dispatcher before any provider IO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(rust): keep post-provider hook failures terminal

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-28 09:22:11 -07:00

75 lines
2.3 KiB
Python

from typing import Final
import litellm
from tests.test_litellm_rust.support.gaps import gap
from tests.test_litellm_rust.support.recording_server import RecordingServer
from tests.test_litellm_rust.support.routing import call_public
RESPONSES_MODEL: Final = "openai/gpt-6.1-sol"
RESPONSES_TEXT: Final = "Hello from native Responses"
RESPONSES_RESPONSE: Final = {
"id": "resp_native",
"object": "response",
"created_at": 1,
"status": "completed",
"model": RESPONSES_MODEL.removeprefix("openai/"),
"output": [
{
"id": "msg_native",
"type": "message",
"role": "assistant",
"status": "completed",
"content": [{"type": "output_text", "text": RESPONSES_TEXT, "annotations": []}],
}
],
"usage": {"input_tokens": 5, "output_tokens": 4, "total_tokens": 9},
}
RESPONSES_EVENTS: Final = (
(
"response.created",
{
"type": "response.created",
"sequence_number": 0,
"response": {**RESPONSES_RESPONSE, "status": "in_progress", "output": []},
},
),
(
"response.output_text.delta",
{
"type": "response.output_text.delta",
"sequence_number": 1,
"item_id": "msg_native",
"output_index": 0,
"content_index": 0,
"delta": RESPONSES_TEXT,
},
),
("response.completed", {"type": "response.completed", "sequence_number": 2, "response": RESPONSES_RESPONSE}),
)
def _error(kind: str) -> dict[str, object]:
return {"error": {"type": kind, "message": kind, "param": None, "code": None}}
REQUEST: Final = {"model": RESPONSES_MODEL, "input": "Hello"}
BAD_REQUEST: Final = _error("invalid_request_error")
RATE_LIMITED: Final = _error("rate_limit_exceeded")
async def call(server: RecordingServer, *, asynchronous: bool = True, **kwargs: object) -> object:
return await call_public(
litellm.responses,
litellm.aresponses,
REQUEST,
server,
asynchronous=asynchronous,
**kwargs,
)
SYNC_DEPLOYMENT_HOOK: Final = gap("native sync calls skip the async pre-call deployment hook")
STREAMING: Final = gap(
"native Responses streaming is unsupported, the catalog keeps it on Python", raises=RuntimeError
)
BODY_HOOKS: Final = gap("native Responses does not run the handler body hooks")