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

# Create a text completion (legacy)

> Legacy OpenAI text-completion endpoint: a raw `prompt` in, text out, with no chat
template applied. Use [`/chat/completions`](/api-reference/inference/chat/create-a-chat-completion)
instead. The catalog models are chat models, so this endpoint is not part of the
per-model checks in [Feature support](/inference/models#feature-support) and is not
listed in a model's `supported_endpoints`; tool calling and reasoning controls are
not available here.




## OpenAPI

````yaml /api-reference/inference/openapi.yaml post /completions
openapi: 3.1.0
info:
  title: PrimaLabs Inference API
  version: 1.0.0
  description: >
    Serverless LLM inference on PrimaLabs. The API is OpenAI-compatible: point
    any

    OpenAI SDK at the base URL below and pass a PrimaLabs API key as the bearer

    token. Anthropic (`/messages`) and OpenAI Responses (`/responses`) formats
    are

    also accepted as passthroughs.


    This is a **curated** spec covering the endpoints we serve; it is maintained
    by

    hand. The current model list is published at

    https://docs.primalabs.ai/inference/models.
servers:
  - url: https://api.primalabs.ai/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: OpenAI-compatible chat completions — the primary endpoint.
  - name: Completions
    description: Legacy text completions.
  - name: Models
    description: The models your key can call, with context, pricing and capabilities.
  - name: Account
    description: Your account's balance.
  - name: Passthrough
    description: Anthropic and OpenAI Responses formats, forwarded as-is.
paths:
  /completions:
    post:
      tags:
        - Completions
      summary: Create a text completion (legacy)
      description: >
        Legacy OpenAI text-completion endpoint: a raw `prompt` in, text out,
        with no chat

        template applied. Use
        [`/chat/completions`](/api-reference/inference/chat/create-a-chat-completion)

        instead. The catalog models are chat models, so this endpoint is not
        part of the

        per-model checks in [Feature support](/inference/models#feature-support)
        and is not

        listed in a model's `supported_endpoints`; tool calling and reasoning
        controls are

        not available here.
      operationId: createCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionRequest'
            example:
              model: primalabs-ai/DeepSeek-V4.1-Flash-1017
              prompt: The capital of France is
              max_tokens: 16
      responses:
        '200':
          description: A text completion.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Completion'
              example:
                id: cmpl-123
                object: text_completion
                created: 1760460000
                model: primalabs-ai/DeepSeek-V4.1-Flash-1017
                choices:
                  - index: 0
                    text: ' Paris.'
                    finish_reason: stop
                usage:
                  prompt_tokens: 6
                  completion_tokens: 3
                  total_tokens: 9
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/BalanceExhausted'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    CompletionRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          example: primalabs-ai/DeepSeek-V4.1-Flash-1017
        prompt:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        max_tokens:
          type: integer
        stream:
          type: boolean
          default: false
      additionalProperties: true
    Completion:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: text_completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              text:
                type: string
              finish_reason:
                type: string
                example: stop
        usage:
          $ref: '#/components/schemas/Usage'
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
          description: Output tokens, reasoning tokens included.
        total_tokens:
          type: integer
        completion_tokens_details:
          type: object
          properties:
            reasoning_tokens:
              type: integer
              description: >
                The part of `completion_tokens` the model spent thinking. Billed
                at the

                output rate like the rest of `completion_tokens`.
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
              description: >
                Input tokens served from the prompt cache, billed at the cached
                rate. See

                [Prompt caching](/inference/prompt-caching).
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              type: string
  responses:
    BadRequest:
      description: Malformed request (bad JSON, missing/invalid parameters).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Authentication Error, Invalid proxy server token passed.
              type: token_not_found_in_db
              param: key
              code: '401'
    Forbidden:
      description: >
        The key cannot access this model. Unknown model IDs return this status
        too —

        check the `model` against the published catalog. A URL path the API does
        not serve

        (for example one built on a wrong base URL) is also refused with `403`,
        by the

        network edge and without a JSON body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                key not allowed to access model. Tried to access
                primalabs-ai/does-not-exist
              type: key_model_access_denied
              param: model
              code: '403'
    BalanceExhausted:
      description: >
        Your balance has reached zero. Retrying will not help until you top up
        on the

        [dashboard](https://dashboard.primalabs.ai); check `GET /credits`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                ExceededBudget: User=<your user id> over budget. Spend=25.0,
                Budget=25.0
              type: budget_exceeded
              code: '422'
    RateLimited:
      description: >
        Rate limited. One of three layers tripped — per-IP, per-user fair share,
        or

        per-model admission. Back off and retry with jitter; honor `Retry-After`
        when present.

        The per-IP limit is enforced at the network edge and returns no JSON
        body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Your PrimaLabs API key, sent as `Authorization: Bearer <key>`.'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.