Skip to main content
The Assistants API is in beta. This API is deprecated and may be removed in future versions. Consider using the Responses API for new applications.

Overview

The Assistants API allows you to build AI assistants with custom instructions, tools (Code Interpreter, File Search, Function calling), and knowledge bases. Assistants can maintain context across multiple conversations.
All assistant endpoints require the OpenAI-Beta: assistants=v2 header, which is automatically added by the SDK.

Create assistant

Creates an assistant with a model and instructions.
assistant = client.beta.assistants.create(
  model: "gpt-4o",
  name: "Math Tutor",
  instructions: "You are a helpful math tutor. Answer questions clearly and show your work.",
  tools: [
    { type: "code_interpreter" },
    { type: "file_search" }
  ]
)

Parameters

model
string
required
ID of the model to use. See the model list for available options.
name
string
Name of the assistant (max 256 characters)
description
string
Description of the assistant (max 512 characters)
instructions
string
System instructions for the assistant (max 256,000 characters)
tools
array
Tools available to the assistant (max 128). Options:
tool_resources
object
Resources for tools:
metadata
hash
Optional metadata (up to 16 key-value pairs)
temperature
float
Sampling temperature (0-2, default: 1)
top_p
float
Nucleus sampling parameter (0-1)
response_format
object
Response format specification:
  • auto (default)
  • { type: "text" }
  • { type: "json_object" }
  • { type: "json_schema", json_schema: {...} }

Response

id
string
Unique assistant identifier
object
string
Object type: assistant
created_at
integer
Unix timestamp of creation
name
string
Assistant name
description
string
Assistant description
model
string
Model ID
instructions
string
System instructions
tools
array
Enabled tools
metadata
object
Attached metadata

Retrieve assistant

Retrieves an assistant by ID.
assistant = client.beta.assistants.retrieve("asst_abc123")
puts assistant.name

Parameters

assistant_id
string
required
ID of the assistant to retrieve

Update assistant

Modifies an assistant.
assistant = client.beta.assistants.update(
  "asst_abc123",
  instructions: "Updated instructions for the assistant",
  name: "Updated Math Tutor"
)

Parameters

assistant_id
string
required
ID of the assistant to modify
All creation parameters are available as optional update parameters.

List assistants

Returns a list of assistants.
assistants = client.beta.assistants.list(
  limit: 20,
  order: :desc
)

assistants.data.each do |assistant|
  puts "#{assistant.name} (#{assistant.model})"
end

Parameters

limit
integer
Number to return (1-100, default: 20)
order
string
Sort order: asc or desc (default)
after
string
Cursor for pagination
before
string
Cursor for reverse pagination

Delete assistant

Deletes an assistant.
client.beta.assistants.delete("asst_abc123")

Parameters

assistant_id
string
required
ID of the assistant to delete

Examples

Math tutor with Code Interpreter

# Create assistant
assistant = client.beta.assistants.create(
  name: "Math Tutor",
  instructions: "You are a helpful math tutor. Solve problems step by step.",
  model: "gpt-4o",
  tools: [{ type: "code_interpreter" }]
)

# Create thread
thread = client.beta.threads.create

# Add message
client.beta.threads.messages.create(
  thread.id,
  role: "user",
  content: "Solve: x^2 + 5x + 6 = 0"
)

# Run assistant
run = client.beta.threads.runs.create(
  thread.id,
  assistant_id: assistant.id
)

# Wait for completion
loop do
  run = client.beta.threads.runs.retrieve(thread.id, run.id)
  break if run.status == "completed"
  sleep 1
end

# Get response
messages = client.beta.threads.messages.list(thread.id)
puts messages.data.first.content.first.text.value
# Create vector store with files
vector_store = client.vector_stores.create(
  name: "Product Docs",
  file_ids: [file1.id, file2.id]
)

# Create assistant with file search
assistant = client.beta.assistants.create(
  name: "Documentation Assistant",
  instructions: "Answer questions using the uploaded documentation.",
  model: "gpt-4o",
  tools: [{ type: "file_search" }],
  tool_resources: {
    file_search: {
      vector_store_ids: [vector_store.id]
    }
  }
)

Function calling assistant

assistant = client.beta.assistants.create(
  name: "Weather Assistant",
  instructions: "Help users check the weather.",
  model: "gpt-4o",
  tools: [
    {
      type: "function",
      function: {
        name: "get_current_weather",
        description: "Get the current weather for a location",
        parameters: {
          type: "object",
          properties: {
            location: {
              type: "string",
              description: "City and state, e.g. San Francisco, CA"
            },
            unit: {
              type: "string",
              enum: ["celsius", "fahrenheit"]
            }
          },
          required: ["location"]
        }
      }
    }
  ]
)

Build docs developers (and LLMs) love