# Authentication
Source: https://docs.raccoonai.tech/api-reference/authentication
How to authenticate with the Raccoon AI Agents API
All API requests require authentication using a Bearer token in the `Authorization` header.
## Getting an API Key
1. Log in to [Raccoon AI](https://raccoonai.tech/app)
2. Click your profile picture in the top right
3. Select **Manage Account**
4. Go to **API Keys**
5. Click **Add new key**
6. Copy and securely store your API key
API keys are shown only once. If you lose your key, you'll need to generate a new one.
## Using Your API Key
Include your API key in the `Authorization` header of all requests:
```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```
### Example Request
```bash cURL theme={null}
curl -X GET https://api.raccoonai.tech/chats \
-H "Authorization: Bearer sk_live_abc123xyz"
```
```python Python theme={null}
import requests
API_KEY = "sk_live_abc123xyz"
response = requests.get(
"https://api.raccoonai.tech/chats",
headers={"Authorization": f"Bearer {API_KEY}"}
)
```
```javascript JavaScript theme={null}
const API_KEY = "sk_live_abc123xyz";
const response = await fetch("https://api.raccoonai.tech/chats", {
headers: { "Authorization": `Bearer ${API_KEY}` }
});
```
## WebSocket Authentication
For WebSocket connections, pass the token as a query parameter:
```
wss://api.raccoonai.tech/ws/chat/{taskId}?token=YOUR_API_KEY&message_id={messageId}&last_stream_entry_id=0-0
```
## Authentication Errors
### 401 Unauthorized
Returned when the API key is missing or invalid:
```json theme={null}
{
"error": "unauthorized",
"message": "Invalid or missing API key"
}
```
### 403 Forbidden
Returned when the API key doesn't have permission for the requested resource:
```json theme={null}
{
"error": "forbidden",
"message": "You don't have access to this resource"
}
```
# Upload a file
Source: https://docs.raccoonai.tech/api-reference/media/upload-a-file
openapi.yaml put /media/upload
Uploads a file to include with a turn. Returns a file reference
to use in the `files` array when starting a turn.
# Raccoon AI Agents API
Source: https://docs.raccoonai.tech/api-reference/overview
Run autonomous AI agents programmatically
Agents API is currently in early beta. The API may change before general availability.
The agent operates in sandboxed environments where they can execute code, access the web, manage files, and complete multistep tasks, all streaming results back in real-time.
The API is powered by Raccoon AI's Agents SDK.
## Key Concepts
### Sessions
Persistent workspaces identified by a UUID. The agent maintains context across turns: files, conversation history, credentials and processes persist.
### Turns
Single request-response cycles. Each turn builds on previous context within the same session. The agent sees prior work and continues incrementally.
### Modes
Control how the agent works:
| Mode | Use case |
| ------------ | ------------------------- |
| `auto` | General-purpose (default) |
| `code` | Software development |
| `deepsearch` | Research and analysis |
| `slides` | Presentations |
| `plan` | Planning before execution |
## How It Works
`POST /sessions/new` with your prompt, mode, and `session_id`.
Connect to `wss://api.raccoonai.tech/ws/sessions/{sessionId}` to receive events as the agent executes.
Reuse the same `session_id` to continue the session, or generate a new UUID to start fresh.
## Endpoints
| Method | Endpoint | Description |
| ------ | ----------------------------- | ------------------- |
| `POST` | `/sessions/new` | Start a turn |
| `GET` | `/sessions` | List sessions |
| `GET` | `/sessions/{sessionId}` | Get session details |
| `PUT` | `/sessions/{sessionId}/title` | Rename session |
| `DEL` | `/sessions/{sessionId}` | Delete session |
| `PUT` | `/media/upload` | Upload files |
| `WSS` | `/ws/sessions/{sessionId}` | Real-time events |
## Rate Limits
Rate limits are enforced based on your plan. The `X-Rate-Limit-Max-Concurrent` header indicates the maximum turns you can run simultaneously. Exceeding limits returns `429` with an `X-Rate-Limit-Retry-After` header.
For custom limits and pricing, [contact sales](https://raccoonai.tech/contact).
# Delete a session
Source: https://docs.raccoonai.tech/api-reference/sessions/delete-a-session
openapi.yaml delete /sessions/{sessionId}
Permanently deletes a session and all its turns, files, and history.
# Get session history
Source: https://docs.raccoonai.tech/api-reference/sessions/get-session-history
openapi.yaml get /sessions/{sessionId}
Retrieves a session with all its turns, including user prompts, agent responses, and generated content.
# List sessions
Source: https://docs.raccoonai.tech/api-reference/sessions/list-sessions
openapi.yaml get /sessions
Retrieves a paginated list of sessions.
# Start a new session/turn
Source: https://docs.raccoonai.tech/api-reference/sessions/start-a-new-sessionturn
openapi.yaml post /sessions/new
Starts a new turn in a session. If the session doesn't exist, it's created automatically.
To continue an existing session, pass the same `session_id` from a previous turn.
To start a fresh session, generate a new UUID for `session_id`.
After calling this endpoint, connect to the WebSocket at `/ws/sessions/{sessionId}`
to receive real-time execution updates.
# Update session title
Source: https://docs.raccoonai.tech/api-reference/sessions/update-session-title
openapi.yaml put /sessions/{sessionId}/title
Updates the title of a session.
# Stream a session
Source: https://docs.raccoonai.tech/api-reference/streaming