Skip to main content
Create a new API key for programmatic access. Required scope: admin
key = await mesa.api_keys.create(
    name="ci-key",
    scopes=["read", "write"],
    repo_ids=["repo_123"],
    expires_in_seconds=3600,
)

print(key.id)
print(key.key)  # only returned once

Options

org
str | None
Organization override.
name
str | None
Human-readable key name.
scopes
list[str] | None
Permission scopes. Supported scopes are read, write, and admin. When omitted, the API defaults to ['read', 'write'].
repo_ids
list[str] | None
Restrict the key to specific repository IDs. Omit to allow all repositories in the organization.
expires_in_seconds
int | None
Server-side TTL in seconds. The API accepts values from 100 through 31536000.

Response

id
str
API key ID.
key
str
Plaintext API key. Store it immediately; it is shown only once.
name
str | None
API key name, or null when unnamed.
scopes
list[str]
Scopes granted to this key.
repo_ids
list[str] | None
Repository allowlist, or null when the key is not repo-scoped.
tags
dict[str, str]
User-defined API key tags.
created_at
datetime
Creation time.