Skip to content

feat(providers): add Inference APIs as OpenAI-compatible provider - #41669

Merged
mateo-berri merged 14 commits into
BerriAI:mainfrom
TaylorHawkes:feat/add-inferenceapis-provider
Oct 15, 2026
Merged

mateo-berri merged 14 commits into
BerriAI:mainfrom
TaylorHawkes:feat/add-inferenceapis-provider

Conversation

@TaylorHawkes

@TaylorHawkes TaylorHawkes commented Sep 17, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • inferenceapis/<model> fails, since LiteLLM does not know the provider
  • Users hand-configure openai/ plus a custom api_base

How it solves it:

  • Adds Inference APIs as a JSON-configured OpenAI-compatible provider
  • Serves chat completions, responses, and messages on its native endpoints
  • Reads INFERENCEAPIS_API_KEY and lists it in Admin UI Add Model
  • Prices 12 chat models and 24 aliases for spend tracking
  • JSON providers send top_k and similar in extra_body instead of a 500
  • Its context overflow raises ContextWindowExceededError, so context_window_fallbacks work
    • Other providers keep their error class, since the router skips generic fallbacks for it
  • Docs in litellm-docs#2389

User Flow

Before: an admin with an Inference APIs key cannot route a model to it by provider name

  1. The admin adds inferenceapis/deepseek-ai/DeepSeek-V4-Flash to the proxy config and sets INFERENCEAPIS_API_KEY
  2. A developer calls POST https://litellm-domain/v1/chat/completions, /v1/responses, or /v1/messages with it
  3. Every call answers 400 There are no healthy deployments for this model
  4. Add Model at https://litellm-domain/ui/?page=models has no Inference APIs provider

add_model_provider_base

After: the same calls return real answers from Inference APIs and are billed

  1. The admin adds inferenceapis/deepseek-ai/DeepSeek-V4-Flash to the proxy config and sets INFERENCEAPIS_API_KEY
  2. A developer calls POST https://litellm-domain/v1/chat/completions, /v1/responses, or /v1/messages with it
  3. Each call answers 200 with the reply, billed in GET https://litellm-domain/spend/logs
  4. Add Model lists Inference APIs, and a model saved there answers 200

add_model_provider_head

add_model_form_head

all_models_head

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/llms/openai_like/test_inferenceapis_provider.py tests/unit/litellm_core_utils/test_exception_mapping_utils.py -v
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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 controls

Proxy config
model_list:
  - model_name: inferenceapis-flash
    litellm_params:
      model: inferenceapis/deepseek-ai/DeepSeek-V4-Flash
  - model_name: inferenceapis-alias
    litellm_params:
      model: inferenceapis/deepseek-chat
  - model_name: inferenceapis-tts
    litellm_params:
      model: inferenceapis/hexgrad/Kokoro-82M
  - model_name: inferenceapis-small
    litellm_params:
      model: inferenceapis/openai/gpt-oss-20b
  - model_name: inferenceapis-small-with-fallback
    litellm_params:
      model: inferenceapis/openai/gpt-oss-20b
  - model_name: fireworks-with-fallback
    litellm_params:
      model: fireworks_ai/accounts/fireworks/models/gpt-oss-120b
      api_key: os.environ/FIREWORKS_AI_API_KEY
  - model_name: cloudflare-small-with-fallback
    litellm_params:
      model: cloudflare/@cf/meta/llama-3.2-1b-instruct
      api_key: os.environ/CLOUDFLARE_API_KEY
  - model_name: ollama-cloud-with-fallback
    litellm_params:
      model: ollama_chat/gpt-oss:20b
      api_base: https://ollama.com
      api_key: os.environ/OLLAMA_API_KEY
  - model_name: veniceai-route
    litellm_params:
      model: veniceai/deepseek-ai/DeepSeek-V4-Flash
      api_base: https://api.inferenceapis.com/v1
      api_key: os.environ/INFERENCEAPIS_API_KEY
  - model_name: veniceai-overflow-with-generic-fallback
    litellm_params:
      model: veniceai/openai/gpt-oss-20b
      api_base: https://api.inferenceapis.com/v1
      api_key: os.environ/INFERENCEAPIS_API_KEY
router_settings:
  fallbacks:
    - veniceai-overflow-with-generic-fallback: ["veniceai-route"]
  context_window_fallbacks:
    - inferenceapis-small-with-fallback: ["inferenceapis-flash"]
    - fireworks-with-fallback: ["inferenceapis-flash"]
    - cloudflare-small-with-fallback: ["inferenceapis-flash"]
    - ollama-cloud-with-fallback: ["inferenceapis-flash"]
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  database_url: os.environ/DATABASE_URL
Case Before (bf56719) After (353c701)
/v1/chat/completions 400 200, pong
chat streaming 400 200, usage chunk
/v1/responses 400 200 on all three
/v1/messages 400 200 on all three
alias deepseek-chat 400 200, billed
speech on TTS model 400 500, no vendor call
spend tracking 10 rows at $0 9 billed rows
top_k, chat_template_kwargs 400 200, pong
150K-token prompt 400 ContextWindowExceededError
same, with fallback 400 200 from the fallback
veniceai top_k 500 200, pong
other providers' overflow unchanged unchanged
Python SDK script LLM Provider NOT provided pong, completed
Admin UI Add Model provider missing saved model answers
/audit matrix at 4795f60, merge base bf56719 (every cell)
Lane Cells Base Head run 1 Head run 2 Ran at
Context window fallbacks and chaos 11 10 red, 1 control green 11 green 11 green 4795f60
Inference APIs wire 22 22 red 22 green 22 green db1a68a
SDK error and extra_body families 106 23 red, 83 controls green 106 green 106 green db1a68a
Controls 147 not run 136 green, 11 skipped not run 353c701
/live-pr-risk legacy sweep 157 1 red of 51 rechecked 156 green, 1 red 1 red of 51 rechecked db1a68a

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

  1. Send the request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

