Skip to content

fix(decisions): preserve missing native usage (#48147) - #48261

Merged
ishaan-j-berri merged 1 commit into
mainfrom
litellm_fix_typesafe_decisions_48147
Oct 25, 2026
Merged

ishaan-j-berri merged 1 commit into
mainfrom
litellm_fix_typesafe_decisions_48147

Conversation

@ishaan-j-berri

@ishaan-j-berri ishaan-j-berri commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #48147

If TypeSafe omits token usage, LiteLLM reports zero tokens and a $0 cost, so you cannot tell an unbilled request from missing billing data. This fix keeps missing usage and SDK cost unknown for native decisions calls. It leaves the issue’s error-handling and response-size requests for separate fixes, and keeps the OpenAI-format response contract unchanged.

Before (4710c3b30e5c)

I sent this request through the running proxy. The upstream returned an answer without usage. URLs, model aliases, and credentials use placeholders below; the response contains synthetic data.

curl -sS "$LITELLM_URL/v1/systemone" \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"model":"typesafe-repro","state":{"finding":"x"},"questions":{"exp":{"type":"noul","instructions":"Is it exploitable?"}}}' \
  --write-out '\nHTTP %{http_code}\n'
{"model":"jev-1.13.0","answers":{"exp":{"type":"noul","noul":0.8}},"usage":{"input_tokens":0,"output_tokens":0}}
HTTP 200

After (212219ecc0cd)

I repeated the same curl request against the fixed proxy:

curl -sS "$LITELLM_URL/v1/systemone" \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"model":"typesafe-repro","state":{"finding":"x"},"questions":{"exp":{"type":"noul","instructions":"Is it exploitable?"}}}' \
  --write-out '\nHTTP %{http_code}\n'
{"model":"jev-1.13.0","answers":{"exp":{"type":"noul","noul":0.8}},"usage":null}
HTTP 200
Local reproduction setup

Run this upstream in a separate terminal. It returns an answer without usage; no paid inference is involved.

from http.server import BaseHTTPRequestHandler, HTTPServer

class Upstream(BaseHTTPRequestHandler):
    def do_POST(self):
        self.rfile.read(int(self.headers.get("Content-Length", 0)))
        body = b'{"model":"jev-1.13.0","answers":{"exp":{"type":"noul","noul":0.8}}}'
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)

HTTPServer(("127.0.0.1", 8190), Upstream).serve_forever()

Save this proxy config as /tmp/typesafe-repro.yaml. Set LITELLM_API_KEY and TYPESAFE_API_KEY in your environment; the local upstream ignores the provider credential.

model_list:
  - model_name: typesafe-repro
    litellm_params:
      model: typesafe/jev-1.13.0
      api_base: http://127.0.0.1:8190
      api_key: os.environ/TYPESAFE_API_KEY
general_settings:
  master_key: os.environ/LITELLM_API_KEY

Start each checkout with uv run litellm --config /tmp/typesafe-repro.yaml --port 4000, set LITELLM_URL=http://127.0.0.1:4000, then run the curl command above. Stop the old proxy before starting the fixed one.

@codspeed

codspeed Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing litellm_fix_typesafe_decisions_48147 (212219e) with main (5171b3f)

Open in CodSpeed

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ellm/llms/fireworks_ai/decisions/transformation.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ishaan-j-berri
ishaan-j-berri force-pushed the litellm_fix_typesafe_decisions_48147 branch from aa8ea51 to 212219e Compare October 25, 2026 00:23
@ishaan-j-berri ishaan-j-berri changed the title fix(decisions): preserve upstream response integrity (#48147) fix(decisions): preserve missing native usage (#48147) Oct 25, 2026
@ishaan-j-berri
ishaan-j-berri marked this pull request as ready for review October 25, 2026 00:34
@ishaan-j-berri
ishaan-j-berri enabled auto-merge (squash) October 25, 2026 00:34
@ishaan-j-berri
ishaan-j-berri merged commit cb65a21 into main Oct 25, 2026
85 of 86 checks passed
@ishaan-j-berri
ishaan-j-berri deleted the litellm_fix_typesafe_decisions_48147 branch October 25, 2026 00:37
yuneng-berri added a commit that referenced this pull request Oct 28, 2026
…havior (#48665)

* test(integration): update stale expectations to intended provider behavior

Each expectation moved because a merged PR changed behavior on purpose.
- chatgpt string input is wrapped as one user message (#41522)
- Gemini 2.5 tool media sits beside function_response (#48428)
- sampling knobs move to Gemini 3.5 Flash, which keeps them (#47645)
- a body base_model is stripped without allow_client_pricing_override (#47639)
- ai_decide answers without usage return usage null (#48261)
- azure_ai forwards mapped client anthropic-beta values (#48033)
- the OpenCode scripted upstream mints a fresh id per request

* test(e2e-ui): type the guardrail name before deleting it

GuardrailDeleteModal requires the exact name before Delete enables since
#45893. All three guardrail delete flows now go through one helper.

* test(observability): accept any sampled traceresponse flags and expect a 400 for a non-object body

OpenTelemetry 1.45 (#48055) sets the W3C random trace id flag on new traces,
so the gateway's traceresponse now ends in -03. The producer copies the server
span's own trace flags, so the tests now accept any two-digit flags with the
sampled bit set instead of pinning -01

#48438 made a non-object JSON body a 400 "Invalid JSON payload: expected an
object" on purpose, so the [1] body case is renamed non_object_body and
expects that 400

* test(observability): stop waiting on OpenTelemetry's export log line in the langtrace outage test

The outage test waited for "Exception while exporting Span batch" in the proxy
log, which is OpenTelemetry's wording and no longer appears with 1.45. The test
keeps asserting what the gateway guarantees, callers unaffected during the
outage, a live gateway, and every span after recovery delivered once with no
outage span duplicated

* test(guardrails): count the Responses disconnect spend rows #47611 added

Since #47611 a streamed /v1/responses disconnect writes its own spend row, so
the concurrent disconnect test saw 20 rows where it counted 10 by model group.
It now reads each row's call type and expects ten acompletion rows with the
outage verdict and ten aresponses rows with success. /v1/messages disconnects
still write no row on main, so they are left out of the count rather than
pinned as absent

The responses-httpx case of the single disconnect test no longer needs its
LIT-8603 skip and passes

* test(observability): size K4's timeout from the harness boot budget

K4 boots three two-worker proxies in a row. On CircleCI each boot takes 43 to
58 seconds, so a passing run took 179.97s against its fixed 180s cap and 6 of
30 runs hit pytest-timeout. The cap and the restart gate wait now come from
readiness_seconds and graceful_stop_seconds, like other multi-boot tests
mateo-berri pushed a commit to owen-hj/litellm that referenced this pull request Nov 23, 2026
…I#48261)

Backport of BerriAI#48261 to lts/1.108.x (prerequisite of BerriAI#51220).
Cherry-picked from cb65a21 (main).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: decisions (typesafe): missing usage becomes zero cost, a 200 with an invalid body becomes a 500, and the error body is only in the message

2 participants