# Code Deb API Hub

Project-scoped API management for Code Deb developers. The backend includes authenticated project creation, one-time API keys, HMAC-hashed token storage, per-key scopes, durable per-minute quotas, revocation and real usage observations.

## Create a project

Open [API Hub](/docs/platform/api-hub), sign into your first-party Code Deb account, and create a project code and display name. The project is owned by that account; another account cannot list or mutate its records. Every management mutation is guarded by a first-party signed session and strict browser Origin validation.

## Create and rotate API keys

Issue a key with a name, rate limit from 1 to 300 calls/minute, and exactly the required permission: `mock:invoke`, `events:publish`, or `telemetry:write`. The complete token is returned **once**. Only its keyed HMAC digest and short lookup prefix are stored. Never paste tokens into a frontend bundle or public source repository. To rotate, issue a replacement, update its server-side environment configuration, then revoke the prior key.

## Make an authenticated request

```bash
curl -H "Authorization: Bearer $CODEDEB_API_KEY" \
  https://api.codedeb.com/api/developer/v1/invoke/PROJECT_UUID/products
```

Requires a project with an OpenAPI mock contract and a `mock:invoke` key. A non-success response is an actual failure, not a sample success. Rate-limited requests receive HTTP 429 and Retry-After. The rate limit is claimed atomically in PostgreSQL to prevent bypass by concurrent API replicas.

## API versions and usage

The service route uses an explicit `/v1` API prefix. Projects have their own unique UUIDs; package SDK versions are independent. API Hub's usage page reads real 24-hour per-minute request counters rather than simulated dashboard charts. Error and latency percentiles require actual instrumented telemetry.

## OAuth and access policy

A Code Deb first-party authenticated session protects management operations. **Arbitrary third-party OAuth app registration or external OAuth grants are not included in this implementation.** These require client registration, consent screens, token rotation, revocation, scopes and security auditing; the API Hub must not claim that they already exist.

## Implementation requirements

The Code Deb API router, `developer_projects`, `developer_api_keys`, `developer_api_usage` and the authorized quota RPC must all be deployed. Provision `CODEDEB_DEVELOPER_ENCRYPTION_KEY` as a random 32-byte base64 server secret. No browser receives this key. Grant the server service role; never grant table access to anon/authenticated Data API roles.

## API errors

- `401`: missing, invalid or insufficient-scope API key, or no first-party session for management.
- `403`: cross-origin management mutation rejected.
- `404`: project or mock operation not found, without exposing another owner's resources.
- `429`: per-key atomic request budget exhausted.
- `503`: the API or database cannot fulfill the operation; no fabricated successful data.

## Production checklist

Verify tenant isolation, issuance, one-time secret display, revoke immediacy, concurrent quota claims, log redaction, key rotation, and a real API deployment. Record server-side retention and alert policies for usage records.

[Webhooks](/docs/platform/webhooks) · [Mock](/docs/platform/mock) · [Observability](/docs/platform/observability)
