Thread API

Threads serve as conversation containers that store Messages exchanged between a user and an Assistant, maintaining context and continuity across interactions.

This page provides API schemas for the following methods:

https://api.aimlapi.com/threads

https://api.aimlapi.com/threads/{threadId}

https://api.aimlapi.com/threads/{threadId}

https://api.aimlapi.com/threads/{threadId}

After each API schema, you'll find a short example demonstrating how to correctly call the described method in code using the OpenAI SDK.

API Schemas

Create a Thread

post
Authorizations
Body
Responses
default
application/json
post
POST /threads HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 432

{
  "messages": [
    {
      "role": "user",
      "content": "text",
      "attachments": [
        {
          "file_id": "text",
          "tools": [
            {
              "type": "code_interpreter"
            }
          ]
        }
      ],
      "metadata": {
        "ANY_ADDITIONAL_PROPERTY": "text"
      }
    }
  ],
  "metadata": {
    "ANY_ADDITIONAL_PROPERTY": "text"
  },
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ],
      "vector_stores": [
        {
          "chunking_strategy": {
            "type": "auto"
          },
          "file_ids": [
            "text"
          ],
          "metadata": {
            "ANY_ADDITIONAL_PROPERTY": "text"
          }
        }
      ]
    }
  }
}
default
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

Python + OpenAI SDK Example:

from openai import OpenAI
client = OpenAI()

thread = client.beta.threads.create(
  messages=[
    {
      "role": "user",
      "content": "Create 3 data visualizations based on the trends in this file.",
      "attachments": [
        {
          "file_id": file.id,
          "tools": [{"type": "code_interpreter"}]
        }
      ]
    }
  ]
)        


Retrieve information about a specific Thread by its ID

get
Authorizations
Path parameters
threadIdstringRequired
Responses
default
application/json
get
GET /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Accept: */*
default
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

Python + OpenAI SDK Example:

from openai import OpenAI
client = OpenAI()

my_thread = client.beta.threads.retrieve("thread_abc123")
print(my_thread)


Modify a specific Thread by its ID

post
Authorizations
Path parameters
threadIdstringRequired
Body
Responses
default
application/json
post
POST /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 139

{
  "metadata": {
    "ANY_ADDITIONAL_PROPERTY": "text"
  },
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": []
    }
  }
}
default
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

Python + OpenAI SDK Example:

from openai import OpenAI
client = OpenAI()

my_updated_thread = client.beta.threads.update(
  "thread_abc123",
  metadata={
    "modified": "true",
    "user": "abc123"
  }
)
print(my_updated_thread)


Delete a specific Thread by its ID

delete
Authorizations
Path parameters
threadIdstringRequired
Responses
default
application/json
delete
DELETE /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Accept: */*
default
{
  "id": "text",
  "object": "thread.deleted",
  "deleted": true
}

Python + OpenAI SDK Example:

from openai import OpenAI
client = OpenAI()

response = client.beta.threads.delete("thread_abc123")
print(response)

Last updated

Was this helpful?