# API quickstart (https://inference.net/docs/api/quickstart)

The Inference.net API is OpenAI-compatible, so you can use the OpenAI SDK or plain HTTP to make requests. There are two ways to use it:

1. **Call a model serverless**: call open-source models and popular closed-source models (GPT, Claude, Gemini) with just your Inference.net API key. Credit-billing keys bill usage per token to your credit balance; [Inference Pass plan keys](/docs/api-keys/#plan-keys) draw from your plan allowance first (and only draw from prepaid API credits if your team enables prepaid overage and the allowance is used up).
2. **Proxy through the Inference.net Gateway**: route requests to any provider (OpenAI, Anthropic, etc.) through the Inference.net Gateway with your own provider API key.

Both paths use the same base URL. Path 2 requires a key that bills API credits.

<Callout tone="info">

Path 1 needs only your Inference.net API key and base URL `https://api.inference.net/v1` (US-only: `https://us.api.inference.net/v1`). The `x-inference-provider*` headers are only for path 2, where you proxy your own provider key. To use Inference.net models in OpenCode, Claude Code, Codex, or another coding agent, see [Coding agents](/docs/integrations/overview/).

</Callout>

## Get an API key

<Steps>
  <Step title="Create an account">

Create an account at [/register](/register/), or [sign in](/signin/) with an existing account.

  </Step>
  <Step title="Create an API key">

Open [API keys](/dashboard/api-keys/) in the dashboard and create a new key. If
you hold an active Inference Pass plan in that team, new keys default to a
[plan key](/docs/api-keys/#plan-keys): team owners and admins can switch **Uses**
to API credits (needed for Batch, Files, async, Group, or gateway passthrough
requests), while other members with an active plan can create plan keys only.

  </Step>
  <Step title="Set the environment variable">

```bash
export INFERENCE_API_KEY=<your-api-key>
```

  </Step>
</Steps>

## 1. Call a model serverless

Call models with just your Inference.net API key. No provider API key is needed. This works for two kinds of models:

- **Open-source models** hosted on Inference.net, such as `glm-5.2`.
- **Popular closed-source models**, such as `claude-haiku-4-5`, `gpt-5-mini`, and `gemini-3.5-flash`. Inference.net routes the request to the provider for you, billing per token to your credit balance for credit-billing keys, or drawing from your plan allowance first (with optional prepaid overage billed to API credits once exhausted, if enabled) for [plan keys](/docs/api-keys/#plan-keys).

Browse available models in the [model catalog](/models/), or list them with `GET https://api.inference.net/v1/models`.

Some models are privileged. They have `"requires_approved_access": true` in `GET /v1/models`, and your team must be approved before it can call them. See [Privileged model access](/docs/api/privileged-model-access/).

For US-only inference, use `https://us.api.inference.net/v1`. It has the same API, and requests are handled by US data centers end to end: US Cloudflare edge, US routing, and US-hosted GPU capacity. Not every model is served in the US. Models with a `US` badge in the Regions column of the [model catalog](/models/) are. See [Regional endpoints](#regional-endpoints) for base URLs, third-party caveats, and retries.

Prefer the Anthropic SDK? The API also supports the Anthropic Messages format. See [Anthropic SDK](/docs/api/anthropic-sdk/).

<CodeTabs>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
});

const response = await client.chat.completions.create({
  model: "glm-5.2",
  messages: [{ role: "user", content: "What is the meaning of life?" }],
  stream: true,
});

for await (const chunk of response) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
)

response = client.chat.completions.create(
    model="glm-5.2",
    messages=[{"role": "user", "content": "What is the meaning of life?"}],
    stream=True,
)

for chunk in response:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

```rust
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("INFERENCE_API_KEY")?;

    let response: Value = reqwest::Client::new()
        .post("https://api.inference.net/v1/chat/completions")
        .bearer_auth(api_key)
        .json(&json!({
            "model": "glm-5.2",
            "messages": [
                {"role": "user", "content": "What is the meaning of life?"}
            ]
        }))
        .send()
        .await?
        .json()
        .await?;

    println!(
        "{}",
        response["choices"][0]["message"]["content"]
            .as_str()
            .unwrap_or_default()
    );
    Ok(())
}
```

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"model": "glm-5.2",
		"messages": []map[string]string{
			{"role": "user", "content": "What is the meaning of life?"},
		},
	})

	req, _ := http.NewRequest("POST", "https://api.inference.net/v1/chat/completions", bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("INFERENCE_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var result struct {
		Choices []struct {
			Message struct {
				Content string `json:"content"`
			} `json:"message"`
		} `json:"choices"`
	}
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result.Choices[0].Message.Content)
}
```

```bash
curl -N https://api.inference.net/v1/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.2",
    "messages": [
      {"role": "user", "content": "What is the meaning of life?"}
    ],
    "stream": true
  }'
