# POST /api/ai/turns

Canonical URL: https://developers.iagenify.com/api/reference/ai/post-turns/
Language: en

`POST https://api.iagenify.com/api/ai/turns`

Reference for POST /api/ai/turns.

Status: authenticated · JSON

## Contract boundaries

This endpoint inventory is generated from the mounted API route. Its HTTP method, path, observed field names, and explicit status/error codes come from route source. It is not a complete OpenAPI schema: generic `value` types, descriptions such as `Request field`, and `YOUR_*` placeholders do not define JSON types, nested shapes, validation rules, enums, or all response properties. Do not copy placeholder values as a request body or invent missing constraints.

For the model-turn message, tool, and streaming payload structures, consult the matching SDK contracts: [messages](https://developers.iagenify.com/sdk/ref/models/turn/messages/index.md), [tools](https://developers.iagenify.com/sdk/ref/models/turn/tools/index.md), and [streaming](https://developers.iagenify.com/sdk/ref/models/turn/streaming/index.md). These explain shared object shapes; they do not replace this HTTP route's authentication and JSON envelope.

## HTTP request {#http}

```bash
curl https://api.iagenify.com/api/ai/turns -X POST -H "Authorization: Bearer $IAGENIFY_TOKEN" -H "Content-Type: application/json" -d '{"model":"YOUR_MODEL","system":"YOUR_SYSTEM","messages":"YOUR_MESSAGES","tools":"YOUR_TOOLS","maxOutputTokens":"YOUR_MAX_OUTPUT_TOKENS","temperature":"YOUR_TEMPERATURE","thinking":"YOUR_THINKING","stream":"YOUR_STREAM","sessionId":"YOUR_SESSION_ID"}'
```

## JavaScript {#javascript}

```javascript
const requestBody = {
  "model": "YOUR_MODEL",
  "system": "YOUR_SYSTEM",
  "messages": "YOUR_MESSAGES",
  "tools": "YOUR_TOOLS",
  "maxOutputTokens": "YOUR_MAX_OUTPUT_TOKENS",
  "temperature": "YOUR_TEMPERATURE",
  "thinking": "YOUR_THINKING",
  "stream": "YOUR_STREAM",
  "sessionId": "YOUR_SESSION_ID"
};
const response = await fetch("https://api.iagenify.com/api/ai/turns", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.IAGENIFY_TOKEN}`, "Content-Type": "application/json" },
  body: JSON.stringify(requestBody)
});
const result = await response.json();
if (!response.ok) throw new Error(result.error);
```

## Python {#python}

```python
import os
import requests

request_body = {
  "model": "YOUR_MODEL",
  "system": "YOUR_SYSTEM",
  "messages": "YOUR_MESSAGES",
  "tools": "YOUR_TOOLS",
  "maxOutputTokens": "YOUR_MAX_OUTPUT_TOKENS",
  "temperature": "YOUR_TEMPERATURE",
  "thinking": "YOUR_THINKING",
  "stream": "YOUR_STREAM",
  "sessionId": "YOUR_SESSION_ID"
}

response = requests.request("POST", "https://api.iagenify.com/api/ai/turns", headers={"Authorization": "Bearer " + os.environ["IAGENIFY_TOKEN"], "Content-Type": "application/json"}, json=request_body, timeout=30)
response.raise_for_status()
result = response.json()
```

## Request body {#body}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `model` | value | see route rules | Request field `model`. |
| `system` | value | see route rules | Request field `system`. |
| `messages` | value | see route rules | Request field `messages`. |
| `tools` | value | see route rules | Request field `tools`. |
| `maxOutputTokens` | value | see route rules | Request field `maxOutputTokens`. |
| `temperature` | value | see route rules | Request field `temperature`. |
| `thinking` | value | see route rules | Request field `thinking`. |
| `stream` | value | see route rules | Request field `stream`. |
| `sessionId` | value | see route rules | Request field `sessionId`. |

## Response and errors {#response}

Success returns JSON from the endpoint. Explicit statuses: 400, 402, 502. Error codes: `model_required`, `messages_required`, `invalid_tools`, `not_enough_credits`, `turn_failed`.
