# Raindrop auth.md

Raindrop monitors AI agents in production. This file tells an agent how to get a Raindrop write key for the user it works for, with no account and no browser. The user claims the org later with one link.

- API: https://backend.raindrop.ai
- Human docs: https://www.raindrop.ai/docs/integrations/agent-signup

## 1. Check for an existing key

If `RAINDROP_WRITE_KEY` is set in the environment or the project's `.env`, the user already has Raindrop. Do not create a second org. Do step 3 only, then tell the user to review the integration on the **Get started** page of the Raindrop dashboard. There is no claim link, and the integration check in step 4 does not work with a key you did not create.

## 2. Register

Run this in the project root:

```bash
npx -y create-raindrop --org-name "<project or company name>"
```

`--org-name` is required and allows letters, numbers, spaces, and underscores. The command writes `RAINDROP_WRITE_KEY` to `.env`, adds `.env` to `.gitignore`, and prints the claim link. It never prints the key. Keep the claim link for step 5.

Without Node.js, call the API directly:

```http
POST https://backend.raindrop.ai/api/v1/agent/signup
Content-Type: application/json

{"org_name": "<project or company name>", "source": "<your agent name>"}
```

`org_name` is required; `source` is optional. `201 Created`:

```json
{
  "status": "created",
  "org_id": "…",
  "org_name": "Acme",
  "write_key": "…",
  "env_var": "RAINDROP_WRITE_KEY",
  "plan": "hobby",
  "claim_url": "https://app.raindrop.ai/claim#…",
  "integration_check_url": "https://backend.raindrop.ai/api/v1/agent/integration-check"
}
```

Write `write_key` to `.env` as `RAINDROP_WRITE_KEY` and make sure `.env` is gitignored. Keep `claim_url` for step 5.

Before the claim, the key can only write events. Nobody can sign in to read them. If nobody claims the org within 72 hours, the claim link and the key both stop working.

## 3. Instrument the app

Add the Raindrop SDK or integration that matches the app's stack. See https://www.raindrop.ai/docs/integrations/overview. Then send one real interaction through the instrumented code path and wait about 30 seconds.

## 4. Verify

```bash
npx -y create-raindrop check
```

It exits `0` when healthy, `1` when the integration needs attention (it prints the checks and a fix prompt), and `2` when no events have arrived yet. Or call the API:

```http
GET https://backend.raindrop.ai/api/v1/agent/integration-check
Authorization: Bearer <write_key>
```

- `no_events`: nothing arrived yet. Wait and try again.
- `needs_attention`: follow `fix_prompt`, send another interaction, and check again.
- `healthy`: done.

The check works only for an org you created in step 2, until someone claims it. Any other key gets `403`.

## 5. Hand off the claim link

Tell the user: "Raindrop is set up. Open this link within 72 hours to claim your org and see your first trace: <claim_url>". The first person who signs in through the link becomes the owner. Treat it like a password: show it only to the user, and never write it to files, commits, or shared logs.

## 6. Connect the MCP

After the user claims the org, add the Raindrop MCP server `https://mcp.raindrop.ai/mcp` to your MCP configuration. It signs in with OAuth, so the user approves it once in the browser. With it, you can keep working in Raindrop: read issues, tune signals, and set up alerts. Setup for each client: https://www.raindrop.ai/docs/mcp/overview

## Errors

| Status | `error` | Action |
| --- | --- | --- |
| 400 | `invalid_request` | Fix the body as `message` describes. |
| 401 | `unauthorized` | The integration check needs `Authorization: Bearer <write_key>`. |
| 403 | `not_an_unclaimed_agent_org` | The key is not from step 2, or the org was claimed. Review the integration on the dashboard instead. |
| 404 | `event_not_found` | The newest event is not readable yet. Check again in 30 seconds. |
| 429 | `rate_limited` | Wait for `Retry-After` seconds. Do not loop. |
| 503 | `write_key_pending` | Give the user the claim link in `message`; they copy the key from Settings after claiming. |
| 500 | `signup_failed` | Try once more after a minute, then tell the user. |