```

</CodeTabs>

The same code works for every serverless model. Set `model` to the model ID you want, for example `claude-haiku-4-5`. This includes the purpose-built [Schematron](/docs/api/models/schematron/) models for structured data extraction.

## 2. Proxy through the Inference.net Gateway

Route requests to any LLM provider (OpenAI, Anthropic, Groq, etc.) through the Inference.net Gateway. You keep your existing provider API key, and the provider bills you directly. The gateway adds roughly 10ms of latency.

Use this path when you want a model that is not in the serverless catalog, or when you want usage billed to your own provider account.

Your Inference.net API key authenticates with the gateway. Your provider API key is forwarded to the provider via the `x-inference-provider-api-key` header.

<CodeTabs>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
  defaultHeaders: {
    "x-inference-provider-api-key": process.env.OPENAI_API_KEY,
    "x-inference-provider": "openai",
  },
});

const response = await client.chat.completions.create({
  model: "gpt-4.1",
  messages: [{ role: "user", content: "What is the meaning of life?" }],
});

console.log(response.choices[0].message.content);
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
    default_headers={
        "x-inference-provider-api-key": os.environ["OPENAI_API_KEY"],
        "x-inference-provider": "openai",
    },
)

response = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "What is the meaning of life?"}],
)

print(response.choices[0].message.content)
```

```bash
curl https://api.inference.net/v1/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "x-inference-provider-api-key: $OPENAI_API_KEY" \
  -H "x-inference-provider: openai" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {"role": "user", "content": "What is the meaning of life?"}
    ]
  }'
```

</CodeTabs>

<Callout tone="info">

For setup guides per provider (Anthropic, Groq, Cerebras, OpenRouter, and more), see the [provider integration docs](https://docs.inference.net/integrations/overview).

</Callout>

## 3. Call your deployment

Hit a dedicated model you've deployed on Inference.net. The model path is your team slug followed by the deployment slug (copy the model identifier shown on your deployment's detail page in the dashboard).

<CodeTabs>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
});

const response = await client.chat.completions.create({
  model: "your-team/your-model",
  messages: [{ role: "user", content: "Hello, world!" }],
});

console.log(response.choices[0].message.content);
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
)

response = client.chat.completions.create(
    model="your-team/your-model",
    messages=[{"role": "user", "content": "Hello, world!"}],
)

print(response.choices[0].message.content)
```

```bash
curl https://api.inference.net/v1/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-team/your-model",
    "messages": [
      {"role": "user", "content": "Hello, world!"}
    ]
  }'
```

</CodeTabs>

<Callout tone="info">

Learn more about deploying dedicated models in the [Deploy docs](https://docs.inference.net/platform/deploy/overview).

</Callout>

## Regional endpoints

Choose an endpoint based on where you want requests to run:

| API base URL | Where requests run |
| --- | --- |
| `https://api.inference.net/v1` | Any eligible GPU, in any country. |
| `https://us.api.inference.net/v1` | Only GPUs located in the United States, for models hosted by Inference.net. GPUs outside the US or with an unknown location are not used. |

Both endpoints use the same API keys, model IDs, and request formats. To use the US-only endpoint, change the base URL. You do not need a region parameter or an extra header.

On the US-only endpoint, requests are handled in the US end to end:

- **Edge:** Cloudflare terminates TLS and handles the request only in US data centers.
- **Routing:** requests for models that Inference.net hosts are routed only to US-hosted GPU capacity.
- **Inference:** those models run on a GPU located in the US.

<Callout tone="info">

The US-only endpoint serves only models with a US-capable Inference.net-hosted route: public serverless models carrying the `US` badge in the [model catalog](/models/), and dedicated hosted deployments (which are not listed in the public catalog and are filtered by worker region when routed on `us.api.inference.net`). Third-party-only models such as GPT, Claude, and Gemini are not supported on `us.api.inference.net`, and requests for unsupported models return HTTP `400` with `error.code: "region_not_supported"`. Hosted models also do not fall back to external third-party providers on `us.api.inference.net`; external fallback applies only on the global `api.inference.net` endpoint.

</Callout>

<CodeTabs>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://us.api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
});

const response = await client.chat.completions.create({
  model: "deepseek-v4.1-flash-1017",
  messages: [{ role: "user", content: "What is the meaning of life?" }],
});

console.log(response.choices[0].message.content);
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://us.api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
)

response = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017",
    messages=[{"role": "user", "content": "What is the meaning of life?"}],
)

print(response.choices[0].message.content)
```

```bash
curl https://us.api.inference.net/v1/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash-1017",
    "messages": [{"role": "user", "content": "What is the meaning of life?"}]
  }'
```

</CodeTabs>

### Regional base URLs

| Setting | Global | US-only |
| --- | --- | --- |
| OpenAI-compatible base URL | `https://api.inference.net/v1` | `https://us.api.inference.net/v1` |
| Anthropic Messages base URL | `https://api.inference.net` | `https://us.api.inference.net` |

To use the US-only endpoint with the [Anthropic SDK](/docs/api/anthropic-sdk/), set `baseURL` (TypeScript) or `base_url` (Python) to `https://us.api.inference.net`.

