# API Quick Start

## 1. Health
`GET /health`

## 2. Authentication
Send either:

```http
X-API-Key: mjai_xxxxxxxxx
```

or:

```http
Authorization: Bearer mjai_xxxxxxxxx
```

## 3. Chat
`POST /v1/chat/completions`

Example body:

```json
{
  "messages": [
    {"role": "user", "content": "What can you help me with?"}
  ]
}
```

The response is intentionally close to the OpenAI chat-completion shape so existing clients can adapt easily.

## 4. Persistent conversation
Create:

`POST /v1/conversations`

```json
{"external_user_id":"user-123","title":"Accounts chat"}
```

Then use the returned ID in:

`POST /v1/chat/completions`

```json
{
  "conversation_id":"YOUR-ID",
  "messages":[{"role":"user","content":"Show my outstanding summary."}]
}
```

## 5. Admin
Management endpoints use `X-Admin-Key` and are intentionally separate from customer API keys.

Create organization:

`POST /admin/organizations`

```json
{"name":"Demo ERP","slug":"demo-erp"}
```

Create key:

`POST /admin/organizations/1/keys`

```json
{"name":"Demo Production Key","scopes":["chat","conversations"]}
```

The raw key is returned once.
