API quickstart
Call hosted models with your Inference.net API key, or proxy requests to your own provider through the Inference.net Gateway.
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:
- Call a model serverless: call open-source models and popular closed-source models (GPT, Claude, Gemini) with just your Inference.net API key. Usage is billed per token to your credit balance.
- 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 and the same Inference.net API key.
Get an API key
Create an API key
Open API keys in the dashboard. Create a new key.
Set the environment variable
bashexport INFERENCE_API_KEY=<your-api-key>
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, andgemini-3.5-flash. Inference.net routes the request to the provider for you and bills the usage per token to your credit balance.
Browse available models in the model catalog, 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.
For US-only inference, use https://us.api.inference.net/v1: same API and same models, but requests are handled by US data centers end to end: US Cloudflare edge, US routing, and US-hosted GPU capacity.
Prefer the Anthropic SDK? The API also supports the Anthropic Messages format. See Anthropic SDK.
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 || "");
}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 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.
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);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. |
x-inference-environment | No | Works on both paths. Tags requests with an environment label, such as production or staging. |
x-inference-task-id | No | Works on both paths. Groups requests under a logical task. See Tasks. |
x-inference-metadata-* | No | Works on both paths. 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 and glm-5.3-flash always think and always sample at 1.0, their model card value, whatever you send. deepseek-v4.1-flash samples at 1.0 when it thinks; with thinking off (Reasoning) it keeps 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. |
tools | array | Tool/function definitions for 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. |