chat streaming

Steps and raw output
  1. Send the streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"stream":true,"stream_options":{"include_usage":true}}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

/v1/responses

Steps and raw output
  1. Send a plain request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","input":"Reply with the single word: pong","max_output_tokens":200}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
  1. Send a streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","input":"Reply with the single word: pong","max_output_tokens":200,"stream":true}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
  1. Send a tool call request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_output_tokens":300,"tools":[{"type":"function","name":"get_weather","description":"Get the current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":"required","input":"What is the weather in Paris right now?"}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

/v1/messages

Steps and raw output
  1. Send a plain request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":200,"messages":[{"role":"user","content":"Reply with the single word: pong"}]}'
  1. Observe the response
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted."}}
HTTP 400
  1. Send a streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":200,"stream":true,"messages":[{"role":"user","content":"Reply with the single word: pong"}]}'
  1. Observe the response
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted."}}
HTTP 400
  1. Send a tool call request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":300,"tools":[{"name":"get_weather","description":"Get the current weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"any"},"messages":[{"role":"user","content":"What is the weather in Paris right now?"}]}'
  1. Observe the response
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted."}}
HTTP 400

alias deepseek-chat

Steps and raw output
  1. Call the vendor alias
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-alias","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-alias. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-alias' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

speech on TTS model

Steps and raw output
  1. Call /v1/audio/speech
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-tts","input":"hello","voice":"af_heart"}' | cut -c1-160
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-tts. There are no healthy deployments for this model\n\nLiteLLM: model group 'in
HTTP 400

Spend tracking

Steps and raw output
  1. Wait 25 seconds after the ten calls above, then list the key's spend logs
curl -sS 'http://localhost:$PORT/spend/logs?api_key='"$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq '[.[] | {call_type, model, model_group, custom_llm_provider, prompt_tokens, completion_tokens, spend}]'

The full output is in the gist

  1. Read the key's total spend
curl -sS 'http://localhost:$PORT/key/info?key='"$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq '{spend: .info.spend, models: .info.models}'
{
  "spend": 0.0,
  "models": [
    "inferenceapis-flash",
    "inferenceapis-alias",
    "inferenceapis-tts"
  ]
}

top_k, chat_template_kwargs

Steps and raw output
  1. Send provider-specific params
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"top_k":5,"chat_template_kwargs":{"enable_thinking":false}}'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-flash. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-flash' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

150K-token prompt

Steps and raw output
  1. Send it on /v1/chat/completions
jq -c '.model="inferenceapis-small" | .max_tokens=5' long_prompt.json | curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | cut -c1-600
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-small. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-small' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
  1. Send it to the group with context_window_fallbacks
