docs
0
# Assistants & Threads
1
2
OpenAI Assistants API implementation with thread management, message handling, and tool execution support.
3
4
## Capabilities
5
6
### Assistant Management
7
8
```python { .api }
9
class Assistants:
10
def create(self, **kwargs): ...
11
def list(self, **kwargs): ...
12
def retrieve(self, **kwargs): ...
13
def update(self, **kwargs): ...
14
def delete(self, **kwargs): ...
15
16
class Threads:
17
def create(self, **kwargs): ...
18
def retrieve(self, **kwargs): ...
19
def update(self, **kwargs): ...
20
def delete(self, **kwargs): ...
21
messages: Messages
22
runs: Runs
23
24
class Messages:
25
def create(self, **kwargs): ...
26
def list(self, **kwargs): ...
27
def retrieve(self, **kwargs): ...
28
def update(self, **kwargs): ...
29
30
class Runs:
31
def create(self, **kwargs): ...
32
def list(self, **kwargs): ...
33
def retrieve(self, **kwargs): ...
34
def cancel(self, **kwargs): ...
35
steps: Steps
36
```
37
38
## Usage Examples
39
40
```python
41
from portkey_ai import Portkey
42
43
portkey = Portkey(
44
api_key="PORTKEY_API_KEY",
45
virtual_key="VIRTUAL_KEY"
46
)
47
48
# Create assistant
49
assistant = portkey.beta.assistants.create(
50
name="Math Tutor",
51
instructions="You are a helpful math tutor",
52
model="gpt-4"
53
)
54
55
# Create thread
56
thread = portkey.beta.threads.create()
57
58
# Add message
59
portkey.beta.threads.messages.create(
60
thread_id=thread.id,
61
role="user",
62
content="Solve 2x + 3 = 7"
63
)
64
65
# Create run
66
run = portkey.beta.threads.runs.create(
67
thread_id=thread.id,
68
assistant_id=assistant.id
69
)
70
```