Skip to main content

Get Your API Key

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

Create an account

Visit buntime.sh/dashboard and sign up with your email or GitHub account.
2

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

Set your environment variable

export BUNTIME_API_KEY="your_api_key_here"

Choose Your Integration Method

REST API

Make direct HTTP requests to the API

TypeScript SDK

Use our type-safe client library

REST API

1. Create a Session

Every execution happens within a session. Sessions persist files and processes across multiple executions.
curl -X POST https://api.buntime.sh/sessions/create \
  -H "Authorization: Bearer $BUNTIME_API_KEY" \
  -H "Content-Type: application/json"
Response:
{
  "sessionId": "ses_abc123def456",
  "expiresAt": "2024-01-20T10:30:00Z"
}

2. Execute Code

Run your first piece of code in the session.
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:
{
  "stdout": "Hello from buntime!\n4",
  "stderr": "",
  "exitCode": 0,
  "executionTime": 45,
  "memoryUsed": 12582912
}

3. Work with Files

Write a file and execute it.
# 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

bun add buntime.sh

2. Initialize the Client

import { Buntime } from 'buntime.sh';

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

3. Create a Session

const session = await client.sessions.create();
console.log('Session ID:', session.id);

4. Execute Code

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

// 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

// 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:
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

Multi-file Projects

Learn how to build complex applications

Web Apps

Create web servers with live preview

Databases

Work with Redis, PostgreSQL, and SQLite

AI Integration

Integrate with Claude, GPT, and MCP
Need help? Join our Discord community or check out the API Reference.