jq -c '.model="inferenceapis-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {prompt_tokens: .usage.prompt_tokens}, error}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 400 Bad Request
HTTP 400
{"model":null,"usage":{"prompt_tokens":null},"error":{"message":"litellm.BadRequestError: You passed in model=inferenceapis-small-with-fallback. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-small-with-fallback' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
  1. Send it on /v1/messages
jq -c '.model="inferenceapis-small" | .max_tokens=5' long_prompt.json | curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | cut -c1-600
  1. Observe the response
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: You passed in model=inferenceapis-small. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-small' failed with the error above. No fallback was attempted."}}
HTTP 400
  1. Send it on /v1/messages to the group with context_window_fallbacks
jq -c '.model="inferenceapis-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {input_tokens: .usage.input_tokens}, error}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 400 Bad Request
HTTP 400
{"model":null,"usage":{"input_tokens":null},"error":{"type":"invalid_request_error","message":"litellm.BadRequestError: You passed in model=inferenceapis-small-with-fallback. There are no healthy deployments for this model\n\nLiteLLM: model group 'inferenceapis-small-with-fallback' failed with the error above. No fallback was attempted."}}

Other providers

Steps and raw output
  1. Send top_k to an existing veniceai route
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"veniceai-route","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"top_k":5,"chat_template_kwargs":{"enable_thinking":false}}' | cut -c1-500
  1. Observe the response
{"error":{"message":"litellm.InternalServerError: VeniceaiException - AsyncCompletions.create() got an unexpected keyword argument 'top_k'\n\nLiteLLM: model group 'veniceai-route' failed with the error above. No fallback was attempted.","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500
  1. Overflow a veniceai route that has generic fallbacks
jq -c '.model="veniceai-overflow-with-generic-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {prompt_tokens: .usage.prompt_tokens}, error: (.error.message // null | if . then .[0:300] else null end)}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks)|HTTP)'
  1. Observe the response
HTTP/1.1 200 OK
x-litellm-model-group: veniceai-route
x-litellm-attempted-fallbacks: 1
HTTP 200
{"model":"veniceai/deepseek-ai/DeepSeek-V4-Flash","usage":{"prompt_tokens":150005},"error":null}
  1. Overflow Ollama Cloud, control
jq -c '.model="ollama-cloud-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: Ollama_chatException - {\"error\":\"The prompt is too long: 150078, model maximum context length: 131072 (ref: ad8f64ec-da65-4afc-ab3c-c6698fa3db43)\"}\n\n\nLiteLLM: model group 'ollama-cloud-with-fallback' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP/1.1 400 Bad Request
HTTP 400
  1. Overflow Cloudflare, control
jq -c '.model="cloudflare-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 413 Request Entity Too Large
HTTP 413
{"error":{"message":"litellm.BadRequestError: CloudflareException - {\"errors\":[{\"message\":\"AiError: Ai: The estimated number of input and maximum output tokens (225036) exceeded this model context window limit (60000). (4bb0632f-f101-412a-8b2d-3d01edc80616)\",\"code\":5021}],\"success\":false,\"result\":{},\"messages\":[]}\n\nLiteLLM: model group 'cloudflare-small-with-fallback' failed with t
  1. Send Fireworks a bad context_length_exceeded_behavior, control
curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"fireworks-with-fallback","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":20,"context_length_exceeded_behavior":"foo"}' | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 400 Bad Request
HTTP 400
{"error":{"message":"litellm.BadRequestError: Fireworks_aiException - {\"error\":{\"object\":\"error\",\"type\":\"invalid_request_error\",\"code\":\"invalid_request_error\",\"message\":\"Input should be 'error' or 'truncate', field: 'context_length_exceeded_behavior', value: 'foo'\"}}\n\nLiteLLM: model group 'fireworks-with-fallback' failed with the error above. No fallback was attempted.","type":

Python SDK script

Steps and raw output
  1. Run the script from the original description with INFERENCEAPIS_API_KEY set
import litellm

try:
    r = litellm.completion(model="inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo",
                           messages=[{"role": "user", "content": "Reply with the single word: pong"}], max_completion_tokens=5)
    print("[chat]", r.choices[0].message.content, r._hidden_params.get("custom_llm_provider"), r.usage.total_tokens)
except Exception as e:
    print("[chat]", type(e).__name__, str(e).splitlines()[0][:200])
try:
    r = litellm.responses(model="inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo",
                          input="Reply with the single word: pong", max_output_tokens=20)
    print("[responses]", r.status, [c.text for o in r.output if o.type == "message" for c in o.content])
except Exception as e:
    print("[responses]", type(e).__name__, str(e).splitlines()[0][:200])
  1. Observe the output
[chat] BadRequestError litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo
[responses] BadRequestError litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo

Admin UI Add Model

Steps
  1. Open http://localhost:$PORT/ui/?page=models, click the Add Model tab, open Provider and type Inference
  2. Only Xinference matches, so there is nothing to save (screenshot under User Flow, Before)

After (353c701)

/v1/chat/completions

  1. Send the request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200}'
  1. Observe the response
{"id":"750934e7-aws_ue2","created":1792068680,"model":"inferenceapis-flash","object":"chat.completion","system_fingerprint":"default","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","reasoning_content":"1.  The user asks to reply with the single word: pong.\n2.  The instruction is clear and direct.\n3.  I will output exactly that word."},"provider_specific_fields":{}}],"usage":{"completion_tokens":40,"prompt_tokens":12,"total_tokens":52,"completion_tokens_details":{"reasoning_tokens":36},"prompt_tokens_details":{"cached_tokens":0},"cost":1.748e-05}}
HTTP 200

chat streaming

Steps and raw output
  1. Send the streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"stream":true,"stream_options":{"include_usage":true}}'
  1. Observe the response
data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":"","role":"assistant"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":"1"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":".  The user asks to"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":" reply with the single word:"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":" p"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":"ong.\n2.  The"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":" instruction is clear"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":" and direct"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":".\n3.  I"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":" must output exactly \"pong"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":"\" and"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"reasoning_content":"nothing else."}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{"content":"pong"}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: {"id":"db9f35f9-aws_ue2","created":1792068682,"model":"inferenceapis-flash","object":"chat.completion.chunk","system_fingerprint":"default","choices":[{"index":0,"delta":{}}],"usage":{"completion_tokens":45,"prompt_tokens":12,"total_tokens":57,"completion_tokens_details":{"reasoning_tokens":41},"prompt_tokens_details":{"cached_tokens":0},"cost":0.00001938}}

data: [DONE]


HTTP 200

/v1/responses

Steps and raw output
  1. Send a plain request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","input":"Reply with the single word: pong","max_output_tokens":200}'
  1. Observe the response
{"id":"resp_HU3RtDd0WgFdRnyizfFv3K0-V4UdhHz4T9WgEjQwC_HWzh7_2eYiUmjFFJd5TgIe_18lTrT-FVLBA9Jl71ZQ5Q5iTZTfI0-8obq-WWJ9PEM2W588OFUK3VNDeN2G6GtRYpG3kGI4n4X8cuzzzeRydLq0VwUGYzbwzicIPMD_2HZScwiX88dCX-VHnQVyrnF4oJOTpSy0aBA6XfGDmmiW95ellNh7KXf5caiyFkQ7lXnp-k5srx67srqWh58C-qkJOTv-J4-KkNtS6d6zIUy1noEwWgm1tFOECcbK1Wl8kkYqIn3Vx7LnSrfdqLJRy5v5-_jzDDyWz91qPf0Xrp16JLOHKgmnwhCk_35pzLTjNrj_cMljIna1krUFGfH6bCRGHyZiFf11GaSlz9VIr68RiIb8j4KToLEHZUbM","created_at":1792068684,"error":null,"incomplete_details":null,"instructions":null,"metadata":{},"model":"inferenceapis-flash","object":"response","output":[{"id":"rs_05cc36ce3f6ef3543782","summary":[],"type":"reasoning","content":[{"text":"1.  The user asks to reply with the single word: pong.\n2.  The instruction is clear and direct.\n3.  I must output only the word \"pong\".","type":"reasoning_text"}]},{"id":"msg_d45047ad1dcfbde7fe43","content":[{"annotations":[],"text":"pong","type":"output_text","logprobs":[]}],"role":"assistant","status":"completed","type":"message","phase":null}],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","tools":[],"top_p":1.0,"max_output_tokens":200,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"status":"completed","text":{"format":{"type":"text"}},"truncation":"disabled","usage":{"input_tokens":12,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"image_tokens":null,"text_tokens":null,"video_tokens":null},"output_tokens":43,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":39,"text_tokens":null},"total_tokens":55,"cost":1.862e-05},"user":null,"store":false,"background":false}
HTTP 200
  1. Send a streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","input":"Reply with the single word: pong","max_output_tokens":200,"stream":true}'
  1. Observe the response

