Create an API key - Spacefast Docs

Create an API key

Creates an API key whose policy grants exactly permissions on exactly scope, and returns it with the full secret. That secret appears in this response only and cannot be read back, so store it before moving on. The request fails with policy_exceeds_grantor when the derived policy reaches past what the calling credential itself holds. A browser session must have reverified recently; an API key caller does not.

POST /v1/api-keys

Authorization

Authorization Bearer token · header required

`Authorization: Bearer ` with an API key (`sfa_` prefix), an OAuth access token, a session token, or a Space machine credential (`sfm_` prefix).

or

Authorization OAuth2 access token · header required

OAuth 2.0 with Spacefast scopes. People use the authorization code flow; machines use client credentials.

Scopes: teams:create

Request body

required application/json

Responses

201 Response for status 201

Example Request

curl -X POST "https://api.spacefast.com/v1/api-keys" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{\n  "expiresAt": "2019-08-24T14:15:22Z",\n  "ipAllowlist": [\n    "string"\n  ],\n  "metadata": {\n    "property1": null,\n    "property2": null\n  },\n  "name": "string",\n  "notBefore": "2019-08-24T14:15:22Z",\n  "permissions": [\n    "spaces:read"\n  ],\n  "scope": {\n    "kind": "team",\n    "teamId": "string"\n  }\n}'

Example Response

{  
  "$schema": "http://example.com",  
  "data": {  
    "collection": "team",  
    "createdAt": "2019-08-24T14:15:22Z",  
    "createdByUserId": "string",  
    "enabled": true,  
    "expiresAt": "2019-08-24T14:15:22Z",  
    "id": "string",  
    "ipAllowlist": [\ "string\ "],  
    "lastRequestAt": "2019-08-24T14:15:22Z",  
    "metadata": {  
      "property1": null,  
      "property2": null  
    },  
    "name": "string",  
    "notBefore": "2019-08-24T14:15:22Z",  
    "ownerPrincipal": {  
      "type": "team",  
      "id": "string"  
    },  
    "policy": {  
      "statements": [  
        {  
          "actions": [  
            "spaces:read"  
          ],  
          "conditions": {  
            "request.client": "dashboard"  
          },  
          "effect": "allow",  
          "resources": [  
            "string"  
          ]  
        }  
      ],  
      "version": "2026-06-09"  
    },  
    "preset": "ci_deploy",  
    "revokedAt": "2019-08-24T14:15:22Z",  
    "secret": "string",  
    "secretPreview": "string",  
    "subject": {  
      "type": "user",  
      "id": "string"  
    },  
    "teamScope": {},  
    "updatedAt": "2019-08-24T14:15:22Z"  
  }  
}

Error Response Example

{  
  "$schema": "http://example.com",  
  "type": "string",  
  "title": "string",  
  "status": -9007199254740991,  
  "detail": "string",  
  "code": "string",  
  "pointer": "string",  
  "details": {  
    "property1": null,  
    "property2": null  
  },  
  "suggestions": [  
    "string"  
  ],  
  "next": [  
    "string"  
  ],  
  "requestId": "string"  
}