---
name: ainative-provisioning
description: Use when onboarding a new Cody CLI user, setting up AINative trial accounts, provisioning ZeroDB projects, or implementing zero-auth account creation flows. Covers the instant-db endpoint, credential file format, claim flow, and how the postinstall hook works.
---

# AINative Auto-Provisioning

## How It Works

On `npm install -g @ainative/cody-cli`, the postinstall hook (`bin/postinstall.cjs`) automatically:

1. Calls `POST https://api.ainative.studio/api/v1/public/instant-db`
2. Receives a `tmp_` API key + ZeroDB project ID
3. Writes to `~/.cody/credentials.json`
4. Prints a claim URL to the terminal

**No signup. No auth. No credit card. User is ready to run `cody` immediately.**

## Instant-DB Endpoint

```
POST https://api.ainative.studio/api/v1/public/instant-db
Content-Type: application/json

{ "agree_terms": true, "on_behalf_of": "cody-cli" }
```

Response:
```json
{
  "api_key": "tmp_...",
  "project_id": "uuid",
  "base_url": "https://api.ainative.studio",
  "expires_at": "2026-...",
  "claim_url": "https://www.ainative.studio/claim?token=...",
  "limits": { "chat_credits": 50, "vectors": 10000, ... }
}
```

The `tmp_` key works for **both**:
- LLM inference: `POST /v1/messages` with `x-api-key: tmp_...`
- ZeroDB operations: vectors, memory, embeddings, postgres

## Credential File

Location: `~/.cody/credentials.json`

```json
{
  "api_key": "tmp_...",
  "project_id": "uuid",
  "base_url": "https://api.ainative.studio",
  "expires_at": "2026-...",
  "claim_url": "https://...",
  "claimed": false,
  "provisioned_by": "cody-cli-postinstall",
  "provisioned_at": "2026-..."
}
```

After `cody login`, `api_key` becomes a permanent `sk_` key and `claimed: true`.

## Claim Flow

User visits `claim_url` → signs up or logs into AINative → project transferred to their account → `tmp_` key replaced with permanent `sk_` key.

To trigger via email: set `CODY_EMAIL=user@example.com` before install or first run.

## Skip Conditions

Provisioning is skipped if:
- `ANTHROPIC_API_KEY` or `CODY_API_KEY` env var is already set
- `~/.cody/credentials.json` exists and is not expired
- Network is unavailable (silent fail, never blocks install)

## For Agents Onboarding New Users

```javascript
// Provision a trial account for a new user
const res = await fetch('https://api.ainative.studio/api/v1/public/instant-db', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ agree_terms: true, on_behalf_of: 'cody-cli' }),
})
const { api_key, project_id, claim_url, expires_at } = await res.json()
// api_key is ready to use immediately for both LLM and ZeroDB
```
