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

> ## Agent Instructions
> - Base URLs: models `https://api.aisa.one/v1` (Gemini GenerateContent: `https://api.aisa.one/v1beta`); data APIs `https://api.aisa.one/apis/v1`. The `servers` of each operation in https://aisa.one/openapi.yaml is authoritative.
> - Auth: `Authorization: Bearer $AISA_API_KEY`. Never print, log, or commit the key.
> - MCP (preferred for agents): `https://mcp.aisa.one/mcp`, signed in with OAuth, so there is no key to paste.
> - Agent Skill: `npx skills add AIsa-team/agent-skills --skill aisa`. Fallback with the AIsa CLI: `aisa skills install aisa`.
> - Spending: docs, https://aisa.one/models, https://aisa.one/api, `/v1/models`, and MCP `search`, `list_categories`, `get_details`, `batch_quote`, and the `account` operation are free. Quote the exact calls before running them (MCP `batch_quote`, CLI `aisa quote --json`). If the quote reports `auto_execute_eligible: true`, run it unless the user set a tighter limit or asked only for a quote. Otherwise, tell the user in one message the planned calls, the quoted price, and a total USD budget for the task, then wait for approval. Direct HTTP calls follow the stricter rule at https://aisa.one/docs/get-started/cli.md#direct-http-fallback. Do not make paid calls to test availability. Full rule: https://aisa.one/llms.txt

# OpenAI Chat

> Create chat completion

Creates a model response for the given chat conversation. Learn more in the
[text generation](https://platform.openai.com/docs/guides/text-generation), [vision](https://platform.openai.com/docs/guides/vision),
and [audio](https://platform.openai.com/docs/guides/audio) guides.

Parameter support can differ depending on the model used to generate the
response, particularly for newer reasoning models. Parameters that are only
supported for reasoning models are noted below. For the current state of
unsupported parameters in reasoning models,
[refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).

## Streaming responses

Set `"stream": true` to receive server-sent events (SSE) as each token is generated. This produces a lower time-to-first-token and is ideal for chat UIs.

```bash curl theme={null}
curl https://api.aisa.one/v1/chat/completions \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-4.1-mini",
    "messages": [{"role": "user", "content": "Write a haiku about APIs."}],
    "stream": true
  }'
```

```python Python theme={null}
from openai import OpenAI

client = OpenAI(base_url="https://api.aisa.one/v1", api_key="sk-aisa-...")

stream = client.chat.completions.create(
    model="gpt-4.1-mini",
    messages=[{"role": "user", "content": "Write a haiku about APIs."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)
```

```typescript TypeScript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.aisa.one/v1",
  apiKey: process.env.AISA_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "gpt-4.1-mini",
  messages: [{ role: "user", content: "Write a haiku about APIs." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

### Stream anatomy

Each line of the SSE stream looks like:

```
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"Quiet"},"index":0}]}
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":" packets"},"index":0}]}
...
data: {"id":"chatcmpl-...","choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]
```

* Each `data:` line is a JSON object. The first chunk includes the `role`; subsequent chunks contain only `delta.content`.
* The stream ends with a final chunk whose `finish_reason` is set, followed by a literal `data: [DONE]` line.
* If tool calls are used, `delta.tool_calls` arrives incrementally and should be concatenated by `index`.

### Handling errors and timeouts

* **Mid-stream errors** arrive as a normal SSE event with an `error` key instead of `choices`. Close the stream and surface the error to the caller.
* **Stream disconnects** (network blip, client timeout) cannot be resumed — restart the request. The partial response is not billed beyond the tokens you received.
* **Idle timeout**: AIsa closes streams that are idle (no tokens) for more than 60 s. Set your client read timeout to 120 s to give a safety margin.
* **Client backpressure**: stop reading from the stream if your downstream consumer is slow — AIsa throttles delivery rather than dropping tokens.

> [!TIP]
>
> Streaming bills the same per-token rate as non-streaming. You pay for tokens that were delivered, even if the stream is cut off mid-response.

## Request contract

* **Method and path:** POST /chat/completions
* **Request URL template:** `https://api.aisa.one/v1/chat/completions`

[Complete OpenAPI definition](https://aisa.one/docs/reference-contracts/openai-chat.json)

Effective request declaration (including authentication and referenced schemas):

```json theme={null}
{
  "operationId": "createChatCompletion",
  "method": "POST",
  "path": "/chat/completions",
  "servers": [
    {
      "url": "https://api.aisa.one/v1"
    }
  ],
  "parameters": [],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "properties": {
            "function_call": {
              "oneOf": [
                {
                  "example": "auto",
                  "type": "string"
                },
                {
                  "properties": {
                    "name": {
                      "type": "string"
                    }
                  },
                  "type": "object"
                }
              ]
            },
            "functions": {
              "items": {
                "properties": {
                  "description": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "parameters": {
                    "properties": {},
                    "type": "object"
                  }
                },
                "type": "object"
              },
              "type": "array"
            },
            "logprobs": {
              "type": "boolean"
            },
            "messages": {
              "items": {
                "properties": {
                  "content": {
                    "description": "Can be a text string or an array (for image inputs).",
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "items": {
                          "properties": {
                            "image_url": {
                              "type": "string"
                            },
                            "text": {
                              "type": "string"
                            },
                            "type": {
                              "type": "string"
                            }
                          },
                          "type": "object"
                        },
                        "type": "array"
                      }
                    ]
                  },
                  "role": {
                    "example": "user",
                    "type": "string"
                  }
                },
                "type": "object"
              },
              "type": "array"
            },
            "model": {
              "example": "gpt-4.1-mini",
              "type": "string"
            },
            "stream": {
              "example": false,
              "type": "boolean"
            },
            "top_logprobs": {
              "type": "integer"
            }
          },
          "type": "object"
        }
      }
    },
    "required": true
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "bearerFormat": "API Key",
        "scheme": "bearer",
        "type": "http"
      }
    }
  }
}
```


## OpenAPI

````yaml reference-contracts/openai-chat.json POST /chat/completions
openapi: 3.0.3
info:
  description: >-
    OpenAI Chat Completion API including Image Analysis, Streaming, Function
    Calling, and Logprobs.
  title: OpenAI Chat API
  version: 1.0.0
servers:
  - url: https://api.aisa.one/v1
security:
  - BearerAuth: []
tags:
  - name: Examples
paths:
  /chat/completions:
    post:
      summary: Create chat completion
      description: >-
        Generate chat responses with support for images, streaming, function
        calling, and logprobs.
      operationId: createChatCompletion
      requestBody:
        content:
          application/json:
            schema:
              properties:
                function_call:
                  oneOf:
                    - example: auto
                      type: string
                    - properties:
                        name:
                          type: string
                      type: object
                functions:
                  items:
                    properties:
                      description:
                        type: string
                      name:
                        type: string
                      parameters:
                        properties: {}
                        type: object
                    type: object
                  type: array
                logprobs:
                  type: boolean
                messages:
                  items:
                    properties:
                      content:
                        description: Can be a text string or an array (for image inputs).
                        oneOf:
                          - type: string
                          - items:
                              properties:
                                image_url:
                                  type: string
                                text:
                                  type: string
                                type:
                                  type: string
                              type: object
                            type: array
                      role:
                        example: user
                        type: string
                    type: object
                  type: array
                model:
                  example: gpt-4.1-mini
                  type: string
                stream:
                  example: false
                  type: boolean
                top_logprobs:
                  type: integer
              type: object
        required: true
      responses:
        '200':
          description: Successful completion
components:
  securitySchemes:
    BearerAuth:
      bearerFormat: API Key
      scheme: bearer
      type: http

````

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