The full output is in the gist

  1. Send a tool call request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_output_tokens":300,"tools":[{"type":"function","name":"get_weather","description":"Get the current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":"required","input":"What is the weather in Paris right now?"}'
  1. Observe the response
{"id":"resp_BlKSJikueD5SGE_J1EmZgDF5cf8H1LMpRgLUJpPPqPQli-E2NBOpUGIx3yMe6nBwGfCGJQ2dAxbzc4FBCeWwUA-Ziccs4B2WwkNmGof-Gwo-TNoGSTuiYln7dXdl3Iqn3H-V63it_BjowWsM5xUgGa3t2Mjum7H6yCi9YWUY98WiuFteArTSpWfk61GOKvJPlGmgpIiCIJStaCAxKeTlWogVkLFXhAPTL3udtTCoVAaM9y3543k3kQ73FiedgrT0mEd-WN-FEpTzwELPOcHqyrsd_zIde0vd_1VEqjh8HMdAfQzPvdgh-lbr8XIj8AgP8-ItpRphL-9KUwbsnpDxb232gXxvdk-GTuAqqZysW1c3fESt28wWnEYxUEXhD3HdqTc_92oJPSFEqlQiu7Qto1ee2qhTvAmZRiwf","created_at":1792068695,"error":null,"incomplete_details":null,"instructions":null,"metadata":{},"model":"inferenceapis-flash","object":"response","output":[{"arguments":"{\"city\":\"Paris\"}","call_id":"call_01a13f9e3b9e79d1a77cfa74","name":"get_weather","type":"function_call","id":"fc_da92fca3656ac3262918","namespace":null,"status":"completed"}],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"required","tools":[{"name":"get_weather","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]},"strict":null,"type":"function","defer_loading":null,"description":"Get the current weather for a city"}],"top_p":1.0,"max_output_tokens":300,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"status":"completed","text":{"format":{"type":"text"}},"truncation":"disabled","usage":{"input_tokens":289,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"image_tokens":null,"text_tokens":null,"video_tokens":null},"output_tokens":17,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":null},"total_tokens":306,"cost":6.137e-05},"user":null,"store":false,"background":false}
HTTP 200

/v1/messages