To use it in LiteLLM or an OpenAI-compatible [coding agent](/docs/integrations/overview/), set the provider base URL to `https://us.api.inference.net/v1`. For Bifrost (which appends `/v1` automatically), set `base_url` to `https://us.api.inference.net` without `/v1`. Model IDs do not change.

To keep requests in the US, send retries to `us.api.inference.net` too. A retry sent to `api.inference.net` can run outside the US.

## Headers reference

| Header                         | Required   | Description                                                                                                                                                                                                                                                      |
| ------------------------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Authorization`                | Yes        | `Bearer <your-api-key>`. Authenticates the request. For OpenAI-compatible SDKs, set this as the SDK's `apiKey`.                                                                                                                                                  |
| `Content-Type`                 | Yes        | Must be `application/json`.                                                                                                                                                                                                                                      |
| `x-inference-provider`         | Proxy only | Routes the request to the correct provider: `openai`, `anthropic`, `cerebras`, `vertex-ai`, `gemini`, etc. For providers without a dedicated value that require it (for example Groq or Together AI), route by base URL instead with `x-inference-provider-url`. |
| `x-inference-provider-api-key` | Proxy only | Your provider's API key. The gateway forwards it downstream. For Anthropic's native SDK, use `x-api-key` instead.                                                                                                                                                |
| `x-inference-provider-url`     | No         | Routes to any OpenAI-compatible provider by base URL, even if it doesn't have a dedicated integration. Must be `http` or `https` without embedded credentials, and most Inference.net-owned hosts are refused; the gateway returns `400` for a URL that breaks these rules. |
| `x-inference-environment`      | No         | Works on every path. Tags requests with an environment label, such as `production` or `staging`.                                                                                                                                                                 |
| `x-inference-task-id`          | No         | Works on every path. Groups requests under a logical task. See [Tasks](/docs/api/tasks/).                                                                                                                                                                         |
| `x-inference-metadata-*`       | No         | Works on every path. Attach arbitrary metadata to a request. The gateway removes the prefix to make the key. For example, `x-inference-metadata-chat-id: abc123` stores `chat-id: abc123`.                                                                       |

## Supported request parameters

The API supports the standard OpenAI chat completions parameters:

| Parameter           | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`             | `string`  | The model to use.                                                                                                                                                                                                                                                                                                                                                                                                         |
| `messages`          | `array`   | The conversation messages.                                                                                                                                                                                                                                                                                                                                                                                                |
| `stream`            | `boolean` | Whether to stream the response.                                                                                                                                                                                                                                                                                                                                                                                           |
| `max_tokens`        | `integer` | Maximum number of tokens to generate.                                                                                                                                                                                                                                                                                                                                                                                     |
| `temperature`       | `number`  | Sampling temperature (0-2). `glm-5.3`, `glm-5.3-flash`, and `z-ai/glm-5.3-fast` always think and always sample at 1.0, their model card value, whatever you send. `deepseek-v4.1-flash` and `deepseek-v4.1-flash-1017` sample at 1.0 when they think; with thinking off ([Reasoning](/docs/api/reasoning/)) they keep your temperature. Below 1.0 these models can repeat themselves while thinking until `max_tokens`; their first-party APIs fix the temperature the same way. |
| `top_p`             | `number`  | Nucleus sampling threshold.                                                                                                                                                                                                                                                                                                                                                                                               |
| `frequency_penalty` | `number`  | Penalizes repeated tokens based on frequency.                                                                                                                                                                                                                                                                                                                                                                             |
| `presence_penalty`  | `number`  | Penalizes tokens based on whether they've appeared.                                                                                                                                                                                                                                                                                                                                                                       |
| `response_format`   | `object`  | Set to `{"type": "json_object"}` or a JSON schema for [structured outputs](/docs/api/structured-outputs/).                                                                                                                                                                                                                                                                                                                 |
| `tools`             | `array`   | Tool/function definitions for [function calling](/docs/api/function-calling/).                                                                                                                                                                                                                                                                                                                                             |
| `service_tier`      | `string`  | `"priority"` (alias `"fast"`) serves the request from the model's fast tier, where one exists, at that tier's pricing; the response then reports `"service_tier": "priority"`. Fast tiers: `moonshotai/kimi-k3` (served as `moonshotai/kimi-k3-fast`) and `glm-5.3` (served as `z-ai/glm-5.3-fast`, 65,536-token context). Other values use the standard tier.                                                            |

<Callout tone="info">

Need a parameter that isn't listed here? [Contact us](mailto:support@inference.net) and we'll add it.

</Callout>

## Next steps

<CardGroup>
  <Card title="Coding agents" href="/docs/integrations/overview/">
    Use Inference.net models in Claude Code, Codex, OpenCode, and other coding agents.
  </Card>
  <Card title="Structured outputs" href="/docs/api/structured-outputs/">
    Get typed JSON responses from your API calls.
  </Card>
  <Card title="Batch processing" href="/docs/api/async/batch/">
    Process up to 1,000,000 requests in a single batch job.
  </Card>
  <Card title="Browse models" href="/models/">
    Explore all models available on Inference.net.
  </Card>
</CardGroup>