|
| 1 | +# 21st-sdk Python |
| 2 | + |
| 3 | +Server-side Python SDK for [21st Agents](https://21st.dev/agents). Manage sandboxes, threads, and tokens programmatically. |
| 4 | + |
| 5 | +Method arguments use Python-style `snake_case`, but SDK responses keep the relay's `camelCase` field names. |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install 21st-sdk |
| 11 | +``` |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +```python |
| 16 | +import os |
| 17 | + |
| 18 | +from twentyfirst_sdk import AgentClient |
| 19 | + |
| 20 | +client = AgentClient(api_key=os.environ["API_KEY_21ST"]) # an_sk_... |
| 21 | + |
| 22 | +# Create a sandbox for your agent |
| 23 | +sandbox = client.sandboxes.create(agent="my-agent") |
| 24 | + |
| 25 | +# Create a thread |
| 26 | +thread = client.threads.create(sandbox_id=sandbox.id, name="Review PR #42") |
| 27 | + |
| 28 | +# Generate a short-lived token for browser clients |
| 29 | +token = client.tokens.create(agent="my-agent", expires_in="1h") |
| 30 | +print(token.expiresAt) |
| 31 | +``` |
| 32 | + |
| 33 | +## API |
| 34 | + |
| 35 | +### `AgentClient(api_key, base_url=...)` |
| 36 | + |
| 37 | +```python |
| 38 | +AgentClient( |
| 39 | + api_key="...", # Your an_sk_ API key |
| 40 | + base_url="...", # Optional, default: "https://relay.an.dev" |
| 41 | +) |
| 42 | +``` |
| 43 | + |
| 44 | +### `client.sandboxes` |
| 45 | + |
| 46 | +| Method | Description | |
| 47 | +|--------|-------------| |
| 48 | +| `create(agent=...)` | Create a new sandbox for an agent | |
| 49 | +| `get(sandbox_id)` | Get sandbox details (status, threads, agent info) | |
| 50 | +| `delete(sandbox_id)` | Delete a sandbox | |
| 51 | +| `exec(sandbox_id, command, ...)` | Run a command in a sandbox | |
| 52 | +| `files.write(sandbox_id, files)` | Write files into a sandbox | |
| 53 | +| `files.read(sandbox_id, path)` | Read a file from a sandbox | |
| 54 | +| `git.clone(sandbox_id, url, ...)` | Clone a repository into a sandbox | |
| 55 | + |
| 56 | +### `client.threads` |
| 57 | + |
| 58 | +| Method | Description | |
| 59 | +|--------|-------------| |
| 60 | +| `list(sandbox_id)` | List all threads in a sandbox | |
| 61 | +| `create(sandbox_id, name=...)` | Create a new thread | |
| 62 | +| `get(sandbox_id, thread_id)` | Get thread with messages | |
| 63 | +| `delete(sandbox_id, thread_id)` | Delete a thread | |
| 64 | +| `run(agent, messages, ...)` | Run a thread and return the raw streaming response | |
| 65 | + |
| 66 | +### `client.tokens` |
| 67 | + |
| 68 | +| Method | Description | |
| 69 | +|--------|-------------| |
| 70 | +| `create(agent=..., user_id=..., expires_in=...)` | Create a short-lived JWT (default: `"1h"`) | |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +MIT |
0 commit comments