> ## Documentation Index
> Fetch the complete documentation index at: https://docs.physionlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Inference runs

> Serve a finished job's model and call it with an OpenAI client.

An inference run serves the model a training job saved, on the GPUs that trained it, for 7 days after training. It
is billed by its tokens (the model's `token_prices`): prompt, cached prompt and generated tokens. More in [Inference](https://docs.physionlabs.ai/nexcloud/guides/inference.md).

> [!WARNING]
>
> A run is billed until it is stopped. It stops itself after `max_hours`, or after `idle_timeout` seconds without a
> request, but stop it yourself when you are done.

## Estimate and start

`POST /v1/inference/estimate` takes `job_id` or `model`, and `max_hours`, and returns the price, in the same shape as an
[RL run's estimate](https://docs.physionlabs.ai/nexcloud/api/serverless-rl.md#estimate). `POST /v1/inference` starts the run.

| Field | Default | |
| - | - | - |
| `job_id` | this or `model` | a job that succeeded in the last 7 days, of a model that lists `inference` in its methods |
| `model` | this or `job_id` | a base model that lists `inference` in its methods, served with no training job |
| `max_hours` | required | the run stops itself after this long |
| `idle_timeout` | 1800 | seconds without a request before the run stops |
| `images` | false | true lets prompts hold images and videos |
| `name`, `tags` | | your labels |

```bash curl theme={null}
curl https://nexcloud.physionlabs.ai/v1/inference \
  -H "Authorization: Bearer $NEXTRON_API_KEY" -H "Content-Type: application/json" \
  -d '{"job_id": "job_26c2f39989634135", "max_hours": 1}'
```

```python Python theme={null}
run = client.inference.start(job_id="job_26c2f39989634135", max_hours=1)
run = client.inference.wait(run.id)      # until the model is loaded, about 8 minutes
```

```bash CLI theme={null}
nextron-cloud inference start --job job_26c2f39989634135 --max-hours 1         # the price only (exit code 3)
nextron-cloud inference start --job job_26c2f39989634135 --max-hours 1 --yes
nextron-cloud inference wait inf_bbf6b46cf7a74c44
```

Refusals: 422 for a job that did not succeed or a model without inference, 410 for a job that finished more than 7
days ago.

## The run object

`GET /v1/inference/{id}` returns one run; `GET /v1/inference` returns a list. The fields are an RL run's, with the
job in `params.job_id`.

```json theme={null}
{
  "id": "inf_bbf6b46cf7a74c44",
  "state": "ready",
  "model": "qwen3.5-4b",
  "layout": "1x8-h100",
  "params": {
    "train_type": "inference",
    "job_id": "job_26c2f39989634135",
    "max_context": 65536,
    "max_hours": 1,
    "idle_timeout": 1800
  },
  "created": 1795860214.47,
  "ready": 1795860463.2,
  "billable_seconds": 10,
  "close_requested": false,
  "error": null,
  "name": null,
  "tags": [],
  "price_per_hour": 2800,
  "gpus": 8
}
```

## Call the model

The run speaks OpenAI's API. The base URL is `/v1/inference/{id}/v1` and the key is your NexCloud key. It serves
`chat/completions`, `completions` and `models`; any `model` name means the run's model.

```bash curl theme={null}
curl https://nexcloud.physionlabs.ai/v1/inference/inf_bbf6b46cf7a74c44/v1/chat/completions \
  -H "Authorization: Bearer $NEXTRON_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "any", "messages": [{"role": "user", "content": "I was charged twice this month."}], "max_tokens": 256}'
```

```python OpenAI client theme={null}
import os
from openai import OpenAI

llm = OpenAI(
    base_url="https://nexcloud.physionlabs.ai/v1/inference/inf_bbf6b46cf7a74c44/v1",
    api_key=os.environ["NEXTRON_API_KEY"],
)
reply = llm.chat.completions.create(
    model="any",
    messages=[{"role": "user", "content": "I was charged twice this month."}],
    max_tokens=256,
)
print(reply.choices[0].message.content)
```

```python NexCloud SDK theme={null}
with client.inference.connect("inf_bbf6b46cf7a74c44") as live:
    batch = live.sample(prompts, n=1, max_tokens=256, temperature=0)   # a whole evaluation set in one request
    replies = [group[0].text for group in batch]
```

One call without `stream` must finish in about 90 seconds: stream a long answer, and send large batches with
`connect`. Chat prompts render with thinking off, as jobs train.

## Stop

`POST /v1/inference/{id}/stop`.

```bash curl theme={null}
curl -X POST https://nexcloud.physionlabs.ai/v1/inference/inf_bbf6b46cf7a74c44/stop \
  -H "Authorization: Bearer $NEXTRON_API_KEY"
```

```python Python theme={null}
client.inference.stop("inf_bbf6b46cf7a74c44", wait=True)
```

```bash CLI theme={null}
nextron-cloud inference stop inf_bbf6b46cf7a74c44 --wait
```

## Images and videos

`POST /v1/inference/{id}/images` with `{"dataset_id"}` gives a run started with `images` a dataset's files. The SDK's
`live.add_images(paths)` does it for you; see [Inference](https://docs.physionlabs.ai/nexcloud/guides/inference.md#images-and-videos).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.