LiteLLM
Call Inference.net models from the LiteLLM Python SDK or LiteLLM Proxy with OpenAI-compatible config and US-only routing.
Last updated
Connect LiteLLM to Inference.net through LiteLLM's OpenAI-compatible provider using api_base="https://api.inference.net/v1", your Inference.net API key, and the openai/<model-id> prefix. LiteLLM strips the leading openai/ prefix and forwards the exact model ID to Inference.net with no custom adapter required.
Quick configuration
Create an account at /register and generate a project key in API keys.
| Setting | Value |
|---|---|
| API base | https://api.inference.net/v1 |
| API base (US-only) | https://us.api.inference.net/v1 |
| API key | INFERENCE_API_KEY |
| Model format | openai/<model-id>, for example openai/deepseek-v4.1-flash-1017 |
export INFERENCE_API_KEY="inf_sk_..."LiteLLM Python SDK
Install LiteLLM
bashpip install litellmSend a chat completion
pythonimport os from litellm import completion response = completion( model="openai/deepseek-v4.1-flash-1017", api_base="https://api.inference.net/v1", api_key=os.environ["INFERENCE_API_KEY"], messages=[{"role": "user", "content": "Explain prompt caching in one sentence."}], max_tokens=256, ) print(response.choices[0].message.content)Stream responses with token usage
pythonimport os from litellm import completion stream = completion( model="openai/glm-5.3", api_base="https://api.inference.net/v1", api_key=os.environ["INFERENCE_API_KEY"], messages=[{"role": "user", "content": "List three benefits of prefix caching."}], max_tokens=512, stream=True, stream_options={"include_usage": True}, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) usage = getattr(chunk, "usage", None) if usage is not None: print("\nUsage:", usage.model_dump())
Tag SDK requests with task and environment headers
Pass optional Inference.net headers in extra_headers to group requests in Usage:
response = completion(
model="openai/deepseek-v4.1-flash-1017",
api_base="https://api.inference.net/v1",
api_key=os.environ["INFERENCE_API_KEY"],
messages=[{"role": "user", "content": "Summarize this support ticket."}],
extra_headers={
"x-inference-task-id": "summarize-ticket",
"x-inference-environment": "production",
},
)LiteLLM Proxy
Use LiteLLM Proxy to expose verified Inference.net models to internal services and editors behind one centralized key.
Create config.yaml
Add your models under
model_list. The example below defines standard aliases plus a US-only alias forglm-5.3:yamlmodel_list: - model_name: deepseek-v4.1-flash litellm_params: model: openai/deepseek-v4.1-flash-1017 api_base: https://api.inference.net/v1 api_key: os.environ/INFERENCE_API_KEY - model_name: kimi-k3.1-pro litellm_params: model: openai/moonshotai/kimi-k3.1-pro api_base: https://api.inference.net/v1 api_key: os.environ/INFERENCE_API_KEY - model_name: glm-5.3-us litellm_params: model: openai/glm-5.3 api_base: https://us.api.inference.net/v1 api_key: os.environ/INFERENCE_API_KEY extra_headers: x-inference-environment: production general_settings: master_key: os.environ/LITELLM_MASTER_KEY forward_client_headers_to_llm_api: trueforward_client_headers_to_llm_api: truelets downstream apps send per-requestx-inference-task-idorx-inference-environmentheaders through the proxy.Start the proxy
bashpip install "litellm[proxy]" export LITELLM_MASTER_KEY="sk-$(openssl rand -hex 24)" litellm --config config.yaml --host 127.0.0.1 --port 4000Call the proxy
Send requests to your local proxy using the
model_namealias fromconfig.yaml:import OpenAI from "openai"; const client = new OpenAI({ baseURL: "http://127.0.0.1:4000/v1", apiKey: process.env.LITELLM_MASTER_KEY, }); const response = await client.chat.completions.create({ model: "deepseek-v4.1-flash", messages: [{ role: "user", content: "Say hello in one sentence." }], }); console.log(response.choices[0].message.content);import os from openai import OpenAI client = OpenAI( base_url="http://127.0.0.1:4000/v1", api_key=os.environ["LITELLM_MASTER_KEY"], ) response = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Say hello in one sentence."}], ) print(response.choices[0].message.content)curl http://127.0.0.1:4000/v1/chat/completions \ -H "Authorization: Bearer $LITELLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-v4.1-flash", "messages": [{"role": "user", "content": "Say hello in one sentence."}] }'
Verified model IDs for LiteLLM
| Inference.net model ID | LiteLLM model value | Model page |
|---|---|---|
deepseek-v4.1-flash-1017 | openai/deepseek-v4.1-flash-1017 | DeepSeek V4.1 Flash |
glm-5.3 | openai/glm-5.3 | GLM 5.3 |
glm-5.3-flash | openai/glm-5.3-flash | GLM 5.3 Flash |
moonshotai/kimi-k3.1-pro | openai/moonshotai/kimi-k3.1-pro | Kimi K3.1 Pro |
inference-net/schematron-v2-turbo | openai/inference-net/schematron-v2-turbo | Schematron V2 Turbo |
Optional: bring your own provider key
To route requests to an external provider through the Inference.net Gateway with your own provider credentials (requires a credit-billing API key), add x-inference-provider and x-inference-provider-api-key under extra_headers. See API quickstart for gateway passthrough headers.
Troubleshooting
LLM Provider NOT providederror: Prefix every Inference.net model ID withopenai/in LiteLLM (openai/deepseek-v4.1-flash-1017).404or HTML response: Verifyapi_baseishttps://api.inference.net/v1(with/v1), nothttps://inference.net/v1.region_not_supported(400): Only models with aUSbadge in the model catalog run onhttps://us.api.inference.net/v1.- Proxy fails to start: Set
LITELLM_MASTER_KEYbefore startinglitellm --config config.yaml.
See all supported editors, gateways, and SDKs in the Integrations hub.