Create an API key
Mint a new API key on the project. The token is NOT returned — the response carries the key's metadata plus a one-time revealUrl that only a signed-in dashboard session can open.
Scope attenuation: a key created with a delegated credential (an OAuth token or another API key) may not carry a scope that credential does not itself hold. A request that asks for more is refused with 400 SCOPE_ESCALATION rather than quietly narrowed, so the mistake is reported where it was made instead of surfacing later as an unexplained 403. Naming only legacyGrantPreset counts as asking for every scope that preset implies.
Requires the api-keys:write scope — Create, rotate, and revoke API keys — these keep working even after you disconnect this app.
BetterAuth session cookie. Used by the dashboard / browser clients. When present, the active project is taken from the x-project-id header.
In: cookie
Path Parameters
Project id.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/api/projects/string/api-keys" \ -H "Content-Type: application/json" \ -d '{ "name": "string" }'{
"success": true,
"data": {
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"projectId": "5a8591dd-4039-49df-9202-96385ba3eff8",
"name": "string",
"lastFour": "string",
"legacyGrantPreset": "FULL",
"mode": "LIVE",
"scopes": [
"emails:send"
],
"domainId": "8a0b02c3-fdd8-452e-bc6e-ef07a335ec7e",
"lastUsedAt": "2019-08-24T14:15:22Z",
"createdAt": "2019-08-24T14:15:22Z",
"revokedAt": "2019-08-24T14:15:22Z",
"revealUrl": "http://example.com",
"revealExpiresAt": "2019-08-24T14:15:22Z"
}
}{
"success": false,
"error": {
"message": "string",
"code": "string",
"details": {
"errors": [
null
]
}
}
}{
"success": false,
"error": {
"message": "string",
"code": "string",
"details": {
"errors": [
null
]
}
}
}{
"success": false,
"error": {
"message": "string",
"code": "string",
"details": {
"errors": [
null
]
}
}
}{
"success": false,
"error": {
"message": "string",
"code": "string",
"details": {
"errors": [
null
]
}
}
}{
"success": false,
"error": {
"message": "string",
"code": "string",
"details": {
"errors": [
null
]
}
}
}