Steps and raw output
  1. Send a plain request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":200,"messages":[{"role":"user","content":"Reply with the single word: pong"}]}'
  1. Observe the response
{"id":"msg_6ce364976435536f85d17b0a","type":"message","role":"assistant","model":"inferenceapis-flash","content":[{"type":"text","text":"pong"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":12,"output_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"service_tier":"standard","cost":3.42e-06}}
HTTP 200
  1. Send a streaming request
curl -sS -N -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":200,"stream":true,"messages":[{"role":"user","content":"Reply with the single word: pong"}]}'
  1. Observe the response
event: message_start
data: {"type":"message_start","message":{"id":"msg_604af6a341b128c243292356","type":"message","role":"assistant","model":"inferenceapis-flash","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":21,"output_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}}

event: ping
data: {"type":"ping"}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"p"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"ong"}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"output_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"service_tier":"standard","cost":3.42e-6}}

event: message_stop
data: {"type":"message_stop"}


HTTP 200
  1. Send a tool call request
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","max_tokens":300,"tools":[{"name":"get_weather","description":"Get the current weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"any"},"messages":[{"role":"user","content":"What is the weather in Paris right now?"}]}'
  1. Observe the response
{"id":"msg_85f6e622b57dd9d8d553dc4f","type":"message","role":"assistant","model":"inferenceapis-flash","content":[{"type":"tool_use","id":"call_01a13f9e36d47823a0662f3f","name":"get_weather","input":{"city":"Paris"}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":289,"output_tokens":17,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"service_tier":"standard","cost":6.137e-05}}
HTTP 200

alias deepseek-chat

Steps and raw output
  1. Call the vendor alias
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-alias","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200}'
  1. Observe the response
{"id":"c803b4f7-aws_ue2","created":1792068697,"model":"inferenceapis-alias","object":"chat.completion","system_fingerprint":"default","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant"},"provider_specific_fields":{}}],"usage":{"completion_tokens":3,"prompt_tokens":12,"total_tokens":15,"prompt_tokens_details":{"cached_tokens":0},"cost":3.42e-06}}
HTTP 200

speech on TTS model

Steps and raw output
  1. Call /v1/audio/speech
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-tts","input":"hello","voice":"af_heart"}' | cut -c1-160
  1. Observe the response
{"error":{"message":"litellm.APIConnectionError: Unable to map the custom llm provider=inferenceapis to a known provider=[<LlmProviders.OPENAI: 'openai'>, <LlmP
HTTP 500

Spend tracking

Steps and raw output
  1. Wait 25 seconds after the ten calls above, then list the key's spend logs
curl -sS 'http://localhost:$PORT/spend/logs?api_key='"$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq '[.[] | {call_type, model, model_group, custom_llm_provider, prompt_tokens, completion_tokens, spend}]'

The full output is in the gist

  1. Read the key's total spend
curl -sS 'http://localhost:$PORT/key/info?key='"$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq '{spend: .info.spend, models: .info.models}'
{
  "spend": 0.0002071,
  "models": [
    "inferenceapis-flash",
    "inferenceapis-alias",
    "inferenceapis-tts"
  ]
}
  1. Spend matches the cost map rows and the usage.cost Inference APIs reports itself, e.g. the /v1/messages tool call is 289 prompt x $0.19/M + 17 completion x $0.38/M = $0.00006137 and the UI-added gpt-oss-20b call under Admin UI Add Model is 61 x $0.04/M + 125 x $0.19/M = $0.00002619

top_k, chat_template_kwargs

Steps and raw output
  1. Send provider-specific params
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"inferenceapis-flash","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"top_k":5,"chat_template_kwargs":{"enable_thinking":false}}'
  1. Observe the response
{"id":"2e318d54-aws_ue2","created":1792068675,"model":"inferenceapis-flash","object":"chat.completion","system_fingerprint":"default","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant"},"provider_specific_fields":{}}],"usage":{"completion_tokens":3,"prompt_tokens":12,"total_tokens":15,"prompt_tokens_details":{"cached_tokens":0},"cost":3.42e-06}}
HTTP 200

150K-token prompt

Steps and raw output
  1. Send it on /v1/chat/completions
jq -c '.model="inferenceapis-small" | .max_tokens=5' long_prompt.json | curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | cut -c1-600
  1. Observe the response
{"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: InferenceapisException: Context Window Error - Error code: 400 - {'error': {'message': 'Input too long: 150055 input tokens, limit is 131072 for this model', 'type': 'invalid_request_error', 'param': None, 'code': 'context_length_exceeded'}}\n\nLiteLLM: model group 'inferenceapis-small' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
  1. Send it to the group with context_window_fallbacks
jq -c '.model="inferenceapis-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {prompt_tokens: .usage.prompt_tokens}, error}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
{"model":"inferenceapis/deepseek-ai/DeepSeek-V4-Flash","usage":{"prompt_tokens":150005},"error":null}
HTTP/1.1 200 OK
x-litellm-model-api-base: https://api.inferenceapis.com/v1
x-litellm-model-group: inferenceapis-flash
x-litellm-attempted-fallbacks: 1
HTTP 200
  1. Send it on /v1/messages
jq -c '.model="inferenceapis-small" | .max_tokens=5' long_prompt.json | curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | cut -c1-600
  1. Observe the response
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.ContextWindowExceededError: litellm.BadRequestError: InferenceapisException: Context Window Error - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"Input too long: 150055 input tokens, limit is 131072 for this model\",\"code\":\"upstream_rejected\",\"docs_url\":\"https://inferenceapis.com/docs/errors#upstream_rejected\"},\"request_id\":null}\n\nLiteLLM: model group 'inferenceapis-small' failed with the error above. No fallback was attempted."}}
HTTP 400
  1. Send it on /v1/messages to the group with context_window_fallbacks
