# Asynchronous inference (https://inference.net/docs/api/async/overview)

The OpenAI-compatible Asynchronous Inference API accepts individual inference
requests that complete within 24 hours at reduced cost. Use `/v1/slow` instead
of `/v1` in your API calls.

Background inference is cheaper, and easier to build with when your application
isn't serving real-time inference.

<Callout tone="info">

The Asynchronous Inference API works with every model in the
[model catalog](/models/).

</Callout>

<Callout tone="warning">

Webhook support is available for all slow endpoints: `/chat/completions`,
`/completions`, and `/embeddings` calls.

</Callout>

<Callout tone="warning">

With the **Zero Data Retention (ZDR)** team setting on, a `/v1/slow` request
must set `metadata.webhook_id` to an enabled webhook identifier from
[**Settings → Webhooks**](/dashboard/settings/webhooks/), or it returns
`400 Bad Request`. The result is delivered only to the
[webhook](/docs/api/async/webhooks/). Once delivery succeeds, its retries run
out, or the webhook can no longer be delivered, the request and response
content is purged. If you miss the webhook, the result cannot be fetched again.

Batch (`/v1/batches`) and file upload (`/v1/files`) requests return
`403 Forbidden` while ZDR is on. Group (`/v1/slow/group/*`) requests need a
webhook and deliver their results only to it. See
[Data retention](/docs/data-retention/#retention-and-groups).

</Callout>

## How it works

The Asynchronous Inference API is a simple way to make cost-effective inference
requests when you don't need an immediate response. With the `/v1/slow` prefix
instead of `/v1`, you:

1. **Get a request ID immediately:** your API call returns at once with a unique ID.
2. **Save on cost:** pricing is significantly lower than synchronous requests.
3. **Get flexible completion:** requests complete within 24 hours.
4. **Use the same API:** the request format is the same as the standard endpoints.

Good fits include:

- Large-scale content generation
- Batch document processing
- Non-urgent data analysis
- Cost-sensitive workloads
- Background processing tasks

## Get started

Change your base URL from `/v1/` to `/v1/slow/`. The API stays fully compatible
with the OpenAI SDK, and the same credit-billing API key works for both. Plan
keys cannot submit `/v1/slow` requests or read Group status and results (they
return `403 plan_route_not_supported`); use a key that bills API credits instead
(see [plan keys](/docs/api-keys/#plan-keys)).

<CodeTabs>

```typescript
import OpenAI from "openai";

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

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1/slow",  # Note the /v1/slow prefix
    api_key=os.environ["INFERENCE_API_KEY"],
)
```

```bash
# Use /v1/slow/ instead of /v1/ in the URL
curl https://api.inference.net/v1/slow/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ ... }'
```

</CodeTabs>

## Make an asynchronous request

### Submit a request

Make requests exactly as you would with the standard API. The response includes
a request ID instead of the completion result:

<CodeTabs>

```typescript
const response = await client.chat.completions.create({
  model: "kimi-k3-fast",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "What is the capital of France?" },
  ],
  max_tokens: 1000,
});

console.log(response.id); // Returns immediately with request ID
```

```python
response = client.chat.completions.create(
    model="kimi-k3-fast",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"},
    ],
    max_tokens=1000,
)

print(response.id)  # Returns immediately with request ID
```

```bash
curl https://api.inference.net/v1/slow/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3-fast",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ],
    "max_tokens": 1000
  }'
```

</CodeTabs>

The initial response includes a unique request ID:

```json
{
  "id": "N2mZQjrvh-k_m8nMMN7Jn",
  "choices": [],
  "created": 1749061362809,
  "model": "kimi-k3-fast",
  "object": "chat.completion"
}
```

#### Calling from a Cloudflare Worker

Cloudflare allows a request to pass through at most 16 Workers. If your call reaches the API after too many Worker-to-Worker or service-binding hops on your side, the API cannot forward it through Cloudflare Workers. When a route outside Cloudflare Workers is available, the API may send an async or slow `POST` once by that route instead. Otherwise it returns HTTP `508`:

```json
{
  "error": {
    "message": "The request reached inference.net through too many Cloudflare Worker hops, so it could not be forwarded. ...",
    "type": "subrequest_depth_exceeded",
    "request_id": "5f0c2a7e-3b1d-4c8e-9a6f-2d4e8b1c7a90"
  }
}
```

A `508` means no request was created. A retry through the same chain can fail the same way: send the request from a point with fewer Worker hops before it, for example directly from the Worker that receives your traffic. If the API sent the request by the other route and that failed, you get a different `5xx` error. That request may have been created, so check for it before you send it again.

### Retrieve the result

Once the request is processed, retrieve the result from the generation endpoint.

<Callout tone="info">

A finished request's content is kept only until it is delivered. With a
webhook, take the result from the webhook: the content is deleted once the
event is delivered or its retries run out. Without a webhook, fetch the result
as soon as the state is final: the content is deleted soon after. See
[Data retention](/docs/data-retention/#asynchronous-results-are-kept-until-delivery-finishes).

</Callout>

<Callout tone="warning">

With ZDR on, take the result from the webhook. Once webhook delivery succeeds
or its retries run out, this endpoint returns the generation with its request
and response content purged. State, model, usage, and timestamps remain.

</Callout>

<CodeTabs>

```typescript
const response = await fetch(
  `https://api.inference.net/v1/generation/${generationId}`,
  {
    headers: {
      Authorization: `Bearer ${process.env.INFERENCE_API_KEY}`,
    },
  },
);
const result = await response.json();
```

```python
import os
import requests

response = requests.get(
    f"https://api.inference.net/v1/generation/{generation_id}",
    headers={"Authorization": f"Bearer {os.environ['INFERENCE_API_KEY']}"},
)
result = response.json()
```

```bash
curl https://api.inference.net/v1/generation/N2mZQjrvh-k_m8nMMN7Jn \
  -H "Authorization: Bearer $INFERENCE_API_KEY"
```

</CodeTabs>

The completed response includes both the original request and the generation
result:

<Callout tone="info">
  Once the generation finishes, each image URL in a chat `image_url` part or an image embedding input of `request` reads `"REDACTED"`, unless the request sets its own `metadata.webhook_id`.
</Callout>

```json
{
  "request": {
    "messages": [
      { "content": "You are a helpful assistant.", "role": "system" },
      { "content": "What is the meaning of life?", "role": "user" }
    ],
    "model": "kimi-k3-fast",
    "stream": false,
    "max_tokens": 8,
    "metadata": { "webhook_id": "mPufxRcrw" }
  },
  "response": {
    "id": "N2mZQjrvh-k_m8nMMN7Jn",
    "object": "chat.completion",
    "created": 1749061362,
    "model": "kimi-k3-fast",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "The meaning of life is a complex and",
          "reasoning_content": null,
          "tool_calls": null
        },
        "logprobs": null,
        "finish_reason": "length",
        "matched_stop": null
      }
    ],
    "usage": {
      "prompt_tokens": 48,
      "total_tokens": 56,
      "completion_tokens": 8,
      "prompt_tokens_details": null
    },
    "system_fingerprint": ""
  },
  "state": "Success",
  "stateMessage": "Generation successful",
  "error": null,
  "finishedAt": "2025-06-04T18:22:42.912Z",
  "deadlineAt": null
}
```

## Completion window

By default an asynchronous request completes within 24 hours. To get the result
sooner, set `metadata.completion_window` to how long you can wait, from
submission to [webhook](/docs/api/async/webhooks-reference/#retry-schedule) delivery:

```json JSON
{
  "model": "google/gemma-3-27b-instruct/bf-16",
  "messages": [{"role": "user", "content": "What is the capital of France?"}],
  "metadata": {"webhook_id": "mPufxRcrw", "completion_window": "4m"}
}
```

- The value is a string: an integer and a unit, `ms`, `s`, `m`, or `h` (for
  example `"90s"`, `"4m"`, `"24h"`), from `60s` to `72h`.
- Any other value is ignored: the request is accepted without a window from
  `metadata`, as if the field were absent.
- The submit response, the webhook payload, and the generation status endpoint
  return the resulting deadline. The submit response has `deadline_at` (Unix
  seconds); the generation object has `deadlineAt` (ISO 8601).
- A request without `metadata.completion_window` can still get a deadline from
  a default set on its endpoint. A request with neither returns no
  `deadline_at` and has `deadlineAt: null`.

A window of 1 hour or less changes how the request is handled:

1. It is dispatched ahead of requests with a later deadline or none, and
   queued requests of the same model wait while it waits for capacity.
2. While the model is busy, its retry wait is capped by the time left: at most
   1/16 of what remains of the window, never longer than the normal backoff
   (up to a minute). A 4-minute window retries about every 5 to 13 seconds.
3. A failed webhook delivery is retried several times inside the window, then
   on the normal [retry schedule](/docs/api/async/webhooks-reference/#retry-schedule).

A longer window is accepted and returned as the deadline, but is handled like a
request without one. A queued request whose deadline has passed settles as
`Failed` (`stateMessage: "Inference expired"`) instead of running. A request
actively running at its deadline is not cancelled. If an in-progress request has
no worker claim, its deadline has passed, and the time since its last `updatedAt`
update exceeds the configured recovery interval, reconciliation can settle it as
`Failed` (`stateMessage: "Inference expired"`). This interval accounts for the
dispatch attempt timeout and the time for its claim to expire. It is not a fixed
delay after the deadline.

### Worked example: a 4-minute window

The request is submitted at 0:00 with `"completion_window": "4m"`, so its
deadline is 4:00. The model finishes at 0:30, and your endpoint fails until
attempt 5. Nominal webhook attempt times (each wait varies by up to 20%):

| Attempt | Time since submission | Wait before it |
| ------- | --------------------- | -------------- |
| 1       | 0:30                  | None           |
| 2       | 0:35                  | 5 seconds      |
| 3       | 1:05                  | 30 seconds     |
| 4       | About 2:32            | About 88 seconds |
| 5       | About 3:16            | About 44 seconds |
| 6       | About 3:38            | About 22 seconds |
| 7       | About 3:53            | 15 seconds     |
| 8       | About 4:08            | 15 seconds     |
| 9 to 24 | 4 hours more each     | 4 hours        |

Inside the window, each wait is half the time left to the deadline, at least 15
seconds (1/16 of the window), and never longer than the normal schedule's wait
for that attempt. After the deadline the normal schedule resumes at the current
attempt, so the event still gets 24 attempts in total.

## Request states

| Status      | Description                                       |
| ----------- | ------------------------------------------------- |
| Queued      | Request received and queued for processing        |
| In Progress | Request is currently being processed              |
| Success     | Request completed successfully, results available |
| Failed      | Request failed due to an error                    |

## Best practices

1. **Store request IDs:** always save the returned request ID for later
   retrieval. With ZDR on, retrieval returns purged content once the webhook
   delivery finishes, so rely on the webhook for the result.
2. **Use webhooks:** instead of polling, set up webhooks to be notified when
   requests complete. See [Webhooks](/docs/api/async/webhooks/).
3. **Handle failures:** a 4xx status other than 429 means the request fails
   again if resent unchanged; a 429 or 5xx status can succeed on retry.
   Queued requests continue processing after the submitting client disconnects;
   disconnecting does not cancel asynchronous work.
4. **Batch when possible:** for many requests, use the
   [Batch API](/docs/api/async/batch/) or the [Group API](/docs/api/async/group/).
   Batch requests are not available while ZDR is on; group requests need a
   webhook.

## Supported endpoints

- `/v1/slow/chat/completions`
- `/v1/slow/completions`
- `/v1/slow/embeddings`

Replace `/v1/` with `/v1/slow/` in your existing code to use asynchronous
processing.

## Pricing and limits

- **Pricing:** significantly reduced compared to synchronous requests (contact
  sales for specific rates)
- **Completion time:** 24 hours
- **Rate limits:** more generous than synchronous endpoints. See
  [Rate limits](/docs/rate-limits/).
- **Request expiration:** requests expire after 24 hours if not completed

For specific pricing and higher rate limits, contact
[support@inference.net](mailto:support@inference.net).