MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _spend_error

Function _spend_error

uncommon_route/proxy.py:1950–1972  ·  view source on GitHub ↗

Build a 429 error response for spend control violations.

(
    result: Any,
    *,
    api_format: str = "openai",
    headers: dict[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

1948
1949
1950def _spend_error(
1951 result: Any,
1952 *,
1953 api_format: str = "openai",
1954 headers: dict[str, str] | None = None,
1955) -> JSONResponse:
1956 """Build a 429 error response for spend control violations."""
1957 if api_format == "anthropic":
1958 return JSONResponse(
1959 anthropic_error_response(429, result.reason or "Spending limit exceeded"),
1960 status_code=429,
1961 headers=headers,
1962 )
1963 body: dict[str, Any] = {
1964 "error": {
1965 "message": result.reason or "Spending limit exceeded",
1966 "type": "spend_limit_exceeded",
1967 "code": "spend_limit_exceeded",
1968 }
1969 }
1970 if result.reset_in_s is not None:
1971 body["error"]["reset_in_seconds"] = result.reset_in_s
1972 return JSONResponse(body, status_code=429, headers=headers)
1973
1974
1975def _routing_infeasible_payload(

Callers 2

_handle_chat_coreFunction · 0.85
_spend_error_for_modelFunction · 0.85

Calls 1

anthropic_error_responseFunction · 0.90

Tested by

no test coverage detected