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

# Completions

Create a completion based on the provided prompt. This endpoint requires API keys generated from the settings, standard access tokens will not work.


## OpenAPI

````yaml POST /openai/completions
openapi: 3.1.0
info:
  version: 1.2.0
  title: Second Platform API
servers: []
security:
  - bearerAuth: []
externalDocs:
  description: Find out more about Second Platform
  url: https://docs.usesecond.com
paths:
  /openai/completions:
    post:
      tags:
        - OpenAI
      summary: Creates a completion for the provided prompt and parameters
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: >-
                    The unique identifier of the model to be used for generating
                    the completion
                prompt:
                  type: string
                  description: >-
                    The input text that serves as the starting point for the AI
                    to generate a completion
                best_of:
                  type: number
                  default: 1
                  description: >-
                    The number of completion choices to generate and return. The
                    model will generate multiple completions and return the best
                    one(s) based on the specified criteria
                echo:
                  type: boolean
                  default: false
                  description: >-
                    When set to true, the API will include the original prompt
                    in the completion response, effectively echoing it back
                frequency_penalty:
                  type: number
                  default: 0
                  description: >-
                    A value between -2.0 and 2.0 that penalizes new tokens based
                    on their frequency in the text so far. Higher values
                    decrease the model's likelihood to repeat the same lines
                    verbatim
                logit_bias:
                  type: object
                  additionalProperties:
                    type: number
                  description: >-
                    A dictionary that allows fine-tuning the likelihood of
                    specified tokens appearing in the completion. Each key is a
                    token, and the value is the bias (between -100 and 100)
                logprobs:
                  type: number
                  description: >-
                    The number of most likely tokens to return with their log
                    probabilities. If specified, the API will return a list of
                    the most likely tokens for each position
                max_tokens:
                  type: number
                  default: 16
                  description: >-
                    The maximum number of tokens to generate in the completion.
                    The total length of input tokens and generated tokens is
                    limited by the model's context length
                'n':
                  type: number
                  default: 1
                  description: >-
                    The number of completions to generate for each prompt. Note
                    that this may conflict with `best_of` if both are specified
                presence_penalty:
                  type: number
                  default: 0
                  description: >-
                    A value between -2.0 and 2.0 that penalizes new tokens based
                    on whether they appear in the text so far. Positive values
                    increase the model's likelihood to talk about new topics
                seed:
                  type: number
                  default: 689760
                  description: >-
                    A seed for deterministic sampling. Using the same seed with
                    the same parameters will generate the same completion
                stop:
                  type: array
                  items:
                    type: string
                  maxItems: 4
                  description: >-
                    Up to 4 sequences where the API will stop generating further
                    tokens. The returned text will not contain the stop sequence
                stream:
                  type: boolean
                  default: false
                  description: >-
                    If set to true, partial message deltas will be sent as
                    data-only server-sent events. Tokens will be sent as they
                    become available
                stream_options:
                  type: object
                  properties:
                    include_usage:
                      type: boolean
                      default: false
                      description: >-
                        When streaming is enabled, this option determines
                        whether to include token usage information in the stream
                  description: >-
                    Additional options to configure the behavior of streaming
                    responses
                tempature:
                  type: number
                  default: 1
                  description: >-
                    A value between 0 and 2 that controls the randomness of the
                    completion. Lower values make the output more focused and
                    deterministic, while higher values make it more random
                top_p:
                  type: number
                  default: 1
                  description: >-
                    An alternative to temperature, called nucleus sampling. It
                    considers the results of the tokens with top_p probability
                    mass. 0.1 means only the tokens comprising the top 10%
                    probability mass are considered
                user:
                  type: string
                  description: >-
                    A unique identifier representing your end-user, which can
                    help the API to monitor and detect abuse
              required:
                - model
                - prompt
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  object:
                    type: string
                    enum:
                      - text_completion
                  created:
                    type: number
                    default: 1722811396105
                  model:
                    type: string
                  system_fingerprint:
                    type: string
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                        index:
                          type: number
                        logprobs:
                          type: object
                          nullable: true
                          properties:
                            tokens:
                              type: array
                              items:
                                type: string
                            token_logprobs:
                              type: array
                              items:
                                type: number
                            top_logprobs:
                              type: array
                              items:
                                type: object
                                additionalProperties:
                                  type: number
                            text_offset:
                              type: array
                              items:
                                type: number
                          required:
                            - tokens
                            - token_logprobs
                            - top_logprobs
                            - text_offset
                        finish_reason:
                          type: string
                          enum:
                            - stop
                            - length
                            - content_filter
                            - 'null'
                      required:
                        - text
                        - index
                        - logprobs
                        - finish_reason
                  usage:
                    type: object
                    properties:
                      prompt_tokens:
                        type: number
                      completion_tokens:
                        type: number
                      total_tokens:
                        type: number
                    required:
                      - prompt_tokens
                      - completion_tokens
                      - total_tokens
                required:
                  - id
                  - object
                  - model
                  - choices
                  - usage
            text/event-stream:
              schema:
                nullable: true
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      type:
                        type: string
                      param:
                        type: string
                      code:
                        type: string
                    required:
                      - message
                      - type
                required:
                  - error
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      type:
                        type: string
                      param:
                        type: string
                      code:
                        type: string
                    required:
                      - message
                      - type
                required:
                  - error
        '429':
          description: Rate limit reached
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      type:
                        type: string
                      param:
                        type: string
                      code:
                        type: string
                    required:
                      - message
                      - type
                required:
                  - error
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      type:
                        type: string
                      param:
                        type: string
                      code:
                        type: string
                    required:
                      - message
                      - type
                required:
                  - error
      security:
        - openaiBearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    openaiBearerAuth:
      type: http
      scheme: bearer

````