The Auth endpoints create and inspect the credentials every other endpoint uses. Four routes live in AuthController (apps/api/src/modules/auth/auth.controller.ts) and delegate to AuthService (apps/api/src/modules/auth/auth.service.ts). With the global /api/v1 prefix from apps/api/src/main.ts, the paths below are the full routes.
The TypeScript SDK (packages/sdk) has no auth resource: its resources are users, balance, orders, top-ups, withdrawals, disputes and wallet. The TypeScript examples on this page therefore use plain fetch. For a conceptual overview of credential types and scopes, see Authentication & Scopes and Security Best Practices.
Common behavior
Authentication and scope
Each route attaches ApiKeyGuard and, except GET /auth/me, ScopeGuard with a @Scopes(...) declaration (apps/api/src/common/guards/api-key.guard.ts, scope.guard.ts). Send the credential as Authorization: Bearer <token>.
The master key exists so you can create the first real key. Use real keys in application code.
Success status codes and response envelope
None of the handlers declares @HttpCode, so the two POST routes return NestJS's default 201 Created. ResponseInterceptor (apps/api/src/common/interceptors/response.interceptor.ts) skips wrapping only when a payload has a meta key or is exactly one key named data. As a result:
POST /auth/api-keys and POST /auth/api-keys/{id}/token are wrapped as { "data": { ... }, "meta": { "requestId", "timestamp" } }.
GET /auth/me is returned as-is, as { "data": { ... } } with no meta.
GET /auth/api-keys returns an object with two keys (data and pagination), so it wrapped. The list therefore sits one level deeper than you might expect: data.data is the array and data.pagination is the cursor info (see the response below).
Errors use { "error": { "code", "message", "details?" } } from GlobalExceptionFilter. See Error Codes.
Idempotency and rate limiting
IdempotencyGuard and IdempotencyInterceptor are registered globally (apps/api/src/modules/idempotency/idempotency.module.ts), so both POST routes honor an optional Idempotency-Key header (a UUID v4; scoped to your key; completed results replay for 24 hours by default). The GET routes ignore it. The global RateLimitGuard allows 100 requests per 60 seconds per key.
These handlers bind individual body fields (@Body('name'), @Body('scopes')) instead of a DTO class, so the global ValidationPipe has no DTO rules to enforce for them. Validate name and scopes on your side.
POST /api/v1/auth/api-keys
Creates an API key. The plain-text key is in this response only; the database stores a salted hash, so it cannot be shown again.
Create API key response (201 Created)
{ "data": { "id": "key_V1StGXR8Z5jdHi6B3mEv0", "key": "ohk_live_key_V1StGXR8Z5jdHi6B3mEv0_9f2c1a7e5b3d8f6041c2a9e7b5d3f1a08c6e4b2d7f9a1c3e", "name": "Marketplace backend", "scopes": [ "read", "write" ] }, "meta": { "requestId": "req_1ab90c", "timestamp": "2026-09-30T10:00:00.000Z" }}
curl -X POST "http://localhost:4000/api/v1/auth/api-keys" \-H "Authorization: Bearer $OFFERHUB_MASTER_KEY" \-H "Content-Type: application/json" \-H "Idempotency-Key: 3f1c2a4e-8b7d-4c1e-9a6f-2d5b7e9c1a3f" \-d '{ "name": "Marketplace backend", "scopes": ["read", "write"] }'
const res = await fetch("http://localhost:4000/api/v1/auth/api-keys", {method: "POST",headers: { Authorization: `Bearer ${process.env.OFFERHUB_MASTER_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(),},body: JSON.stringify({ name: "Marketplace backend", scopes: ["read", "write"] }),}); const { data } = await res.json();console.log(data.id, data.key); // save data.key now - it is not shown again
GET /api/v1/auth/api-keys
Lists API keys, newest first. Key values are never returned, only their metadata.
List API keys response (200 OK)
{ "data": { "data": [ { "id": "key_V1StGXR8Z5jdHi6B3mEv0", "name": "Marketplace backend", "scopes": [ "read", "write" ], "lastUsedAt": "2026-09-30T09:58:12.000Z", "createdAt": "2026-09-29T14:20:00.000Z" } ], "pagination": { "hasMore": false, "nextCursor": null } }, "meta": { "requestId": "req_1ab90d", "timestamp": "2026-09-30T10:00:05.000Z" }}
curl "http://localhost:4000/api/v1/auth/api-keys?limit=20" \-H "Authorization: Bearer $OFFERHUB_API_KEY" # Next pagecurl "http://localhost:4000/api/v1/auth/api-keys?limit=20&cursor=key_V1StGXR8Z5jdHi6B3mEv0" \-H "Authorization: Bearer $OFFERHUB_API_KEY"
const res = await fetch("http://localhost:4000/api/v1/auth/api-keys?limit=20", {headers: { Authorization: `Bearer ${process.env.OFFERHUB_API_KEY}` },}); const body = await res.json();const keys = body.data.data; // array of keysconst { hasMore, nextCursor } = body.data.pagination;
POST /api/v1/auth/api-keys/:id/token
Exchanges an API key ID for a short-lived token (ohk_tok_...) that expires after 1 hour. It is designed for a frontend or other untrusted client that should not hold the long-lived key. The token carries the scopes of the key with that ID.
Token response (201 Created)
{ "data": { "token": "ohk_tok_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJrZXlfVjFTdEdYUjhaNWpkSGk2QjNtRXYwIiwic2NvcGVzIjpbInJlYWQiXSwidHlwZSI6InNob3J0LWxpdmVkIn0.signature" }, "meta": { "requestId": "req_1ab90e", "timestamp": "2026-09-30T10:01:00.000Z" }}
curl -X POST "http://localhost:4000/api/v1/auth/api-keys/key_V1StGXR8Z5jdHi6B3mEv0/token" \-H "Authorization: Bearer $OFFERHUB_API_KEY"
const keyId = "key_V1StGXR8Z5jdHi6B3mEv0"; const res = await fetch(`http://localhost:4000/api/v1/auth/api-keys/${keyId}/token`, {method: "POST",headers: { Authorization: `Bearer ${process.env.OFFERHUB_API_KEY}` },}); const { data } = await res.json();// hand data.token to the browser; it expires in 1 hour
GET /api/v1/auth/me
Returns the identity behind the credential you sent. Use it to check a key, or to see which scopes a token carries.
Current auth context (200 OK)
{ "data": { "apiKeyId": "key_V1StGXR8Z5jdHi6B3mEv0", "apiKeyName": "Marketplace backend", "scopes": [ "read", "write" ] }}
This response has no meta object, because the handler already returns a single-key { "data": ... } payload.
curl "http://localhost:4000/api/v1/auth/me" \-H "Authorization: Bearer $OFFERHUB_API_KEY"
const res = await fetch("http://localhost:4000/api/v1/auth/me", {headers: { Authorization: `Bearer ${process.env.OFFERHUB_API_KEY}` },}); const { data } = await res.json();console.log(data.scopes.includes("write"));
- Users Endpoints - create users and link Airtm accounts
- Config and Health Endpoints - public configuration and health checks
- Authentication & Scopes - credential types and the scope model
- Security Best Practices - key storage, scopes and rotation
- Error Codes - the full error catalog