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

# OpenAI-compatible API

> Models, chat completions, streaming, and errors

## Base URL and authentication

```text theme={"theme":"css-variables"}
https://inference.runanywhere.ai/v1
Authorization: Bearer sk-runa-…
```

Cloud keys are separate from device SDK keys. Never log a key or include one in
client-side analytics. The console's playground receives the endpoint and
model from your signed-in session; production applications should keep the
key server-side. To track usage per user or customer, give each one its own key; see
[Usage by key](https://docs.runanywhere.ai/wally-cloud/usage.md).

## Models and pricing

Models are billed per million tokens against prepaid credits. Production Wally
runs with zero data retention by default: it does not store prompt or completion
bodies. The console playground is the one exception and keeps your recent
conversations. Usage records are separate. The current models and their
rates are on
[console.runanywhere.ai](https://console.runanywhere.ai), and
[refund terms](https://runanywhere.ai/legal/refunds) cover how unused credits come back.

Entitlement is per environment, so a key that works in development can get a `403` in
production for the same model id. Treat the `/models` response for your own key as the
authority on what you can call.

## List models

```bash theme={"theme":"css-variables"}
curl https://inference.runanywhere.ai/v1/models \
  -H "Authorization: Bearer $RUNA_CLOUD_KEY"
```

The response follows the OpenAI list shape. Treat the returned IDs as the
authority; do not hardcode a model that is absent from the current response.

## Chat completions

The endpoint is OpenAI-compatible, so the official OpenAI clients work by pointing `base_url`
at it.

For Python, install the client with `python3 -m pip install openai`. Set
`RUNA_CLOUD_KEY` in your environment to your cloud API key, then replace
`<model-id>` with an ID returned by `/models` before running the example.

```bash cURL theme={"theme":"css-variables"}
curl -N https://inference.runanywhere.ai/v1/chat/completions \
  -H "Authorization: Bearer $RUNA_CLOUD_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<model-id>",
    "stream": true,
    "messages": [{"role": "user", "content": "Explain edge AI in one sentence."}]
  }'
```

```python Python theme={"theme":"css-variables"}
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://inference.runanywhere.ai/v1",
    api_key=os.environ["RUNA_CLOUD_KEY"],
)

stream = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "Explain edge AI in one sentence."}],
    stream=True,
)
for chunk in stream:
    # Usage-only chunks have no choices.
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
```

```javascript JavaScript theme={"theme":"css-variables"}
import OpenAI from 'openai'

const client = new OpenAI({
  baseURL: 'https://inference.runanywhere.ai/v1',
  apiKey: process.env.RUNA_CLOUD_KEY,
})

const stream = await client.chat.completions.create({
  model: '<model-id>',
  messages: [{ role: 'user', content: 'Explain edge AI in one sentence.' }],
  stream: true,
})
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? '')
```

### Body parameters

**model** `string` *required*

The model id to call. The `/models` response for your key is the authority on what is valid.

**messages** `array` *required*

The conversation so far. Each item has a role and content. Content is text. On a user message or a
tool message it can instead be a list of parts. A part is text, or an image. The image is
optional.

**stream** `boolean` (default: false)

Send the reply as SSE chunks instead of one response.

**temperature** `number`

Sampling temperature.

**max\_tokens** `integer`

Cap on tokens generated for this reply.

**tools** `array`

Tool definitions the model may call.

**tool\_choice** `string | object`

Which tool the model must use, if any.

**stream\_options** `object`

Streaming extras, such as asking for a usage chunk.

The service may reject fields outside the current contract. Streaming sends JSON chunks after
`data: `, optionally includes a usage chunk, and terminates with `data: [DONE]`.

### Images

New

A user message or a tool message can carry a picture. `content` is then a list of parts, not a string. A text part is `{"type": "text", "text": "..."}`. An image part is `{"type": "image_url", "image_url": {"url": "..."}}`. The URL is `https`, or a `data:` URL. `detail` may be `auto`, `low`, or `high`.

Not every model accepts one. `GET /v1/models` lists each model's `input_modalities`. In the hosted catalog today, the chat models that include `image` are `deepseek-v4.1-flash`, `deepseek-v4.1-flash-fast`, and `kimi-k3`. Text-only models reject image parts.

```bash theme={"theme":"css-variables"}
curl https://inference.runanywhere.ai/v1/chat/completions \
  -H "Authorization: Bearer $RUNA_CLOUD_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "deepseek-v4.1-flash",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What colour is this?"},
        {"type": "image_url", "image_url": {"url": "https://placehold.co/200x200/ff0000/ff0000.png"}}
      ]
    }]
  }'
```

## Errors and request IDs

Errors use the following safe shape; prompts, completions, and upstream bodies
are not echoed:

```json theme={"theme":"css-variables"}
{
  "error": {
    "message": "The request could not be admitted.",
    "type": "capacity",
    "code": null,
    "param": null
  }
}
```

Error responses carry `x-request-id` for support and usage correlation. The contract does not
declare that header on successful responses, so do not depend on it there.
Common statuses are `400` (invalid request), `401` (unknown key), `403`
(not entitled), `429` (rate or capacity), `502` (engine failure), `503` (not
ready), and `504` (upstream timeout). Capacity `429` responses may include
`Retry-After`.


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