OpenAI APIs Threads API

Manage conversation threads

OpenAPI Specification

openai-apis-threads-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: OpenAI APIs OpenAI Assistants Threads API
  description: API for building AI assistants with custom instructions, knowledge retrieval, code execution, and function calling capabilities. Supports managing assistants, threads, messages, and runs.
  version: '2.0'
  contact:
    name: OpenAI Support
    email: support@openai.com
    url: https://help.openai.com
  termsOfService: https://openai.com/policies/terms-of-use
servers:
- url: https://api.openai.com/v1
  description: OpenAI Production API
security:
- bearerAuth: []
tags:
- name: Threads
  description: Manage conversation threads
paths:
  /threads:
    post:
      operationId: createThread
      summary: OpenAI APIs Create thread
      description: Create a thread.
      tags:
      - Threads
      parameters:
      - $ref: '#/components/parameters/OpenAIBeta'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateThreadRequest'
      responses:
        '200':
          description: Thread created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Thread'
        '400':
          description: Invalid request
  /threads/{thread_id}:
    get:
      operationId: getThread
      summary: OpenAI APIs Retrieve thread
      description: Retrieves a thread by ID.
      tags:
      - Threads
      parameters:
      - $ref: '#/components/parameters/threadId'
      - $ref: '#/components/parameters/OpenAIBeta'
      responses:
        '200':
          description: Thread details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Thread'
        '404':
          description: Thread not found
    post:
      operationId: modifyThread
      summary: OpenAI APIs Modify thread
      description: Modifies a thread.
      tags:
      - Threads
      parameters:
      - $ref: '#/components/parameters/threadId'
      - $ref: '#/components/parameters/OpenAIBeta'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                metadata:
                  type: object
                  description: Metadata to attach to the thread
      responses:
        '200':
          description: Thread modified
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Thread'
    delete:
      operationId: deleteThread
      summary: OpenAI APIs Delete thread
      description: Delete a thread by ID.
      tags:
      - Threads
      parameters:
      - $ref: '#/components/parameters/threadId'
      - $ref: '#/components/parameters/OpenAIBeta'
      responses:
        '200':
          description: Thread deleted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteResponse'
components:
  schemas:
    DeleteResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
        deleted:
          type: boolean
    CreateThreadRequest:
      type: object
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/CreateMessageRequest'
          description: Initial messages to start the thread with
        metadata:
          type: object
          description: Key-value metadata for the thread
    CreateMessageRequest:
      type: object
      required:
      - role
      - content
      properties:
        role:
          type: string
          enum:
          - user
          - assistant
          description: The role of the entity creating the message
        content:
          oneOf:
          - type: string
          - type: array
            items:
              type: object
          description: The content of the message
        metadata:
          type: object
          description: Key-value metadata for the message
    Thread:
      type: object
      properties:
        id:
          type: string
          description: The identifier of the thread
        object:
          type: string
          enum:
          - thread
        created_at:
          type: integer
          description: Unix timestamp of creation
        metadata:
          type: object
          description: Key-value metadata attached to the thread
  parameters:
    threadId:
      name: thread_id
      in: path
      required: true
      description: The ID of the thread
      schema:
        type: string
    OpenAIBeta:
      name: OpenAI-Beta
      in: header
      required: true
      description: Required header for the Assistants API beta
      schema:
        type: string
        enum:
        - assistants=v2
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: OpenAI API key passed as a Bearer token
externalDocs:
  description: OpenAI Assistants API Documentation
  url: https://platform.openai.com/docs/api-reference/assistants