Skip to content

Create an API token

POST
/api/tokens
curl --request POST \
--url https://opfield.example.com/api/tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "name": "example", "scopes": [], "registryAccess": { "pull": "all", "push": "all" }, "expiresAt": "2026-04-15T12:00:00Z", "allowedIps": [ "example" ], "exactScopes": true }'

The scopes are bounded by your own. A new token also gets the grants older scripts expect from the scopes they name (for example repository reads with integrations:github:view) where you hold them; send exactScopes: true to store exactly the requested scopes, as the token dialog does.

JSON request body

Media typeapplication/json
object
name
required
string
>= 1 characters <= 255 characters
scopes
Array<string>
default: <= 5000 items
registryAccess

Internal registry access of the token: pull and push each “all” or a list of repository names; omit an action to deny it.

object
pull
Any of:
string
Allowed values: all
push
Any of:
string
Allowed values: all
expiresAt

When the token stops working (ISO 8601 date-time in the future); null for no expiry.

string | null format: date-time
allowedIps

IPv4/IPv6 addresses or CIDR ranges the token works from (up to 20). An empty list allows any address.

Array<string>
<= 20 items
exactScopes

Store exactly the requested scopes. Without it a new token also gets the grants older scripts expect from the scopes they name (for example repository reads with integrations:github:view), where the owner holds them.

boolean

Created

Media typeapplication/json
object
id
required
string
name
required
string
tokenPrefix
required
string
scopes
required
Array<string>
registryAccess
required

Internal registry access of the token: pull and push each “all” or a list of repository names; omit an action to deny it.

object
pull
Any of:
string
Allowed values: all
push
Any of:
string
Allowed values: all
expiresAt
required
string | null
expired
required
boolean
allowedIps
required
Array<string>
lastUsedAt
required
string | null
createdAt
required
string
token
required
string
Example
{
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Automation token",
"tokenPrefix": "opf_abc123",
"scopes": [
"nodes:details"
]
}
}

Bad request

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"path": [
"name"
],
"message": "Required"
}
]
}

Authentication required

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "UNAUTHORIZED",
"message": "Authentication required"
}

Forbidden

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "FORBIDDEN",
"message": "Insufficient permissions"
}

Not found

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "NOT_FOUND",
"message": "Resource not found"
}

Conflict

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "CONFLICT",
"message": "Resource already exists"
}

Unprocessable entity

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "UNPROCESSABLE_ENTITY",
"message": "Request could not be processed"
}

Internal server error

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "INTERNAL_ERROR",
"message": "Internal server error"
}