> ## 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.

# Quickstart

> Get started with buntime.sh in 5 minutes

## Get Your API Key

First, sign up and get your API key from the dashboard.

<Steps>
  <Step title="Create an account">
    Visit [buntime.sh/dashboard](https://buntime.sh/dashboard) and sign up with your email or GitHub account.
  </Step>

  <Step title="Generate an API key">
    Once logged in, navigate to the API Keys section and create a new key. Copy it somewhere safe—you won't be able to see it again.
  </Step>

  <Step title="Set your environment variable">
    ```bash theme={null}
    export BUNTIME_API_KEY="your_api_key_here"
    ```
  </Step>
</Steps>

## Choose Your Integration Method

<CardGroup cols={2}>
  <Card title="REST API" icon="webhook" href="#rest-api">
    Make direct HTTP requests to the API
  </Card>

  <Card title="TypeScript SDK" icon="js" href="#typescript-sdk">
    Use our type-safe client library
  </Card>
</CardGroup>

***

## REST API

### 1. Create a Session

Every execution happens within a session. Sessions persist files and processes across multiple executions.

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

Response:

```json theme={null}
{
  "sessionId": "ses_abc123def456",
  "expiresAt": "2024-01-20T10:30:00Z"
}
```

### 2. Execute Code

Run your first piece of code in the session.

```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_abc123def456",
    "code": "console.log(\"Hello from buntime!\"); console.log(2 + 2);"
  }'
```

Response:

```json theme={null}
{
  "stdout": "Hello from buntime!\n4",
  "stderr": "",
  "exitCode": 0,
  "executionTime": 45,
  "memoryUsed": 12582912
}
```

### 3. Work with Files

Write a file and execute it.

```bash theme={null}
# Write a file
curl -X POST https://api.buntime.sh/files/write \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "ses_abc123def456",
    "path": "hello.ts",
    "content": "export function greet(name: string) { return `Hello, ${name}!`; }"
  }'

# Execute code that uses the file
curl -X POST https://api.buntime.sh/execute \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "ses_abc123def456",
    "code": "import { greet } from \"./hello.ts\"; console.log(greet(\"World\"));"
  }'
```

***

## TypeScript SDK

### 1. Install the SDK

```bash theme={null}
bun add buntime.sh
```

### 2. Initialize the Client

```typescript theme={null}
import { Buntime } from 'buntime.sh';

const client = new Buntime({
  apiKey: process.env.BUNTIME_API_KEY
});
```

### 3. Create a Session

```typescript theme={null}
const session = await client.sessions.create();
console.log('Session ID:', session.id);
```

### 4. Execute Code

```typescript theme={null}
const result = await client.execute({
  sessionId: session.id,
  code: `
    const data = [1, 2, 3, 4, 5];
    const sum = data.reduce((a, b) => a + b, 0);
    console.log('Sum:', sum);
  `
});

console.log(result.stdout); // "Sum: 15"
console.log(result.exitCode); // 0
```

### 5. Work with Multiple Files

```typescript theme={null}
// Write multiple files
await client.files.write({
  sessionId: session.id,
  path: 'utils.ts',
  content: 'export const add = (a: number, b: number) => a + b;'
});

await client.files.write({
  sessionId: session.id,
  path: 'index.ts',
  content: `
    import { add } from './utils';
    console.log('Result:', add(5, 3));
  `
});

// Execute the main file
const result = await client.execute({
  sessionId: session.id,
  command: 'bun run index.ts'
});

console.log(result.stdout); // "Result: 8"
```

### 6. Create a Web Server

```typescript theme={null}
// Write a simple web server
await client.files.write({
  sessionId: session.id,
  path: 'server.ts',
  content: `
    Bun.serve({
      port: 8080,
      fetch(req) {
        return new Response("Hello from buntime!");
      }
    });
    console.log("Server running on port 8080");
  `
});

// Start the server
await client.execute({
  sessionId: session.id,
  command: 'bun run server.ts'
});

// Access your app at: https://{sessionId}.buntime.sh
console.log(`Preview URL: https://${session.id}.buntime.sh`);
```

***

## Complete Example

Here's a full example that demonstrates the power of buntime.sh:

```typescript theme={null}
import { Buntime } from 'buntime.sh';

const client = new Buntime({
  apiKey: process.env.BUNTIME_API_KEY
});

async function main() {
  // Create a session
  const session = await client.sessions.create();
  console.log('Session created:', session.id);

  // Write a data processing script
  await client.files.write({
    sessionId: session.id,
    path: 'process.ts',
    content: `
      interface User {
        name: string;
        age: number;
      }

      const users: User[] = [
        { name: "Alice", age: 30 },
        { name: "Bob", age: 25 },
        { name: "Charlie", age: 35 }
      ];

      const averageAge = users.reduce((sum, user) => sum + user.age, 0) / users.length;
      console.log("Average age:", averageAge);

      const sortedUsers = users.sort((a, b) => b.age - a.age);
      console.log("Sorted users:", JSON.stringify(sortedUsers, null, 2));
    `
  });

  // Execute the script
  const result = await client.execute({
    sessionId: session.id,
    command: 'bun run process.ts'
  });

  console.log('Output:', result.stdout);

  // List all files in the session
  const files = await client.files.list({ sessionId: session.id });
  console.log('Files:', files);

  // Clean up
  await client.sessions.delete({ sessionId: session.id });
}

main();
```

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Multi-file Projects" icon="folder" href="/guides/multi-file-projects">
    Learn how to build complex applications
  </Card>

  <Card title="Web Apps" icon="browser" href="/guides/web-apps">
    Create web servers with live preview
  </Card>

  <Card title="Databases" icon="database" href="/guides/databases">
    Work with Redis, PostgreSQL, and SQLite
  </Card>

  <Card title="AI Integration" icon="brain" href="/guides/ai-integration">
    Integrate with Claude, GPT, and MCP
  </Card>
</CardGroup>

<Note>
  **Need help?** Join our [Discord community](https://discord.gg/buntime) or check out the [API Reference](/api-reference/introduction).
</Note>
