---
title: "Generate chat completion"
method: POST
path: "/v1/llm/chat/completions"
tags: ["LLM"]
---

# Generate chat completion

`POST /v1/llm/chat/completions`

## Request

- Base URL: `https://api.prod.keyban.io`
- URL: `https://api.prod.keyban.io/v1/llm/chat/completions`
- Auth: one of:
  - API key in header `X-Api-Key`
  - `bearer` (a scheme the document does not define)

Send messages to an LLM and receive a completion. Requires authenticated user with active organization. Usage is tracked for auditing and future quota enforcement.

**Message Roles:**
- `system`: Defines the AI's behavior and constraints (e.g., "You are a helpful coding assistant"). Place at the beginning of the conversation. Only one system message is supported (Gemini limitation).
- `user`: Represents the human's questions or requests. Can appear multiple times in the conversation.
- `assistant`: Represents the AI's previous responses. Used to maintain conversation history and context.

**Example conversation flow:**
```json
{
  "messages": [
    {"role": "system", "content": "You are a helpful assistant that responds in French."},
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "La capitale de la France est Paris."},
    {"role": "user", "content": "What is its population?"}
  ]
}
```

The AI will remember the conversation context and respond about Paris's population.

## Request body

- ChatCompletionRequestDto: Request to generate an LLM chat completion. Requires authenticated user with active organization.
  - `application` string, uuid, required: Application ID for usage tracking
  - `provider` 'GOOGLE': LLM provider to use (GOOGLE for MVP)
  - `model` string, required: Model identifier (e.g., gemini-2.5-flash-lite)
  - `messages` object[], required: Conversation history (1-100 messages)
    - `role` 'user' | 'assistant' | 'system', required: Role of the message sender (user, assistant, system)
    - `content` string: Content of the message (simple text mode). Deprecated in favor of parts for multimodal support.
    - `parts` union[]: Message parts for multimodal content (text + files). Use this instead of content for files.
      - union
        - object
          - `type` 'text', required: Text content
          - `text` string, required: Text content of the part
        - object
          - `type` 'inline_data', required: File content (base64 encoded)
          - `inlineData` object, required: File data
            - `mimeType` string, required: MIME type of the file (e.g., application/pdf, image/png, image/jpeg)
            - `data` string, required: Base64-encoded file data
  - `temperature` number: Sampling temperature (0=deterministic, 2=creative). Optional.
  - `maxTokens` integer: Maximum tokens in response (up to 8192). Optional.
  - `topP` number: Nucleus sampling parameter. Optional.
  - `topK` integer: Top-K sampling parameter. Optional.

## Response `200`

Chat completion generated successfully

- ChatCompletionResponseDto: Response from LLM chat completion
  - `id` string, uuid, required: Unique identifier for this completion
  - `provider` 'GOOGLE', required: Provider that generated this
  - `model` string, required: Model that generated this response
  - `message` object, required: Generated assistant message
    - `role` 'user' | 'assistant' | 'system', required: Role of the message sender (user, assistant, system)
    - `content` string: Content of the message (simple text mode). Deprecated in favor of parts for multimodal support.
    - `parts` union[]: Message parts for multimodal content (text + files). Use this instead of content for files.
      - union
        - object
          - `type` 'text', required: Text content
          - `text` string, required: Text content of the part
        - object
          - `type` 'inline_data', required: File content (base64 encoded)
          - `inlineData` object, required: File data
            - `mimeType` string, required: MIME type of the file (e.g., application/pdf, image/png, image/jpeg)
            - `data` string, required: Base64-encoded file data
  - `usage` object, required: Token usage statistics
    - `promptTokens` integer, required: Tokens in the prompt
    - `completionTokens` integer, required: Tokens in the completion
    - `totalTokens` integer, required: Total tokens consumed
  - `finishReason` string, required: Reason completion finished (stop, length, etc.)
  - `createdAt` string, date-time, required: Timestamp of completion

## Other responses

- `400`: Invalid request body
- `401`: Unauthorized
- `403`: No active organization

---

[API](https://skmtc.dev/keyban/apis/keyban-rest-apis.md) · [All operations](https://skmtc.dev/keyban/apis/keyban-rest-apis/llms.txt) · [OpenAPI document](https://skmtc.dev/keyban/apis/keyban-rest-apis/revisions/0bb79a1da961?raw)
