File size: 2,520 Bytes
bd97ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Frox AI Developer API

An OpenAI-compatible developer API with **API keys, authentication, rate
limiting, and usage tracking**, layered in front of the Morph model server.

```
Developer client  ->  Developer Gateway (:8080)  ->  Morph model server (:8000)
  Bearer frx-...        auth + rate limit + usage        raw /v1 inference
```

## Run

```bash
# 1. Start the model server (raw inference, no auth)
python scripts/serve.py --family classic --model ./ckpt --port 8000

# 2. Start the developer gateway in front of it
export MORPH_UPSTREAM_URL=http://localhost:8000
export MORPH_ADMIN_TOKEN=choose-a-strong-admin-secret
uvicorn api.developer_gateway:app --host 0.0.0.0 --port 8080
```

## Issue an API key (admin)

```bash
curl -X POST http://localhost:8080/dev/keys \
  -H "X-Admin-Token: $MORPH_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-app", "plan": "pro"}'
# -> { "key": "frx-....", "plan": "pro", "rpm_limit": 120, ... }
```

The secret is shown **once**. Store it securely.

## Call the API (developer)

Use it exactly like the OpenAI API — just change the base URL and key:

```bash
curl http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer frx-...." \
  -H "Content-Type: application/json" \
  -d '{"model": "classic", "messages": [{"role":"user","content":"Hi"}], "stream": true}'
```

Works with the official OpenAI SDKs:

```python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8080/v1", api_key="frx-....")
resp = client.chat.completions.create(
    model="classic",
    messages=[{"role": "user", "content": "Hello"}],
)
```

## Endpoints

| Method | Path | Auth | Purpose |
|--------|------|------|---------|
| POST | `/dev/keys` | admin | Issue a new API key |
| DELETE | `/dev/keys/{key}` | admin | Revoke a key |
| GET | `/dev/usage` | key | This key's usage counters |
| GET | `/v1/models` | key | List available models |
| POST | `/v1/chat/completions` | key | Chat completion (stream or full) |
| GET | `/health` | none | Gateway + upstream health |

## Plans & rate limits

| Plan | Requests / min |
|------|----------------|
| free | 20 |
| pro | 120 |
| scale | 600 |

## Production notes

- Swap the JSON `KeyStore` for a real database (interface is small: `create`,
  `get`, `revoke`, `record_usage`).
- Set `MORPH_ADMIN_TOKEN` (without it, key management is open — dev only).
- Restrict `MORPH_CORS_ORIGINS` to your real client origins.
- Rate limiting is in-memory per process; use Redis for multi-instance.