jq -c '.model="inferenceapis-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {input_tokens: .usage.input_tokens}, error}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/messages -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 200 OK
x-litellm-model-group: inferenceapis-flash
x-litellm-attempted-fallbacks: 1
HTTP 200
{"model":"deepseek-ai/DeepSeek-V4-Flash","usage":{"input_tokens":1},"error":null}

Other providers

Steps and raw output
  1. Send top_k to an existing veniceai route
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"veniceai-route","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200,"top_k":5,"chat_template_kwargs":{"enable_thinking":false}}' | cut -c1-500
  1. Observe the response
{"id":"4ed02f24-aws_ue2","created":1792068674,"model":"veniceai-route","object":"chat.completion","system_fingerprint":"default","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant"},"provider_specific_fields":{}}],"usage":{"completion_tokens":3,"prompt_tokens":12,"total_tokens":15,"prompt_tokens_details":{"cached_tokens":0},"cost":3.42e-06}}
HTTP 200
  1. Overflow a veniceai route that has generic fallbacks
jq -c '.model="veniceai-overflow-with-generic-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(jq -c '{model, usage: {prompt_tokens: .usage.prompt_tokens}, error: (.error.message // null | if . then .[0:300] else null end)}' >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks)|HTTP)'
  1. Observe the response
{"model":"veniceai/deepseek-ai/DeepSeek-V4-Flash","usage":{"prompt_tokens":150005},"error":null}
HTTP/1.1 200 OK
x-litellm-model-group: veniceai-route
x-litellm-attempted-fallbacks: 1
HTTP 200
  1. Overflow Ollama Cloud, control
jq -c '.model="ollama-cloud-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: Ollama_chatException - {\"error\":\"The prompt is too long: 150078, model maximum context length: 131072 (ref: 7c050522-71cc-4198-addd-af0bf9c21d4f)\"}\n\n\nLiteLLM: model group 'ollama-cloud-with-fallback' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured
HTTP/1.1 400 Bad Request
HTTP 400
  1. Overflow Cloudflare, control
jq -c '.model="cloudflare-small-with-fallback" | .max_tokens=5' long_prompt.json | curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d @- | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
HTTP/1.1 413 Request Entity Too Large
HTTP 413
{"error":{"message":"litellm.BadRequestError: CloudflareException - {\"errors\":[{\"message\":\"AiError: Ai: The estimated number of input and maximum output tokens (225036) exceeded this model context window limit (60000). (27499320-4bd5-44bc-a620-d3f362628d5b)\",\"code\":5021}],\"success\":false,\"result\":{},\"messages\":[]}\n\nLiteLLM: model group 'cloudflare-small-with-fallback' failed with t
  1. Send Fireworks a bad context_length_exceeded_behavior, control
curl -sS -D - -o >(cut -c1-400 >&2) -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"fireworks-with-fallback","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":20,"context_length_exceeded_behavior":"foo"}' | grep -iE '^(x-litellm-(model-group|attempted-fallbacks|model-api-base)|HTTP)'
  1. Observe the response
{"error":{"message":"litellm.BadRequestError: Fireworks_aiException - {\"error\":{\"object\":\"error\",\"type\":\"invalid_request_error\",\"code\":\"invalid_request_error\",\"message\":\"Input should be 'error' or 'truncate', field: 'context_length_exceeded_behavior', value: 'foo'\"}}\n\nLiteLLM: model group 'fireworks-with-fallback' failed with the error above and no fallback model group was foun
HTTP/1.1 400 Bad Request
HTTP 400

Python SDK script

Steps and raw output
  1. Run the script from the original description with INFERENCEAPIS_API_KEY set
import litellm

try:
    r = litellm.completion(model="inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo",
                           messages=[{"role": "user", "content": "Reply with the single word: pong"}], max_completion_tokens=5)
    print("[chat]", r.choices[0].message.content, r._hidden_params.get("custom_llm_provider"), r.usage.total_tokens)
except Exception as e:
    print("[chat]", type(e).__name__, str(e).splitlines()[0][:200])
try:
    r = litellm.responses(model="inferenceapis/meta-llama/Llama-3.3-70B-Instruct-Turbo",
                          input="Reply with the single word: pong", max_output_tokens=20)
    print("[responses]", r.status, [c.text for o in r.output if o.type == "message" for c in o.content])
except Exception as e:
    print("[responses]", type(e).__name__, str(e).splitlines()[0][:200])
  1. Observe the output
[chat] pong inferenceapis 19
[responses] completed ['pong']

Admin UI Add Model

Steps and raw output
  1. Open http://localhost:$PORT/ui/?page=models, click the Add Model tab, open Provider and type Inference
  2. Inference APIs is listed above Xinference (screenshots under User Flow, After)
  3. Pick it, type openai/gpt-oss-20b in LiteLLM Model Name(s), paste the key in API Key, click Add Model
  4. The toast says Model openai/gpt-oss-20b created successfully and All Models lists the row
  5. Make a key for it with POST /key/generate {"models":["openai/gpt-oss-20b"]} and call it
curl -sS -w '\nHTTP %{http_code}\n' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"openai/gpt-oss-20b","messages":[{"role":"user","content":"Reply with the single word: pong"}],"max_tokens":200}'
{"id":"chatcmpl-RHESRMkE6jvAMZOILmVStopd","created":1792068960,"model":"openai/gpt-oss-20b","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","reasoning_content":"The user says: \"Reply with the single word: pong\". The instruction says \"Reply with the single word: pong\". So just output \"pong\". The reaction: The user is telling me to reply with the single word \"pong\". So I should output just that. Let's comply.\n\nBut check if there's any nuance: The user specifically says: \"Reply with the single word: pong\". So the response should be just pong. No explanation, no extra words. The instruction says \"Reply with the single word: pong\". So I should output exactly \"pong\".","provider_specific_fields":{"name":null}},"provider_specific_fields":{},"logprobs":null}],"usage":{"completion_tokens":125,"prompt_tokens":61,"total_tokens":186,"cost":2.619e-05},"service_tier":"default"}
HTTP 200
  1. Wait 20 seconds and list that key's spend logs
curl -sS 'http://localhost:$PORT/spend/logs?api_key='"$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq '[.[] | {call_type, model, model_group, custom_llm_provider, prompt_tokens, completion_tokens, spend}]'
[
  {
    "call_type": "acompletion",
    "model": "openai/gpt-oss-20b",
    "model_group": "openai/gpt-oss-20b",
    "custom_llm_provider": "inferenceapis",
    "prompt_tokens": 61,
    "completion_tokens": 125,
    "spend": 0.00002619
  }
]

Observations from the run:

  • Streamed response.completed names the vendor model id, not the alias
  • Ollama Cloud overflow skips context_window_fallbacks, pre-existing, left alone

Type

🆕 New Feature

Caveats (if any)

Low

  • Audio routes answer 500, as anthropic's do today
  • Embedding, rerank, and audio models need openai/<model> with the vendor api_base
  • previous_response_id gets the vendor's 400, so send the full input
  • No supports_response_schema in the cost map, the vendor claims only json_mode
  • An inferenceapis/* wildcard lists no models on /v1/models
  • The docs link 404s until litellm-docs#2389 merges

Final 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

@TaylorHawkes
TaylorHawkes requested a review from a team September 17, 2026 20:51
@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing TaylorHawkes:feat/add-inferenceapis-provider (4795f60) with main (56dad90)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

The PR is not yet safe to merge because the revised request tests can make real provider calls instead of using their MockTransport

Findings

  1. P1 Mock Client Is Ignored ▶
  2. P2 Redundant Provider Comment ▶

Summary

Adds Inference APIs as a JSON-configured OpenAI-compatible provider with chat-completions and Responses API registration, environment-based credentials, provider metadata, and request tests

  • Registers provider resolution, endpoint support, and public model-creation fields
  • Adds tests for configuration, routing, parameter forwarding, and outgoing chat requests
  • The latest test-seam change does not intercept the OpenAI-like request path, leaving the request tests capable of real network access

Reviews (3) · Last reviewed commit: "test(providers): inject a recording HTTP..."

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TaylorHawkes

Copy link
Copy Markdown
Author

Pushed 940fb4d addressing CI and the Greptile review:

  • proxy-endpoints (test_every_backend_provider_is_listed_in_add_model_or_frozen_as_unlisted): added an inferenceapis entry to provider_create_fields.json.
  • code-quality (provider docs check): added inferenceapis to provider_endpoints_support.json and its backup.
  • Greptile P2, tests inspect structure only: added request-level tests that capture the outgoing HTTP request and assert the URL, Authorization header and JSON body, for an explicit key and for the INFERENCEAPIS_API_KEY / INFERENCEAPIS_API_BASE environment variables.
  • Greptile P2, redundant comment: removed.
  • osv-scan flags soupsieve 2.8.4 in uv.lock. This PR does not touch the lock file and main (1dd4c13) carries the same entry, so I have left it alone.

Live before/after proof in the description was re-run at the new tip.

@greptileai

TaylorHawkes and others added 2 commits September 17, 2026 21:23
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>
@TaylorHawkes
TaylorHawkes force-pushed the feat/add-inferenceapis-provider branch from 940fb4d to f1bda8c Compare September 17, 2026 21:24
…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
@TaylorHawkes

Copy link
Copy Markdown
Author

Pushed 2a7c105 for the class-level patching note: the request tests now inject a recording httpx.Client (with httpx.MockTransport) through litellm.client_session, so nothing is monkeypatched on a class. tests/test_litellm/llms/openai_like/ passes locally (202 passed, 5 skipped); ruff check and ruff format --check are clean.

@greptileai

class TestInferenceAPIsRequests:
def test_completion_sends_request_to_inferenceapis(self, monkeypatch):
sent = []
monkeypatch.setattr(litellm, "client_session", _recording_session(sent))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mock Client Is Ignored

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!

Comment thread litellm/constants.py Outdated
"meta", # Meta Model API (Muse Spark) - JSON-configured provider
"cognition",
"scx-ai",
"inferenceapis", # Inference APIs - JSON-configured provider

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant Provider Comment

This comment only restates the entry, violating the repository directive limiting source comments. This requirement must be satisfied before merging.

Suggested change
"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!

@TaylorHawkes

Copy link
Copy Markdown
Author

Pushed 0ae0ceb.

  • Redundant provider comment in constants.py: removed.

  • "Mock client is ignored": the injected client is what serves these requests, and the tests cannot reach the network:

    • each test asserts len(sent) == 1 on the list the MockTransport handler appends to, then asserts that request's URL, Authorization header and JSON body. If the handler were bypassed, sent would be empty and the test would fail;
    • the keys are fakes (sk-test-explicit, sk-from-env), so a real call would come back 401 and the content == "pong" assertion would fail. These tests passed in CI on this PR;
    • I also ran -k TestInferenceAPIsRequests in a process where socket.socket.connect and socket.create_connection raise: 2 passed.

    JSON-configured providers take the OpenAI SDK path, which builds its client on litellm.client_session; that is the seam used here.

@greptileai

@greptile-apps

greptile-apps Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

You're right. I rechecked the revised test seam and the provider dispatch: JSON providers default to the OpenAIGPTConfig path, which uses litellm.client_session; the MockTransport records the request, each test requires len(sent) == 1, and the socket guard independently confirms there is no network fallback. My earlier claim that this path bypasses the injected client was incorrect. I retract the P1 finding; the revised tests do not make real provider calls.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@TaylorHawkes

Copy link
Copy Markdown
Author

Pushed b7b6adb, a separate 3-line commit: uv lock --upgrade-package soupsieve (2.8.4 -> 2.9.2), only the soupsieve stanza of uv.lock changes.

osv-scan fails on every PR whose lock still pins soupsieve 2.8.4 (GHSA-gjv8-xp57-g29c, GHSA-j934-xhv5-fg8f, fixed in 2.9.0). Locally, with the workflow's pinned osv-scanner v2.3.8 and the same command: No issues found; uv lock --check passes.

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.

@TaylorHawkes

Copy link
Copy Markdown
Author

Dropped b7b6adb (the uv.lock soupsieve bump). I had not seen the "Block fork dependency changes" rule; lockfile changes belong in a branch of this repository, so the PR is back to 0ae0ceb and touches no dependency files.

That leaves osv-scan red for the reason above: main still pins soupsieve 2.8.4, and #41679 fixes it. Once that lands I will update this branch.

@TaylorHawkes
TaylorHawkes force-pushed the feat/add-inferenceapis-provider branch from b7b6adb to 0ae0ceb Compare September 17, 2026 23:05
TaylorHawkes and others added 3 commits September 18, 2026 08:40
…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.
@greptile-apps

greptile-apps Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): Scope: The rule applies because the PR changes litellm/llms/openai_like/providers.json. That change adds a JSON-configured provider and routes its chat, responses and messages calls to native upstream endpoints. The PR also changes extra_body handling for every JSON provider in litellm/utils.py.

Evidence that qualifies: The PR description includes inspectable manual E2E proof against the real Inference APIs on commit 353c701bfe. It covers the proxy config, curl steps and raw outputs for /v1/chat/completions (plain and streaming), /v1/responses (plain, streaming and tool call), /v1/messages, alias billing, top_k sent through extra_body, and a real 150K-token overflow that maps to ContextWindowExceededError and triggers context_window_fallbacks. GitHub compare 353c701bfe...4795f60584 shows that the two later commits change only tests/integration/providers/test_inferenceapis_context_window_fallbacks_wire.py, so the reviewed product code matches the code that was tested.

Fixture provenance: The integration tests use the overflow string Input too long: 150055 input tokens, limit is 131072 for this model, which matches the real upstream error in the PR's raw output.

Tests I ran:

  • uv run pytest tests/unit/llms/openai_like/test_inferenceapis_provider.py tests/unit/litellm_core_utils/test_exception_mapping_utils.py: 1514 passed. One responses test failed until I ran uv sync --all-extras, because the mcp module was missing from my environment; with the extras installed, the inferenceapis file passed 11/11.
  • PYTHONPATH=. uv run pytest integration/sdk/test_provider_error_and_extra_body_families_wire.py: 106 passed.
  • Passed · Cost map matches vendor catalog (optional): I fetched https://api.inferenceapis.com/v1/models and compared it with all 36 inferenceapis/* entries in the cost map. Input, output and cached-input prices, context lengths and vision flags all match their canonical model. The only differences were float-rounding artifacts. Every chat model and alias resolves to a canonical model. Backup JSON copies of the cost map and provider endpoints match the primary files.
  • Not run · CI status at head (optional): At 4795f60584, most GitHub check runs report success. Some were still in_progress when I checked, including router, python, llms-openai-meta and proxy-endpoints. The gateway integration tests need a proxy and Postgres, and I did not run them locally.

View review · Reviewed 4795f60584c3

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

…report context overflow as ContextWindowExceededError
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

…ead of any context_length_exceeded substring
@mateo-berri

Copy link
Copy Markdown
Contributor

@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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous 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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous 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
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution!

@mateo-berri
mateo-berri merged commit fd84e97 into BerriAI:main Oct 15, 2026
96 checks passed
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.

3 participants