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

# Create chat completion

> Send a chat completion request



## OpenAPI

````yaml post /api/gateway/v1/chat/completions
openapi: 3.1.0
info:
  title: Waystone API
  description: Development documentation
  version: 1.0.0
servers:
  - url: http://localhost:3000
    description: Local server
security:
  - bearerAuth: []
paths:
  /api/gateway/v1/chat/completions:
    post:
      summary: Create chat completion
      description: Send a chat completion request
      operationId: postApiGatewayV1ChatCompletions
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - type: object
                  properties:
                    model:
                      type: string
                      examples:
                        - openai/gpt-4o-mini
                        - gpt-4o-mini
                      description: >-
                        <provider>/<model> to use in the query. If <model> is
                        unique across providers, can supply <model> only
                    metadata:
                      type: object
                      properties:
                        waystone:
                          type: string
                      additionalProperties:
                        type: string
                      description: >-
                        Key-value pairs of metadata for the request. Identify
                        end-users associated with the query with the `waystone`
                        metadata. All other fields are metadata for OpenAI
                        requests and are not used by Waystone.
                      examples:
                        - waystone: "{\n\t\t\t\t\t\t\"user\": {\n\t\t\t\t\t\t\t\"id\": \"user123\",\n\t\t\t\t\t\t\t\"metadata\": { \"email\": \"user@example.com\", \"name\": \"John Doe\" }\n\t\t\t\t\t\t}\n\t\t\t\t\t}"
                        - waystone: "{\n\t\t\t\t\t\t\"user\": \"user123\",\n\t\t\t\t\t\t\"group\": { \"id\": \"group123\", \"metadata\": { \"name\": \"Group Name\" } }\n\t\t\t\t\t}"
                    store:
                      type:
                        - boolean
                        - 'null'
                      default: false
                      description: >-
                        For OpenAI: Whether or not to store the output of this
                        chat completion request in OpenAI
                  required:
                    - model
                - type: object
                  properties:
                    stream:
                      type:
                        - boolean
                        - 'null'
                      default: false
                      description: >-
                        If set to true, the model response data will be streamed
                        to the client as it is generated
                    user:
                      type: string
                      description: >-
                        For OpenAI: A unique identifier representing your
                        end-user. NOT used by Waystone.
                    temperature:
                      type: number
                      default: 1
                      maximum: 2
                      minimum: 0
                      description: >-
                        What sampling temperature to use, between 0 and 2.
                        Higher values like 0.8 will make the output more random,
                        while lower values like 0.2 will make it more focused
                        and deterministic. We generally recommend altering this
                        or top_p but not both.
                    frequency_penalty:
                      type: number
                      default: 0
                      maximum: 2
                      minimum: -2
                      description: >-
                        Number between -2.0 and 2.0. Positive values penalize
                        new tokens based on their existing frequency in the text
                        so far, decreasing the model's likelihood to repeat the
                        same line verbatim.
                    max_completion_tokens:
                      type: number
                      description: >-
                        An upper bound for the number of tokens that can be
                        generated for a completion, including visible output
                        tokens and reasoning tokens.
                    'n':
                      type: number
                      default: 1
                      description: >-
                        How many chat completion choices to generate for each
                        input message. Note that you will be charged based on
                        the number of generated tokens across all of the
                        choices. Keep n as 1 to minimize costs.
                - type: object
                  properties:
                    messages:
                      type: array
                      items:
                        anyOf:
                          - type: object
                            properties:
                              content:
                                anyOf:
                                  - type: string
                                  - type: array
                                    items:
                                      type: string
                                description: The contents of the system message.
                              role:
                                type: string
                                enum:
                                  - developer
                                  - system
                                  - user
                                  - assistant
                                  - function
                              name:
                                type: string
                                description: >-
                                  An optional name for the participant. Provides
                                  the model information to differentiate between
                                  participants of the same role.
                            required:
                              - content
                              - role
                          - type: object
                            properties:
                              content:
                                type: string
                                description: The contents of the tool message.
                              role:
                                type: string
                                const: tool
                              tool_call_id:
                                type: string
                            required:
                              - content
                              - role
                              - tool_call_id
                      description: A list of messages comprising the conversation so far.
                  required:
                    - messages
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        finish_reason:
                          type: string
                          description: >-
                            The reason the model stopped generating tokens. This
                            will be stop if the model hit a natural stop point
                            or a provided stop sequence, length if the maximum
                            number of tokens specified in the request was
                            reached, content_filter if content was omitted due
                            to a flag from our content filters, tool_calls if
                            the model called a tool, or function_call
                            (deprecated) if the model called a function.
                        index:
                          type: number
                          description: The index of the choice in the list of choices.
                        logprobs:
                          type:
                            - object
                            - 'null'
                          description: Log probability information for the choice.
                        message:
                          type: object
                          properties:
                            contents:
                              type:
                                - string
                                - 'null'
                            refusal:
                              type:
                                - string
                                - 'null'
                              description: The refusal message generated by the model.
                            role:
                              type: string
                            annotations:
                              type: array
                              items:
                                type: object
                              description: >-
                                Annotations for the message, when applicable, as
                                when using the web search tool.
                            audio:
                              type:
                                - object
                                - 'null'
                              description: >-
                                If the audio output modality is requested, this
                                object contains data about the audio response
                                from the model.
                          required:
                            - contents
                            - refusal
                            - role
                            - annotations
                            - audio
                          description: A chat completion message generated by the model.
                        created:
                          type: number
                          description: >-
                            The Unix timestamp (in seconds) of when the chat
                            completion was created.
                      required:
                        - finish_reason
                        - index
                        - logprobs
                        - message
                        - created
                    minItems: 1
                  id:
                    type: string
                    description: >-
                      The unique identifier for the chat completion, generated
                      by the model provider.
                  object:
                    type: string
                  model:
                    type: string
                    description: The model name used to generate the response.
                  usage:
                    type: object
                    properties:
                      completion_tokens:
                        type: number
                      prompt_tokens:
                        type: number
                      total_tokens:
                        type: number
                      completion_tokens_details:
                        type: object
                      prompt_tokens_details:
                        type: object
                required:
                  - choices
                  - id
                  - object
                  - model
                  - usage
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````