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

# Code Recipes

> Production patterns for project provisioning, credential minting, relay discovery, and budget monitoring.

# SDK Code Recipes

Common patterns and production examples using `@qumo-deploy/sdk`.

***

## 1. Minting Short-Lived Relay Credentials

To establish secure WebTransport / MoQ relay sessions, applications mint ephemeral scoped JWT credentials.

```typescript theme={null}
import { QumoClient } from "@qumo-deploy/sdk";

const client = new QumoClient({
  baseUrl: "https://api.qumo.dev",
  apiKey: process.env.QUMO_API_KEY!,
});

async function mintRelayToken() {
  // Issue a short-lived token valid for 1 hour with relay session scope
  const cred = await client.credentials.issue({
    scopes: ["relay:session"],
    ttl_seconds: 3600,
  });

  console.log("Token:", cred.token);
  console.log("Expires at:", cred.expires_at);

  // Read assigned edge relays and fallback hosts
  if (cred.relays && cred.relays.length > 0) {
    const primaryRelay = cred.relays[0];
    console.log(`Connecting to relay: ${primaryRelay.url} (${primaryRelay.region})`);
  }
}

mintRelayToken();
```

***

## 2. Provisioning Isolated Projects & Environments

```typescript theme={null}
import { QumoClient } from "@qumo-deploy/sdk";

const client = new QumoClient({
  baseUrl: "https://api.qumo.dev",
  token: process.env.QUMO_TOKEN!,
});

async function createProjectEnvironment() {
  // Create production project
  const prodProject = await client.projects.create({
    name: "streaming-app-prod",
    environment: "production",
  });

  console.log(`Created prod project: ${prodProject.id}`);

  // Create local relay test project
  const testProject = await client.projects.create({
    name: "streaming-app-test",
    environment: "test",
  });

  console.log(`Created test project: ${testProject.id}`);
}
```

***

## 3. Creating Scoped Bot Accounts for CI/CD

Machine identities (bots) allow CI pipelines to authenticate without user credentials:

```typescript theme={null}
import { QumoClient } from "@qumo-deploy/sdk";

const client = new QumoClient({
  baseUrl: "https://api.qumo.dev",
  token: process.env.QUMO_TOKEN!,
});

async function setupCiBot(tenantId: string) {
  // 1. Create a bot principal
  const bot = await client.bots.create({
    tenant_id: tenantId,
    name: "github-actions-deployer",
    description: "Automated deployment runner",
  });

  // 2. Grant project.admin IAM binding to the bot
  await client.iam.grant({
    role_id: "roles/project.admin",
    member: `bot:${bot.id}`,
    resource_type: "tenant",
    resource_id: tenantId,
  });

  console.log(`Bot created and configured: bot:${bot.id}`);
}
```
