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

# Building SaaS Agents

> How to use Bothive as the AI agent layer inside a real, multi-tenant SaaS product.

<div className="hero-container">
  <h1 className="hero-title">
    Building SaaS Agents
  </h1>

  <p className="hero-subtitle">
    Bothive is strongest when used as the agent layer inside a real product — serving thousands of users, not just you.
  </p>
</div>

## The SaaS agent model

There's a critical difference between a personal assistant and a SaaS agent:

| Personal Assistant   | SaaS Agent                 |
| -------------------- | -------------------------- |
| One user             | Thousands of users         |
| One memory namespace | Isolated memory per user   |
| One session          | Concurrent sessions        |
| You debug it         | You need traces per user   |
| You pay for it       | Users pay for access to it |

Bothive is designed from the ground up for the SaaS agent model.

## What SaaS agents require

<CardGroup cols={2}>
  <Card title="Tenant Isolation" icon="shield" className="glass-effect">
    Every user's memory, context, and session must be completely isolated. One user's data never appears in another user's conversation.
  </Card>

  <Card title="Session Continuity" icon="arrow-right-arrow-left" className="glass-effect">
    Users expect the agent to remember their context — even across devices, browsers, or days. Sessions are stored by `(bot_id, user_id)`.
  </Card>

  <Card title="Per-User Observability" icon="magnifying-glass" className="glass-effect">
    Your support team needs to look up exactly what happened for a specific user. Runs are filterable by user ID in the dashboard.
  </Card>

  <Card title="Integration Auth Handling" icon="key" className="glass-effect">
    Integrations connected by your users (not you) need OAuth flows and token refresh. Bothive manages this per-user credential storage.
  </Card>
</CardGroup>

## Architecture pattern

Here's how Bothive sits inside a typical SaaS product:

```
Your SaaS Product
├── Your Backend (Next.js, Rails, Django...)
│   └── Calls Bothive API: POST /v1/bots/{bot_id}/chat
│       ├── Headers: Authorization, X-Session-ID (your user ID)
│       └── Body: { message, context }
│
└── Bothive Runtime
    ├── Resolves session by (bot_id, user_id)
    ├── Loads memory for this user
    ├── Executes tools with user's credentials
    └── Returns response + trace
```

Your user never directly talks to Bothive. They talk to your product, which calls Bothive behind the scenes.

## Multi-tenant swarm example

```hivelang theme={null}
swarm SaaSSupport {
  description: "Multi-tenant customer support for ProductName SaaS"

  agent ContextAgent {
    role: "Load user account details and history"
    capabilities {
      crm.getUser
      billing.getSubscription
    }
  }

  agent SupportAgent {
    role: "Resolve the user's support request"
    capabilities {
      knowledgebase.search
      support.createTicket
      billing.issueRefund
    }
  }

  on input {
    user_context = delegate to ContextAgent with { user_id: session.user_id }
    delegate to SupportAgent with {
      query: input,
      context: user_context
    }
  }
}
```

Each user's `session.user_id` ensures memory is isolated. The `ContextAgent` loads only *that* user's billing and CRM data.

## Calling Bothive from your backend

```typescript theme={null}
// In your Next.js API route or backend endpoint
const response = await fetch(`https://api.bothive.cloud/v1/bots/${BOT_ID}/chat`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.BOTHIVE_API_KEY}`,
    'Content-Type': 'application/json',
    'X-Session-ID': userId,  // Your user's ID — this scopes memory
  },
  body: JSON.stringify({
    message: userMessage,
    context: {
      // Inject any user context your product has
      plan: user.plan,
      company: user.company,
    }
  })
});

const { response: agentReply, run_id } = await response.json();
```

## HiveStore — sell your SaaS agent

Once your agent is built and working, you can publish it to the **HiveStore marketplace**:

* Set a monthly or per-use price
* Users subscribe directly — payments handled by Bothive (70/30 revenue split)
* Your agent runs on Bothive's infrastructure — no ops overhead
* Usage analytics and revenue dashboard built-in

This turns your agent into a product you can sell, not just a feature you built.

## Case studies

<AccordionGroup>
  <Accordion title="Customer Support SaaS">
    **Company:** B2B SaaS with 500+ customers
    **Challenge:** Support team overwhelmed with tier-1 tickets
    **Solution:** Bothive support agent embedded in app via API channel. Resolves 60% of tier-1 tickets automatically.
    **Stack:** Bothive API + Stripe integration + Custom CRM integration
    **Result:** Support tickets down 60%, CSAT up 12%
  </Accordion>

  <Accordion title="Developer Tool Platform">
    **Company:** Developer productivity tool
    **Challenge:** Users needed help debugging their code inside the product
    **Solution:** Bothive codebase assistant deployed as in-app web widget. Connected to GitHub to read user repos.
    **Stack:** Bothive Web Widget + GitHub integration + OpenAI GPT-4o
    **Result:** Feature adoption +40%, churn down 8%
  </Accordion>

  <Accordion title="Marketing Platform">
    **Company:** Social media management SaaS
    **Challenge:** Wanted to offer AI content writing to users
    **Solution:** Bothive content agent per user workspace, isolated memory per brand profile.
    **Stack:** Bothive API + Twitter/X integration + brand memory (persistent)
    **Result:** New "AI Writing" tier launched in 2 weeks, 200 upgrades in month 1
  </Accordion>
</AccordionGroup>

## Pricing for SaaS builders

| Plan           | Agents    | Monthly Runs | API Access | Support   |
| -------------- | --------- | ------------ | ---------- | --------- |
| **Free**       | 3         | 1,000        |            | Community |
| **Pro**        | 10        | 20,000       |            | Email     |
| **Business**   | Unlimited | 200,000      |            | Priority  |
| **Enterprise** | Unlimited | Custom       |            | Dedicated |

## Next reads

<CardGroup cols={3}>
  <Card title="API Overview" icon="code" href="../api/overview" className="glass-effect" />

  <Card title="Memory System" icon="brain" href="./memory" className="glass-effect" />

  <Card title="Observability" icon="chart-line" href="./observability" className="glass-effect" />
</CardGroup>
