> ## Documentation Index
> Fetch the complete documentation index at: https://docs.buntime.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> Complete REST API documentation for buntime.sh

## Base URL

All API requests are made to:

```
https://api.buntime.sh
```

## Authentication

All endpoints require authentication using an API key in the Authorization header:

```bash theme={null}
Authorization: Bearer your_api_key_here
```

See [Authentication](/authentication) for details on obtaining and managing API keys.

## Request Format

All POST/PUT requests must include:

* `Content-Type: application/json` header
* JSON-encoded request body

```bash theme={null}
curl -X POST https://api.buntime.sh/execute \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sessionId": "ses_123", "code": "console.log(\"Hello!\")"}'
```

## Response Format

All responses are JSON-encoded with appropriate HTTP status codes.

### Success Response

```json theme={null}
{
  "data": {
    // Response data here
  }
}
```

### Error Response

```json theme={null}
{
  "error": {
    "code": "invalid_request",
    "message": "Session not found",
    "details": {
      "sessionId": "ses_invalid"
    }
  }
}
```

## HTTP Status Codes

| Status Code | Description                                             |
| ----------- | ------------------------------------------------------- |
| `200`       | Success - Request completed successfully                |
| `201`       | Created - Resource created successfully                 |
| `400`       | Bad Request - Invalid request parameters                |
| `401`       | Unauthorized - Invalid or missing API key               |
| `403`       | Forbidden - API key lacks required permissions          |
| `404`       | Not Found - Resource doesn't exist                      |
| `429`       | Too Many Requests - Rate limit exceeded                 |
| `500`       | Internal Server Error - Something went wrong on our end |
| `503`       | Service Unavailable - Temporary issue, retry later      |

## Rate Limits

API keys are rate-limited based on your plan:

* **Free:** 100 requests/minute
* **Paid:** 1,000 requests/minute
* **Enterprise:** Custom limits

Rate limit information is included in response headers:

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640000000
```

When you exceed the rate limit, you'll receive a `429` response with a `Retry-After` header indicating when you can retry.

## Pagination

List endpoints support pagination using query parameters:

```
GET /files/list?sessionId=ses_123&limit=50&offset=0
```

| Parameter | Type    | Description                                      |
| --------- | ------- | ------------------------------------------------ |
| `limit`   | integer | Number of items per page (default: 50, max: 100) |
| `offset`  | integer | Number of items to skip (default: 0)             |

Paginated responses include metadata:

```json theme={null}
{
  "data": [...],
  "pagination": {
    "total": 150,
    "limit": 50,
    "offset": 0,
    "hasMore": true
  }
}
```

## Idempotency

POST requests that create resources support idempotency keys to safely retry requests:

```bash theme={null}
curl -X POST https://api.buntime.sh/sessions/create \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Idempotency-Key: unique_request_id_123" \
  -H "Content-Type: application/json"
```

If you retry a request with the same idempotency key within 24 hours, you'll receive the same response as the original request.

## Timeouts

All API requests have a maximum timeout:

* **Session operations:** 10 seconds
* **File operations:** 30 seconds
* **Code execution:** 30 seconds (default), up to 5 minutes (configurable)

If an operation exceeds the timeout, you'll receive a `408 Request Timeout` response.

## Webhooks

buntime.sh can send webhooks for long-running operations:

* Execution completed
* Session expired
* Resource limit exceeded

Configure webhooks in your [dashboard](https://buntime.sh/dashboard/webhooks).

## API Endpoints

### Sessions

Manage isolated execution environments:

<CardGroup cols={2}>
  <Card title="Create Session" icon="plus" href="/api-reference/sessions/create">
    Create a new session
  </Card>

  <Card title="Get Session Info" icon="info" href="/api-reference/sessions/info">
    Retrieve session details
  </Card>

  <Card title="Delete Session" icon="trash" href="/api-reference/sessions/delete">
    Delete a session
  </Card>
</CardGroup>

### Execution

Run code in sessions:

<CardGroup cols={2}>
  <Card title="Execute Code" icon="play" href="/api-reference/execution/execute">
    Run code or commands
  </Card>

  <Card title="Kill Process" icon="stop" href="/api-reference/execution/kill">
    Stop running processes
  </Card>
</CardGroup>

### Files

Manage files in sessions:

<CardGroup cols={2}>
  <Card title="Write File" icon="file-pen" href="/api-reference/files/write">
    Create or update files
  </Card>

  <Card title="Read File" icon="file" href="/api-reference/files/read">
    Read file contents
  </Card>

  <Card title="List Files" icon="folder" href="/api-reference/files/list">
    List all files
  </Card>
</CardGroup>

### Preview

Access web applications:

<Card title="Web Preview" icon="browser" href="/api-reference/preview/access">
  Access running web apps
</Card>

## SDKs

We provide official SDKs to make integration easier:

<CardGroup cols={1}>
  <Card title="TypeScript/JavaScript" icon="js" href="/sdk/introduction">
    Type-safe Node.js and Bun client
  </Card>
</CardGroup>

## Examples

### Quick Start

```bash theme={null}
# 1. Create a session
SESSION=$(curl -s -X POST https://api.buntime.sh/sessions/create \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  | jq -r '.sessionId')

# 2. Execute code
curl -X POST https://api.buntime.sh/execute \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"sessionId\": \"$SESSION\",
    \"code\": \"console.log('Hello, World!')\"
  }"
```

### Multi-file Project

```bash theme={null}
# Write files
curl -X POST https://api.buntime.sh/files/write \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"sessionId\": \"$SESSION\",
    \"path\": \"utils.ts\",
    \"content\": \"export const add = (a: number, b: number) => a + b;\"
  }"

# Execute
curl -X POST https://api.buntime.sh/execute \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"sessionId\": \"$SESSION\",
    \"code\": \"import { add } from './utils'; console.log(add(2, 3));\"
  }"
```

## Need Help?

<CardGroup cols={2}>
  <Card title="Join Discord" icon="discord" href="https://discord.gg/buntime">
    Get help from the community
  </Card>

  <Card title="View Examples" icon="code" href="https://github.com/buntimesh/examples">
    Browse code examples
  </Card>

  <Card title="Report Issues" icon="bug" href="https://github.com/buntimesh/buntime/issues">
    Report bugs or issues
  </Card>

  <Card title="Email Support" icon="envelope" href="mailto:support@buntime.sh">
    Contact our support team
  </Card>
</CardGroup>
