# Chat Completions

URL: https://docs.unli.dev/chat-completions

> Generate conversational AI responses

## OpenAPI specification

```json
{
  "openapi": "3.2.0",
  "info": {
    "title": "UNLI API",
    "version": "1.0.0",
    "description": "OpenAPI spec for UNLI API chat completions endpoint."
  },
  "servers": [
    {
      "url": "https://api.unli.dev/v1",
      "description": "UNLI API"
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create chat completion",
        "description": "Generate conversational AI responses.",
        "tags": [
          "Chat Completions"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "examples": {
                "default": {
                  "summary": "Example request",
                  "value": {
                    "stream": false,
                    "model": "unli-auto",
                    "temperature": 0.1,
                    "messages": [
                      {
                        "role": "user",
                        "content": [
                          {
                            "type": "text",
                            "text": "hi gpt"
                          }
                        ]
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A chat completion response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                },
                "examples": {
                  "default": {
                    "summary": "Example response",
                    "value": {
                      "choices": [
                        {
                          "finish_reason": "stop",
                          "index": 0,
                          "message": {
                            "content": "Hello! How can I help you today?",
                            "padding": "abcdefghijklmnopq",
                            "role": "assistant"
                          }
                        }
                      ],
                      "id": "chatcmpl-C4pf0fiNNxFd6tJ2PKPH5K2t17Ahj",
                      "usage": {
                        "completion_tokens": 10,
                        "prompt_tokens": 10,
                        "prompt_tokens_details": {
                          "cached_tokens": 0
                        },
                        "total_tokens": 20
                      },
                      "model": "unli-auto",
                      "system_fingerprint": "fp_ffd5ba9d2e"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Bearer token authentication using API keys"
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "properties": {
          "messages": {
            "type": "array",
            "description": "List of messages in the conversation.",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "description": "If true, response will be streamed.",
            "default": false
          },
          "temperature": {
            "type": "number",
            "description": "Sampling temperature to use, between 0 and 2.",
            "minimum": 0,
            "maximum": 2,
            "default": 1
          },
          "model": {
            "type": "string",
            "description": "Model to use for completion.",
            "default": "unli-auto"
          }
        },
        "required": [
          "messages"
        ]
      },
      "ChatMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "description": "Role of the message sender.",
            "enum": [
              "user",
              "assistant",
              "system"
            ]
          },
          "content": {
            "type": "array",
            "description": "Content of the message, as an array of message parts.",
            "items": {
              "$ref": "#/components/schemas/MessageContentPart"
            }
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "MessageContentPart": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Type of content part.",
            "enum": [
              "text"
            ]
          },
          "text": {
            "type": "string",
            "description": "Text content (if type is text)."
          }
        },
        "required": [
          "type",
          "text"
        ]
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "choices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatCompletionChoice"
            }
          },
          "id": {
            "type": "string",
            "description": "Unique identifier for the completion."
          },
          "usage": {
            "$ref": "#/components/schemas/ChatCompletionUsage"
          },
          "model": {
            "type": "string",
            "description": "Model used for the completion."
          },
          "system_fingerprint": {
            "type": "string",
            "description": "System fingerprint."
          }
        },
        "required": [
          "choices",
          "id",
          "usage",
          "model",
          "system_fingerprint"
        ]
      },
      "ChatCompletionChoice": {
        "type": "object",
        "properties": {
          "finish_reason": {
            "type": "string",
            "description": "Reason for finishing.",
            "enum": [
              "stop",
              "length",
              "content_filter",
              "tool_calls"
            ]
          },
          "index": {
            "type": "integer",
            "description": "Index of the choice."
          },
          "message": {
            "$ref": "#/components/schemas/ChatCompletionMessage"
          }
        },
        "required": [
          "finish_reason",
          "index",
          "message"
        ]
      },
      "ChatCompletionMessage": {
        "type": "object",
        "properties": {
          "content": {
            "type": "string",
            "description": "Message content."
          },
          "padding": {
            "type": "string",
            "description": "Padding string."
          },
          "role": {
            "type": "string",
            "enum": [
              "assistant"
            ],
            "description": "Role of the message sender."
          }
        },
        "required": [
          "content",
          "padding",
          "role"
        ]
      },
      "ChatCompletionUsage": {
        "type": "object",
        "properties": {
          "completion_tokens": {
            "type": "integer"
          },
          "prompt_tokens": {
            "type": "integer"
          },
          "prompt_tokens_details": {
            "type": "object",
            "properties": {
              "cached_tokens": {
                "type": "integer"
              }
            },
            "required": [
              "cached_tokens"
            ]
          },
          "total_tokens": {
            "type": "integer"
          }
        },
        "required": [
          "completion_tokens",
          "prompt_tokens",
          "prompt_tokens_details",
          "total_tokens"
        ]
      }
    }
  }
}
```
