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

# Create Completion

> Creates a completion for the provided prompt and parameters. This endpoint supports both streaming and non-streaming responses.



## OpenAPI

````yaml POST /completions
openapi: 3.1.0
info:
  title: Passy API
  description: >-
    OpenAI-compatible API for accessing AI models through Passy. Unlimited AI
    for developers with predictable pricing.
  version: 1.0.0
  contact:
    name: Passy Support
    email: hello@passy.ai
    url: https://passy.ai
servers:
  - url: https://api.passy.ai/v1
    description: Passy Production API
security:
  - bearerAuth: []
tags:
  - name: Models
    description: List and retrieve information about available models
  - name: Completions
    description: Create text completions
  - name: Chat
    description: Create chat completions for conversational AI
paths:
  /completions:
    post:
      tags:
        - Completions
      summary: Create Completion
      description: >-
        Creates a completion for the provided prompt and parameters. This
        endpoint supports both streaming and non-streaming responses.
      operationId: createCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionRequest'
            examples:
              basic:
                summary: Basic completion request
                value:
                  model: llama-3.3-70b-versatile
                  prompt: Say this is a test
                  max_tokens: 100
                  temperature: 0.7
              streaming:
                summary: Streaming completion request
                value:
                  model: gpt-4
                  prompt: Write a short story about AI
                  max_tokens: 500
                  temperature: 0.8
                  stream: true
      responses:
        '200':
          description: Successfully created completion
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompletionResponse'
              example:
                id: cmpl-7QyqpwdfhqwajicIEznoc6Q47XAyW
                object: text_completion
                created: 1677664795
                model: llama-3.3-70b-versatile
                choices:
                  - text: ' This is indeed a test'
                    index: 0
                    logprobs: null
                    finish_reason: stop
                usage:
                  prompt_tokens: 5
                  completion_tokens: 7
                  total_tokens: 12
            text/event-stream:
              schema:
                type: string
                description: Server-sent events stream when stream=true
              example: >
                data:
                {"id":"cmpl-7QyqpwdfhqwajicIEznoc6Q47XAyW","object":"text_completion","created":1677664795,"choices":[{"text":"
                This","index":0,"logprobs":null,"finish_reason":null}],"model":"llama-3.3-70b-versatile"}


                data:
                {"id":"cmpl-7QyqpwdfhqwajicIEznoc6Q47XAyW","object":"text_completion","created":1677664795,"choices":[{"text":"
                is","index":0,"logprobs":null,"finish_reason":null}],"model":"llama-3.3-70b-versatile"}


                data: [DONE]
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: 'Invalid value for ''temperature'': must be between 0 and 2'
                  type: invalid_request_error
                  code: invalid_parameter
        '401':
          description: Authentication failed - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Invalid API key provided
                  type: invalid_request_error
                  code: invalid_api_key
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Rate limit exceeded. Please try again later.
                  type: rate_limit_error
                  code: rate_limit_exceeded
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CompletionRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          description: ID of the model to use
          example: llama-3.3-70b-versatile
        prompt:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: The prompt(s) to generate completions for
          example: Say this is a test
        max_tokens:
          type: integer
          description: The maximum number of tokens to generate
          default: 16
          minimum: 1
          example: 100
        temperature:
          type: number
          description: Sampling temperature between 0 and 2
          default: 1
          minimum: 0
          maximum: 2
          example: 0.7
        top_p:
          type: number
          description: Nucleus sampling parameter
          default: 1
          minimum: 0
          maximum: 1
          example: 1
        'n':
          type: integer
          description: Number of completions to generate
          default: 1
          minimum: 1
          maximum: 128
          example: 1
        stream:
          type: boolean
          description: Whether to stream back partial progress
          default: false
          example: false
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
              maxItems: 4
          description: Up to 4 sequences where the API will stop generating
          example: |+

        presence_penalty:
          type: number
          description: Penalty for new tokens based on presence in text so far
          default: 0
          minimum: -2
          maximum: 2
          example: 0
        frequency_penalty:
          type: number
          description: Penalty for new tokens based on frequency in text so far
          default: 0
          minimum: -2
          maximum: 2
          example: 0
    CompletionResponse:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
          description: Unique identifier for the completion
          example: cmpl-7QyqpwdfhqwajicIEznoc6Q47XAyW
        object:
          type: string
          enum:
            - text_completion
          description: Object type, always 'text_completion'
        created:
          type: integer
          description: Unix timestamp (in seconds) when the completion was created
          example: 1677664795
        model:
          type: string
          description: The model used for completion
          example: llama-3.3-70b-versatile
        choices:
          type: array
          description: List of completion choices
          items:
            $ref: '#/components/schemas/CompletionChoice'
        usage:
          $ref: '#/components/schemas/Usage'
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
              description: Human-readable error message
              example: Invalid API key provided
            type:
              type: string
              description: Error type
              example: invalid_request_error
            code:
              type: string
              description: Error code
              example: invalid_api_key
    CompletionChoice:
      type: object
      required:
        - text
        - index
        - finish_reason
      properties:
        text:
          type: string
          description: The generated text
          example: ' This is indeed a test'
        index:
          type: integer
          description: The index of this choice in the list
          example: 0
        logprobs:
          type: object
          nullable: true
          description: Log probabilities of the output tokens
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - content_filter
          description: Reason why the model stopped generating
          example: stop
    Usage:
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      properties:
        prompt_tokens:
          type: integer
          description: Number of tokens in the prompt
          example: 20
        completion_tokens:
          type: integer
          description: Number of tokens in the completion
          example: 10
        total_tokens:
          type: integer
          description: Total number of tokens used
          example: 30
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Enter your Passy API key. Get your key from the Passy dashboard at
        https://dash.passy.ai/

````