Repository navigation
feat(providers): add Inference APIs as OpenAI-compatible provider - #41669
Conversation
Merging this PR will not alter performance
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Pushed 940fb4d addressing CI and the Greptile review:
Live before/after proof in the description was re-run at the new tip. |
Registers https://api.inferenceapis.com/v1 as a JSON-configured provider (chat completions and Responses API). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s index, add request-level tests - provider_create_fields.json entry so the Add Model dropdown test passes - provider_endpoints_support.json (+ backup) entry so the provider docs check passes - tests now capture the outgoing HTTP request (URL, auth header, body) instead of only inspecting registrations - drop a redundant comment Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
940fb4d to
f1bda8c
Compare
…httpx.Client Request-level tests now set litellm.client_session to an httpx.Client with a MockTransport, so nothing is monkeypatched on a class. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qUBY2P8qTTuJCUeMzTCD4
|
Pushed 2a7c105 for the class-level patching note: the request tests now inject a recording |
| class TestInferenceAPIsRequests: | ||
| def test_completion_sends_request_to_inferenceapis(self, monkeypatch): | ||
| sent = [] | ||
| monkeypatch.setattr(litellm, "client_session", _recording_session(sent)) |
There was a problem hiding this comment.
The OpenAI-like handler replaces this client with its own HTTPHandler, so these unit tests can contact the real provider.
Rule Used: What: prevent any tests from being added here that make real network calls - only mock tests can be added to this folder. Exception: tests/e2e folder, this folder can contain network calls. Why: ensure it runs correctly on github ci/cd + for all d... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| "meta", # Meta Model API (Muse Spark) - JSON-configured provider | ||
| "cognition", | ||
| "scx-ai", | ||
| "inferenceapis", # Inference APIs - JSON-configured provider |
There was a problem hiding this comment.
This comment only restates the entry, violating the repository directive limiting source comments. This requirement must be satisfied before merging.
| "inferenceapis", # Inference APIs - JSON-configured provider | |
| "inferenceapis", |
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qUBY2P8qTTuJCUeMzTCD4
|
Pushed 0ae0ceb.
|
|
You're right. I rechecked the revised test seam and the provider dispatch: JSON providers default to the Tip: You can customize Greptile's behavior for this repo with |
|
Pushed b7b6adb, a separate 3-line commit:
Same intent as dependabot's #41679. If you would rather keep dependency changes out of this PR, say so and I will drop the commit. |
|
Dropped b7b6adb (the That leaves |
b7b6adb to
0ae0ceb
Compare
…t the responses route Prices and context windows come from https://inferenceapis.com/pricing and GET /v1/models. Moves the provider test to tests/unit and adds the interactions flag the endpoint matrix now carries.
|
Automatic reviews are disabled for this repository. |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Checks and execution details
Evidence that qualifies: The PR description includes inspectable manual E2E proof against the real Inference APIs on commit Fixture provenance: The integration tests use the overflow string Tests I ran:
View review · Reviewed |
…v1/messages supported
|
@litereview code-review |
… off the provider
|
@litereview code-review |
…report context overflow as ContextWindowExceededError
|
@litereview code-review |
…ead of any context_length_exceeded substring
|
@litereview code-review |
…Error for Inference APIs only Providers without their own mapper keep reporting an overflow as BadRequestError, since the router raises a ContextWindowExceededError instead of trying generic fallbacks when context_window_fallbacks has no entry for the group. Adds the integration cells for the provider, its fallbacks, and the extra_body and overflow families.
|
@litereview code-review |
|
bugbot run |
…the chaos cell A reply the killed worker sent before SIGKILL can lose its queued spend row, which the product never promised to keep. Holding the upstream until after the kill means only the surviving worker answers, so every 200 must log exactly once.
|
@litereview code-review |
|
bugbot run |
…always release held replies The survivor now must hold at least one in-flight request, so the burst check cannot pass as 0 == 0, and the held vendor is released on exit so a failed assertion cannot stall the wire server teardown
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 4795f60. Configure here.
mateo-berri
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the contribution!
TLDR
Problem this solves:
inferenceapis/<model>fails, since LiteLLM does not know the provideropenai/plus a customapi_baseHow it solves it:
INFERENCEAPIS_API_KEYand lists it in Admin UI Add Modeltop_kand similar inextra_bodyinstead of a 500ContextWindowExceededError, socontext_window_fallbacksworkUser Flow
Before: an admin with an Inference APIs key cannot route a model to it by provider name
inferenceapis/deepseek-ai/DeepSeek-V4-Flashto the proxy config and setsINFERENCEAPIS_API_KEYThere are no healthy deployments for this modelAfter: the same calls return real answers from Inference APIs and are billed
inferenceapis/deepseek-ai/DeepSeek-V4-Flashto the proxy config and setsINFERENCEAPIS_API_KEYPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/llms/openai_like/test_inferenceapis_provider.py tests/unit/litellm_core_utils/test_exception_mapping_utils.py -vDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Last updated: 4795f60. QA and /live-pr-risk ran on 353c701, the last commit with a product diff
Real Inference APIs calls, no mocks, one proxy per leg with 2 uvicorn workers and its own Postgres. The overflow cases send 150K tokens to
openai/gpt-oss-20b, capped at 131,072. Ollama Cloud, Cloudflare, and Fireworks are real controlsProxy config
pongdeepseek-chattop_k,chat_template_kwargspongContextWindowExceededErrortop_kpongLLM Provider NOT providedpong,completed/audit matrix at 4795f60, merge base bf56719 (every cell)
Every base red is a cell this PR adds or changes. The one legacy red is a Bedrock prompt cache pin cell that fails the same way on the merge base, and this PR touches no Bedrock or caching code. The 11 skips are cells already marked as known bugs in files this PR does not touch
Before (bf56719)
/v1/chat/completions
chat streaming
Steps and raw output
/v1/responses
Steps and raw output
/v1/messages
Steps and raw output
alias deepseek-chat
Steps and raw output
speech on TTS model
Steps and raw output
/v1/audio/speechSpend tracking
Steps and raw output
The full output is in the gist
top_k, chat_template_kwargs
Steps and raw output
150K-token prompt
Steps and raw output
/v1/chat/completionscontext_window_fallbacks/v1/messages/v1/messagesto the group withcontext_window_fallbacksOther providers
Steps and raw output
top_kto an existing veniceai routefallbackscontext_length_exceeded_behavior, controlPython SDK script
Steps and raw output
INFERENCEAPIS_API_KEYsetAdmin UI Add Model
Steps
Add Modeltab, openProviderand typeInferenceXinferencematches, so there is nothing to save (screenshot under User Flow, Before)After (353c701)
/v1/chat/completions
chat streaming
Steps and raw output
/v1/responses
Steps and raw output
The full output is in the gist
/v1/messages
Steps and raw output
alias deepseek-chat
Steps and raw output
speech on TTS model
Steps and raw output
/v1/audio/speechSpend tracking
Steps and raw output
The full output is in the gist
usage.costInference APIs reports itself, e.g. the/v1/messagestool call is 289 prompt x $0.19/M + 17 completion x $0.38/M = $0.00006137 and the UI-addedgpt-oss-20bcall under Admin UI Add Model is 61 x $0.04/M + 125 x $0.19/M = $0.00002619top_k, chat_template_kwargs
Steps and raw output
150K-token prompt
Steps and raw output
/v1/chat/completionscontext_window_fallbacks/v1/messages/v1/messagesto the group withcontext_window_fallbacksOther providers
Steps and raw output
top_kto an existing veniceai routefallbackscontext_length_exceeded_behavior, controlPython SDK script
Steps and raw output
INFERENCEAPIS_API_KEYsetAdmin UI Add Model
Steps and raw output
Add Modeltab, openProviderand typeInferenceInference APIsis listed aboveXinference(screenshots under User Flow, After)openai/gpt-oss-20binLiteLLM Model Name(s), paste the key inAPI Key, clickAdd ModelModel openai/gpt-oss-20b created successfullyand All Models lists the rowPOST /key/generate {"models":["openai/gpt-oss-20b"]}and call itObservations from the run:
response.completednames the vendor model id, not the aliascontext_window_fallbacks, pre-existing, left aloneType
🆕 New Feature
Caveats (if any)
Low
openai/<model>with the vendorapi_baseprevious_response_idgets the vendor's 400, so send the fullinputsupports_response_schemain the cost map, the vendor claims onlyjson_modeinferenceapis/*wildcard lists no models on/v1/modelsFinal Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
353c701 passes /live-pr-risk