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

# Create a completion



## OpenAPI

````yaml openapi.json post /v1/completions
openapi: 3.1.0
info:
  title: Alter Public API (OpenAI Compatible)
  version: 1.0.0
  description: Public-facing OpenAI-compatible endpoints.
servers:
  - url: https://alterhq.com/api
security: []
paths:
  /v1/completions:
    post:
      summary: Create a completion
      operationId: createCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionRequest'
      responses:
        '200':
          description: The completion response or stream.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/CompletionResponse'
                  - $ref: '#/components/schemas/CompletionChunk'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/CompletionChunk'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
      security:
        - BearerAuth: []
components:
  schemas:
    CompletionRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
        prompt:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        max_tokens:
          type: integer
          minimum: 1
        temperature:
          type: number
          minimum: 0
          maximum: 2
        top_p:
          type: number
          minimum: 0
          maximum: 1
        'n':
          type: integer
          minimum: 1
        stream:
          type: boolean
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
        logit_bias:
          type: object
        user:
          type: string
    CompletionResponse:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
        object:
          type: string
          const: text_completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            $ref: '#/components/schemas/CompletionChoice'
        usage:
          $ref: '#/components/schemas/Usage'
    CompletionChunk:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
        object:
          type: string
          const: text_completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            $ref: '#/components/schemas/CompletionChunkChoice'
    CompletionChoice:
      type: object
      required:
        - text
        - index
        - finish_reason
      properties:
        text:
          type: string
        index:
          type: integer
        logprobs:
          type:
            - object
            - 'null'
        finish_reason:
          type:
            - string
            - 'null'
    Usage:
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    CompletionChunkChoice:
      type: object
      required:
        - text
        - index
        - finish_reason
      properties:
        text:
          type: string
        index:
          type: integer
        finish_reason:
          type:
            - string
            - 'null'
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              oneOf:
                - type: string
                - type: integer
                - type: 'null'
          required:
            - message
            - type
      required:
        - error
  responses:
    BadRequestError:
      description: Bad request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnauthorizedError:
      description: Unauthorized.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Alter token
      description: Bearer token issued by the Alter macOS app.

````