# OpenAI-Compatible Chat Completions Proxy Endpoint

`POST /api/agents/openai/v1/chat/completions`

### Overview
100% OpenAI API compatible proxy endpoint. Allows standard OpenAI SDKs (`openai-python`, `openai-node`), Cursor, LangChain, and third-party tools to interact with Pinter agents seamlessly.

### Authentication & Headers
- **Auth**: Bearer Token or Developer API Key (`Authorization: Bearer <api_key>`)
- **Required Header**: `API-Version: 1`

### Parameters & Request Body Fields
- **`model`** *(string, required)*: Target agent UUID or virtual model ID.
- **`messages`** *(array of message objects, required)*: Chat history containing `role` (`user`, `assistant`, `system`) and `content`.
- **`temperature`** *(number, optional)*: Sampling temperature.
- **`stream`** *(boolean, optional, default: false)*: Set to `true` for OpenAI-compatible streaming chunks.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | yes |  |
| `messages` | object[] | yes |  |
| `messages[].role` | string | yes |  |
| `messages[].content` | object | no |  |
| `messages[].name` | string \| null | no |  |
| `messages[].tool_calls` | object[] \| null | no |  |
| `messages[].tool_call_id` | string \| null | no |  |
| `stream` | boolean | no |  |
| `temperature` | number \| null | no |  |
| `max_tokens` | integer \| null | no |  |
| `top_p` | number \| null | no |  |
| `n` | integer \| null | no |  |
| `stop` | object \| null | no |  |
| `presence_penalty` | number \| null | no |  |
| `frequency_penalty` | number \| null | no |  |
| `user` | string \| null | no |  |
| `tools` | object[] \| null | no |  |
| `tool_choice` | object \| null | no |  |
| `response_format` | object \| null | no |  |

```json
{
  "model": "string",
  "messages": [
    {
      "role": "string",
      "content": null,
      "name": "string",
      "tool_calls": [
        null
      ],
      "tool_call_id": "string"
    }
  ],
  "stream": false,
  "temperature": 0,
  "max_tokens": 0,
  "top_p": 0,
  "n": 0,
  "stop": null,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "user": "string",
  "tools": [
    null
  ],
  "tool_choice": null,
  "response_format": {}
}
```

## Responses

### 200 — Standard OpenAI ChatCompletion response structure

### 400 — Bad Request - The request parameters or headers are invalid (e.g. unsupported API-Version).

### 401 — Unauthorized - Missing, invalid, or expired JWT Bearer token.

### 403 — Forbidden - Insufficient role permissions or resource access denied by RBAC policy.

### 404 — Not Found - The requested resource ID was not found.

### 422 — Validation Error

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | object[] | no |  |
| `detail[].loc` | string | integer[] | yes |  |
| `detail[].msg` | string | yes |  |
| `detail[].type` | string | yes |  |
| `detail[].input` | object | no |  |
| `detail[].ctx` | object | no |  |

```json
{
  "detail": [
    {
      "loc": [
        null
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

## Example

```bash
curl -X POST "$PINTER_URL/api/agents/openai/v1/chat/completions" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model":"string","messages":[{"role":"string","content":null,"name":"string","tool_calls":[null],"tool_call_id":"string"}],"stream":false,"temperature":0,"max_tokens":0,"top_p":0,"n":0,"stop":null,"presence_penalty":0,"frequency_penalty":0,"user":"string","tools":[null],"tool_choice":null,"response_format":{}}'
```
