Skip to content

API: API keys

Create an API key (a logged-in session only; network mode)

POST /api/v1/keys: Create an API key (a logged-in session only; network mode)

Last updated:

POST/api/v1/keys

Network mode only: local mode answers 404.

Authentication#

Send the secret in the header Authorization: Bearer <secret>: the local token in local mode, an API key in network mode. An API key needs the read scope; the local token has every scope. See the API overview for both modes.

Request body#

Content type application/json.

NameTypeRequiredDescription
expires_in_daysintegerno1 to 365, default 90; 1 to 30 with admin.
namestringyes1 to 60 characters.. min length 1
project_idstringnoLimits the key to one project; not with admin.
scopesarray of stringyesA non-empty subset of your scopes.

Responses#

201 Created#

Content type application/json. Schema: KeyCreateResult.

NameTypeRequiredDescription
keyKeyno
secretstringno

400#

Validation failed; errors maps each field to its messages and issues lists each problem with its code, key and params

Content type application/problem+json. Schema: Problem.

401 Unauthorized#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

403#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

404#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

409#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

422 Unprocessable Content#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

429#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

Any other status#

Error (RFC 9457 problem details)

Content type application/problem+json. Schema: Problem.

curl -X POST "http://127.0.0.1:7878/api/v1/keys" \
  -H "Authorization: Bearer $STUARTY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "ci",
  "scopes": [
    "read"
  ]
}'

Response examples

{
  "key": {
    "created_at": "2006-01-02T15:04:05Z",
    "expires_at": "2006-01-02T15:04:05Z",
    "key_id": "string",
    "last_used_at": "2006-01-02T15:04:05Z",
    "name": "string",
    "project_id": "string",
    "revoked_at": "2006-01-02T15:04:05Z",
    "scopes": [
      "string"
    ]
  },
  "secret": "string"
}

The examples are built from the schemas of the OpenAPI document, so a value is a placeholder of its type. The fields that carry the real values are in the tables.