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

# Create Chat Completion

> Creates a model response for the given chat conversation.
Supports OpenAI, Anthropic, Google, and Bedrock providers via
provider resolution based on the model name.
Set `stream: true` for Server-Sent Events streaming.




## OpenAPI

````yaml POST /chat/completions
openapi: 3.0.3
info:
  title: Traceport Gateway API
  description: |
    OpenAI-compatible unified gateway API for Traceport.
    Supports multiple LLM providers (OpenAI, Anthropic, Google, Bedrock) through
    a single set of endpoints. All endpoints require API key authentication via
    the `Authorization: Bearer <api-key>` header.
  version: 1.0.0
  contact:
    name: Traceport
    url: https://traceport.ai
servers:
  - url: /v1
    description: API v1
security:
  - BearerAuth: []
tags:
  - name: Chat Completions
    description: Create chat completions (supports streaming)
  - name: Embeddings
    description: Create text embeddings
  - name: Batches
    description: Manage batch processing jobs
  - name: Files
    description: Upload and manage files for batch processing
  - name: Workflow
    description: Execute server-side workflows
  - name: Prompts
    description: Run published prompt templates
  - name: Realtime
    description: Build interactive, low-latency AI applications with persistent connections
paths:
  /chat/completions:
    post:
      tags:
        - Chat Completions
      summary: Create Chat Completion
      description: |
        Creates a model response for the given chat conversation.
        Supports OpenAI, Anthropic, Google, and Bedrock providers via
        provider resolution based on the model name.
        Set `stream: true` for Server-Sent Events streaming.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
      responses:
        '200':
          description: Chat completion response (non-streaming)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
            text/event-stream:
              schema:
                description: >
                  SSE stream of `StreamChunk` objects, each prefixed with `data:
                  `.

                  The stream terminates with `data: [DONE]`.
                type: string
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ChatRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model identifier (e.g. `gpt-4o`, `claude-3-sonnet`).
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: List of messages comprising the conversation.
        temperature:
          type: number
          format: double
          nullable: true
          description: Sampling temperature (0–2).
        max_completion_tokens:
          type: integer
          nullable: true
          description: Maximum number of tokens to generate.
        top_p:
          type: number
          format: double
          nullable: true
          description: Nucleus sampling parameter.
        frequency_penalty:
          type: number
          format: double
          nullable: true
          description: Frequency penalty (−2.0 to 2.0).
        presence_penalty:
          type: number
          format: double
          nullable: true
          description: Presence penalty (−2.0 to 2.0).
        stop:
          type: array
          items:
            type: string
          description: Stop sequences.
        stream:
          type: boolean
          default: false
          description: Whether to stream partial responses via SSE.
        tools:
          type: array
          items:
            $ref: '#/components/schemas/Tool'
          description: List of tools the model may call.
        tool_choice:
          description: >
            Controls which tool is called. Can be `"none"`, `"auto"`,

            or an object like `{"type": "function", "function": {"name":
            "my_fn"}}`.
        response_format:
          $ref: '#/components/schemas/ResponseFormat'
        seed:
          type: integer
          nullable: true
          description: Seed for deterministic sampling.
        user:
          type: string
          description: End-user identifier for abuse monitoring.
        'n':
          type: integer
          nullable: true
          description: Number of completions to generate.
        logprobs:
          type: boolean
          nullable: true
          description: Whether to return log probabilities.
        top_logprobs:
          type: integer
          nullable: true
          description: Number of most likely tokens to return (0–20).
        stream_options:
          $ref: '#/components/schemas/StreamOptions'
    ChatResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
          format: int64
        model:
          type: string
        choices:
          type: array
          items:
            $ref: '#/components/schemas/Choice'
        usage:
          $ref: '#/components/schemas/Usage'
        system_fingerprint:
          type: string
    Message:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
          description: Role of the message author.
        content:
          description: |
            Message content — either a plain string or an array of
            `ContentPart` objects for multimodal input.
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/ContentPart'
        name:
          type: string
          description: Optional participant name.
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ToolCall'
          description: Tool calls generated by the assistant.
        tool_call_id:
          type: string
          description: ID of the tool call this message is responding to.
    Tool:
      type: object
      required:
        - type
        - function
      properties:
        type:
          type: string
          enum:
            - function
        function:
          $ref: '#/components/schemas/FunctionTool'
    ResponseFormat:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
            - json_object
    StreamOptions:
      type: object
      properties:
        include_usage:
          type: boolean
          description: Include usage info in the final streaming chunk.
    Choice:
      type: object
      properties:
        index:
          type: integer
        message:
          $ref: '#/components/schemas/Message'
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - tool_calls
            - content_filter
        logprobs:
          $ref: '#/components/schemas/LogProbs'
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        prompt_tokens_details:
          $ref: '#/components/schemas/PromptTokensDetails'
        completion_tokens_details:
          $ref: '#/components/schemas/CompletionTokensDetails'
        cache_creation_input_tokens:
          type: integer
          description: Anthropic — tokens used to create the cache.
        cache_read_input_tokens:
          type: integer
          description: Anthropic — tokens read from cache.
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
    ContentPart:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
        text:
          type: string
        image_url:
          $ref: '#/components/schemas/ImageURL'
    ToolCall:
      type: object
      required:
        - id
        - type
        - function
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - function
        function:
          $ref: '#/components/schemas/FunctionCall'
    FunctionTool:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        description:
          type: string
        parameters:
          type: object
          description: JSON Schema describing the function's parameters.
          additionalProperties: true
    LogProbs:
      type: object
      properties:
        content:
          type: array
          items:
            $ref: '#/components/schemas/LogProbContent'
    PromptTokensDetails:
      type: object
      properties:
        cached_tokens:
          type: integer
    CompletionTokensDetails:
      type: object
      properties:
        reasoning_tokens:
          type: integer
        accepted_prediction_tokens:
          type: integer
        rejected_prediction_tokens:
          type: integer
    ImageURL:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
        detail:
          type: string
          enum:
            - auto
            - low
            - high
    FunctionCall:
      type: object
      required:
        - name
        - arguments
      properties:
        name:
          type: string
        arguments:
          type: string
          description: JSON-encoded function arguments.
    LogProbContent:
      type: object
      properties:
        token:
          type: string
        logprob:
          type: number
          format: double
        bytes:
          type: array
          items:
            type: integer
        top_logprobs:
          type: array
          items:
            type: object
            properties:
              token:
                type: string
              logprob:
                type: number
                format: double
              bytes:
                type: array
                items:
                  type: integer
  responses:
    BadRequest:
      description: Bad request — invalid or missing parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Unauthorized — missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key passed as a Bearer token.

````