Skip to contentNewKimi K3.1 Pro is now availableTry it now
Docs / LiteLLM

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.

SettingValue
API basehttps://api.inference.net/v1
API base (US-only)https://us.api.inference.net/v1
API keyINFERENCE_API_KEY
Model formatopenai/<model-id>, for example openai/deepseek-v4.1-flash-1017
bash
export INFERENCE_API_KEY="inf_sk_..."

LiteLLM Python SDK

  1. Install LiteLLM

    bash
    pip install litellm
  2. Send a chat completion

    python
    import 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)
  3. Stream responses with token usage

    python
    import 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:

python
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.

  1. Create config.yaml

    Add your models under model_list. The example below defines standard aliases plus a US-only alias for glm-5.3:

    yaml
    model_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: true

    forward_client_headers_to_llm_api: true lets downstream apps send per-request x-inference-task-id or x-inference-environment headers through the proxy.

  2. Start the proxy

    bash
    pip install "litellm[proxy]"
    export LITELLM_MASTER_KEY="sk-$(openssl rand -hex 24)"
    litellm --config config.yaml --host 127.0.0.1 --port 4000
  3. Call the proxy

    Send requests to your local proxy using the model_name alias from config.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);

Verified model IDs for LiteLLM

Inference.net model IDLiteLLM model valueModel page
deepseek-v4.1-flash-1017openai/deepseek-v4.1-flash-1017DeepSeek V4.1 Flash
glm-5.3openai/glm-5.3GLM 5.3
glm-5.3-flashopenai/glm-5.3-flashGLM 5.3 Flash
moonshotai/kimi-k3.1-proopenai/moonshotai/kimi-k3.1-proKimi K3.1 Pro
inference-net/schematron-v2-turboopenai/inference-net/schematron-v2-turboSchematron 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 provided error: Prefix every Inference.net model ID with openai/ in LiteLLM (openai/deepseek-v4.1-flash-1017).
  • 404 or HTML response: Verify api_base is https://api.inference.net/v1 (with /v1), not https://inference.net/v1.
  • region_not_supported (400): Only models with a US badge in the model catalog run on https://us.api.inference.net/v1.
  • Proxy fails to start: Set LITELLM_MASTER_KEY before starting litellm --config config.yaml.

See all supported editors, gateways, and SDKs in the Integrations hub.