# LiteLLM (https://inference.net/docs/integrations/litellm)

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](/register/) and generate a project key in [API keys](/dashboard/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` |

```bash
export INFERENCE_API_KEY="inf_sk_..."
```

<Callout title="Model IDs that contain a slash" tone="info">

Keep the full Inference.net model ID after `openai/`. For example, `moonshotai/kimi-k3.1-pro` becomes `openai/moonshotai/kimi-k3.1-pro`, and `inference-net/schematron-v2-turbo` becomes `openai/inference-net/schematron-v2-turbo`. LiteLLM strips only the leading `openai/`.

</Callout>

## LiteLLM Python SDK

<Steps>
  <Step title="Install LiteLLM">

```bash
pip install litellm
```

  </Step>
  <Step title="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)
```

  </Step>
  <Step title="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())
```

  </Step>
</Steps>

### Tag SDK requests with task and environment headers

Pass optional Inference.net headers in `extra_headers` to group requests in [Usage](/dashboard/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.

<Steps>
  <Step title="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.

  </Step>
  <Step title="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
```

  </Step>
  <Step title="Call the proxy">

Send requests to your local proxy using the `model_name` alias from `config.yaml`:

<CodeTabs>

```typescript
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);
```

```python
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
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."}]
  }'
```

</CodeTabs>

  </Step>
</Steps>

## 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](/models/deepseek-v4-1-flash-1017/) |
| `glm-5.3` | `openai/glm-5.3` | [GLM 5.3](/models/glm-5-3/) |
| `glm-5.3-flash` | `openai/glm-5.3-flash` | [GLM 5.3 Flash](/models/glm-5-3-flash/) |
| `moonshotai/kimi-k3.1-pro` | `openai/moonshotai/kimi-k3.1-pro` | [Kimi K3.1 Pro](/models/kimi-k3-1-pro/) |
| `inference-net/schematron-v2-turbo` | `openai/inference-net/schematron-v2-turbo` | [Schematron V2 Turbo](/models/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](/docs/api/quickstart/#2-proxy-through-the-inferencenet-gateway) 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](/models/) 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](/docs/integrations/).