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

> ## Agent Instructions
> Start with /introduction/getting-started. Use the Inference API's Direct Query endpoint (POST /api/inference/query) with the newton-c-2.6 or newton-fusion-1.0 model (text, image, and video reasoning) or the omega-embedding encoder (time-series embeddings). ATAI_API_ENDPOINT is the base URL https://platform.u1.archetypeai.app with no version path; every endpoint path begins with /api. Pages whose descriptions are marked (Archived) document the legacy Lens runtime — do not use them for new projects.

# Query a Model Session

> Send a Direct Query, Chat Completions, or Responses request to one of your sessions on a platform-hosted model

Requires [version 2.0.1](https://docs.archetypeai.app/release-notes/2.0.x.md#v2-0-1) or later of the Archetype platform.

## Overview

A session answers the same three request formats as the [Inference API](https://docs.archetypeai.app/api-reference/inference/about),
under the session's own path. The model uses the session's `values` and state.

| Endpoint | Format |
| - | - |
| `POST /api/inference/sessions/{session_id}/query` | [Direct Query](https://docs.archetypeai.app/api-reference/inference/query.md) |
| `POST /api/inference/sessions/{session_id}/chat/completions` | [Chat Completions](https://docs.archetypeai.app/api-reference/inference/chat-completions.md) |
| `POST /api/inference/sessions/{session_id}/responses` | [Responses](https://docs.archetypeai.app/api-reference/inference/responses.md) |

Each takes the same body and returns the same response as its endpoint without a session. A model
answers only the formats it serves: see [Available Models](https://docs.archetypeai.app/api-reference/inference/about#available-models).

To use an OpenAI SDK with a session, set its base URL to
`https://platform.u1.archetypeai.app/api/inference/sessions/{session_id}`.

## Request

**session\_id** `string` *required*

Session `ses_` ID, from [Create Model Session](https://docs.archetypeai.app/api-reference/inference/sessions/create-session.md).

The body is the request body of [Direct Query](https://docs.archetypeai.app/api-reference/inference/query.md#request),
[Chat Completions](https://docs.archetypeai.app/api-reference/inference/chat-completions.md#request), or
[Responses](https://docs.archetypeai.app/api-reference/inference/responses.md#request), matching the path.

**model** `string` *required*

The session's model, by any of its names. A body without `model`, or one that names a different
model than the session's, returns `400`.

```bash cURL theme={"system"}
curl -X POST "$ATAI_API_ENDPOINT/inference/sessions/ses_01jcx4m8t2vq6xn3r7k5hbzw9e/query" \
  -H "Authorization: Bearer $ATAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "omega-embedding",
    "query": "",
    "events": [
      {"type": "data.numeric_array", "event_data": {"contents": [[0.12, 0.08, -0.03, 0.15]]}}
    ]
  }'
```

```python Python theme={"system"}
import os
from openai import OpenAI

session_id = "ses_01jcx5a2k9wq3pn8d6r4tmyv7c"  # a session opened on newton-c-2.6
client = OpenAI(
    base_url=f"{os.environ['ATAI_API_ENDPOINT']}/inference/sessions/{session_id}",
    api_key=os.environ["ATAI_API_KEY"],
)

completion = client.chat.completions.create(
    model="newton-c-2.6",
    messages=[{"role": "user", "content": "List three checks to run before starting a conveyor belt."}],
)

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

```javascript JavaScript theme={"system"}
import OpenAI from 'openai';

const sessionId = 'ses_01jcx5f7h3nb2wq9k4s6xdzr8m'; // a session opened on newton-fusion-1.0
const client = new OpenAI({
  baseURL: `${process.env.ATAI_API_ENDPOINT}/inference/sessions/${sessionId}`,
  apiKey: process.env.ATAI_API_KEY
});

const response = await client.responses.create({
  model: 'newton-fusion-1.0',
  input: 'List three checks to run before starting a conveyor belt.'
});

console.log(response.output_text);
```

```json 409 - The session has ended theme={"system"}
{
  "errors": [
    {
      "code": "session_not_running",
      "message": "<message>",
      "suggestion": null,
      "error_uid": "err-xxxxxxxx"
    }
  ]
}
```

## Important Notes

> [!NOTE]
>
> * `409` with `session_not_running` means the session has ended. [Open a new
>   session](https://docs.archetypeai.app/api-reference/inference/sessions/create-session.md) and send the query there. You don't need to
>   read the session's `error` first.
> * `404` means the session doesn't exist or isn't visible to you.
> * `400` also means `model` is missing or names a different model than the session's.
> * A `503` doesn't mean the session has ended. Retry.
> * Every other error is the same as on the endpoint without a session. See
>   [Errors](https://docs.archetypeai.app/api-reference/inference/about#errors).


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