Skip to Content
Organizations

Organization API Keys

Global API keys let you automate Zenifra operations without using a user's personal session. Each key belongs to an organization, records who created it, respects RBAC, and can be restricted by source IP.

Use this feature for CI/CD, internal scripts, operational jobs, and server-side integrations.

Create an API key

In the organization console:

  1. open API keys in the sidebar;
  2. click Create API key;
  3. enter a descriptive name;
  4. choose the required permissions, starting from a policy template, reusable policies, or manual adjustments;
  5. choose the expiration (30, 60, 90 days, 1 year, a custom date or no expiration; the default is 90 days) and, optionally, the allowed IPs;
  6. copy the key shown after creation.

API key creation dialog with organization permissions highlighted

Video: creating an organization API key with chosen permissions and an AI key with models and a quota. Both are shown only once.

The full key is shown only once. After that, the console shows only metadata, such as status, creator, last access, last IP, and expiration, plus a partial key preview.

You can only grant an API Key permissions you already hold in the organization. Creating keys requires api_key.create on organization:*; the owner already has this access.

When another API Key creates the key, the new key cannot exceed the restrictions of the calling key: if the calling key expires, the new one must expire on the same date or earlier (no expiration is not accepted); if the calling key has allowed IPs, the new one must provide a list contained in it. Otherwise, the API responds 403 with code: "API_KEY_RESTRICTIONS_EXCEEDED".

Edit an API key

In the key list, use Edit to change the name, expiration and allowed IPs of an active or expired key. Setting a new future date on an expired key makes it usable again. Permissions cannot be edited: to change the scope, create a new key and revoke the old one.

Editing requires api_key.update on the key (or on api_key:*); the owner already has this access. Revoked keys cannot be edited and respond 404. An API Key cannot edit itself (403), and an edit made by another API Key follows the same rule as creation: the expiration and allowed IPs cannot exceed those of the calling key (403 API_KEY_RESTRICTIONS_EXCEEDED).

Through the API:

curl -X PATCH https://api.zenifra.com/v1/organizations/<organization-id>/api-keys/<api-key-id> \
  -H "Authorization: Bearer znf_your_key" \
  -H "Content-Type: application/json" \
  -d '{"expires_at": "2027-01-31T23:59:00.000Z"}'

The body accepts name, allowed_ips and expires_at (a future date, or null to remove the expiration).

Expiration notice

When a key is 30 days from expiring, Zenifra emails the key creator and the organization owner with the key name, preview and expiration date. To keep your automation running, extend the expiration by editing the key or rotate it.

Use in HTTP requests

Send the API key in an authentication header:

curl https://api.zenifra.com/v1/project \
  -H "Authorization: Bearer znf_your_key"

This header is also accepted:

curl https://api.zenifra.com/v1/project \
  -H "x-api-key: znf_your_key"

Prefer Authorization: Bearer for compatibility with the CLI and common HTTP tools.

Use with the CLI

In automations, use an environment variable:

export ZENIFRA_API_KEY=znf_your_key
zenifra projects --type http --page 1 --limit 15
zenifra deploy --project <project-id> --branch main

To save it locally:

zenifra auth api-key --key znf_your_key

Because the API key is already linked to an organization, automation commands do not need org set. Personal commands, such as listing organizations, still require user login.

Permissions and scope

The API key uses the same organization permission model. Grant only what the automation needs.

Examples:

  • deploy a specific project;
  • read logs and metrics;
  • create projects from a pipeline;
  • inspect builds;
  • rotate controlled operational resources.

If a key leaks, the impact is limited by the granted permissions and allowed IPs.

When a permission is missing

A call without the required permission responds 403 with message: "insufficient organization permission". When the operation depends on a specific scope, the response says which one:

{
  "status": "failed",
  "message": "insufficient organization permission",
  "required_permission": { "resource": "organization", "action": "template.create" },
  "hint": "This API key (or the member who created it) does not have template.create. Use a key that includes it, or the Console.",
  "docs_url": "https://docs.zenifra.com/pt/docs/organizations/api-keys#catálogo-completo-de-scopes"
}

required_permission appears when the operation depends on a single scope, and hint explains what to do. To fix it, create a key with that scope (in the Console, the Full automation template already includes template.create) or ask the owner for the permission. The CLI shows this guidance right in the error.

Effective scope

On every request, the key is worth only the intersection between the scopes granted to it and the current permissions of its creator in the organization (direct or inherited from policies). Keys created by the owner are worth their full granted scope while that person remains owner.

  • If the creator loses a permission, through a role change, direct permission change, linked policy change, or the edit or removal of a policy, the key loses the same access immediately, without being edited. If the creator gets the permission back, the key is worth it again, up to its own scopes.
  • If the creator is no longer an active member of the organization or deletes their account, the key stops authenticating and requests receive 401.
  • On an ownership transfer, the former owner becomes a member without permissions, so the keys they created lose access until the new owner grants them permissions. Before transferring, create the keys for critical automations with the new owner or a dedicated member.

When an API Key creates a project, the key itself receives project.read, project.image.update and project.deploy.trigger on the new project, so the pipeline can publish to it. The key creator, when not the owner, receives the same grants.

Complete scope catalog

The permissions.resources field accepts the scopes below. Use * only when the automation truly needs every resource of that type; for least privilege, provide the ID of the matching organization, project, database, service, or key.

Projects and Previews

ScopeUse
project.createCreate HTTP applications and scheduled Jobs, including from templates. Use on organization:*.
project.readRead a specific project.
project.logs.readRead logs, builds, and Job execution logs.
project.metrics.readRead metrics, capacity, and operational usage.
project.network.visitors.readRead visitor data: individual request events (with source IP and user agent) and the source IPs with the highest volume.
project.billing.readRead project or Preview usage and costs.
project.env.readRead environment variables without exposing the key. Without project.env.secrets.read, sensitive values come back masked.
project.env.secrets.readSee the values of environment variables (without it, names only). See Protected values.
project.env.updateUpdate environment variables.
project.name.updateChange a project name.
project.description.updateChange a project description.
project.domain.updateChange exposure, domain, and custom domains.
project.network.updateChange network access rules.
project.instances.updateChange instances, auto-scaling, health check, and alerts.
project.image.updateChange the published image.
project.source.updateRead or change the code integration.
project.schedule.updateChange the schedule of a scheduled Job.
project.job-run.cancelCancel a running execution of a scheduled Job.
project.deploy.triggerTrigger a publication.
project.stopStop a project.
project.resumeResume a project.
project.plan.updateChange plan or automatic renewal.
project.storage.updateChange storage size.
project.deleteRemove a project.
project.preview.readRead Preview settings, plans, list, and details, and follow their operations.
project.preview.configureEnable or change Preview settings.
project.preview.deployCreate or update a Preview, read its details, and follow its operation. Creating or updating also requires project.env.read or project.image.update on the primary project.
project.preview.deleteRemove a Preview.

Templates

ScopeUse
template.createCreate a private template. Use on organization:*.
template.readRead an authorized template.
template.updateEdit an authorized template.
template.publishPublish or make a template private.
template.deleteRemove a template.

Databases

ScopeUse
database.createCreate PostgreSQL, MariaDB, or ClickHouse (Analytics). Use on organization:*.
database.status.readRead a database state.
database.connection.readRead authorized connection data.
database.password.rotateRequest a password rotation.
database.version.updateUpdate the database version.

Managed services

ScopeUse
managed_service.createCreate Valkey services with the Key-Value, Cache, or Queue profile. Use on organization:*.
managed_service.readNot currently exposed to organization API Keys.
managed_service.status.readRead a service state.
managed_service.connection.readRead connection data without credentials.
managed_service.credentials.rotateRequest credential rotation.
managed_service.version.updateNot currently exposed to organization API Keys.
managed_service.metrics.readNot currently exposed to organization API Keys.
managed_service.lifecycle.updateNot currently exposed to organization API Keys.
managed_service.deleteNot currently exposed to organization API Keys.

AI

ScopeUse
ai_key.createCreate an AI key. Use on organization:*.
ai_key.readRead an authorized AI key.
ai_key.updateChange an AI key budget.
ai_key.deleteRemove an AI key.
ai_usage.readRead AI usage and costs; it can be limited to one AI key ID.

Organization API keys

ScopeUse
api_key.createCreate an organization API key. Use on organization:*.
api_key.readRead authorized API keys.
api_key.updateEdit the name, expiration and allowed IPs of an authorized API key.
api_key.deleteRevoke an authorized API key.

Billing

ScopeUse
billing.readRead the organization's payment configuration.
billing.payment.configureConfigure or start linking a payment method.
billing.transactions.readRead organization transactions.
billing.checkout.createCreate checkout in an authorized integration.

Organization administration

ScopeUse
member.inviteInvite a member. User session only; does not work with an API Key.
member.permissions.updateChange member permissions and policies. User session only; does not work with an API Key.
member.logins.readView members' sign-in times. User session only; does not work with an API Key.

Member, invitation, and policy administration, as well as personal actions such as listing organizations, accepting invitations, or changing account data, require a user session.

Minimum key for operating a Preview

After Preview is enabled on the primary project, an automation that only needs to create/update, read, and remove a Preview should receive only these grants on the primary project:

{
  "resources": {
    "project": {
      "<project-id>": [
        "project.read",
        "project.env.read",
        "project.preview.read",
        "project.preview.deploy",
        "project.preview.delete"
      ]
    }
  }
}

A Preview inherits the primary project's environment variables, so creating or updating a Preview requires project.env.read or project.image.update on the primary project. Without either, the API responds 403 with code: "PREVIEW_ENV_ACCESS_REQUIRED".

project.preview.configure is not required for the operational lifecycle. Preview settings accept organization API Keys: reading them requires project.preview.read and changing them requires project.preview.configure. Grant project.preview.configure only to automation that really needs to enable or change Previews. To read Preview costs, add project.billing.read separately.

Minimum requirement per operation

Each scope below is limited to the same project-id of the primary project:

OperationMinimum scopeResource ID
Read the primary projectproject.readproject:<project-id>
Read Preview settings, plans, and listproject.preview.readproject:<project-id>
Change Preview settingsproject.preview.configureproject:<project-id>
Create or update a Previewproject.preview.deploy and project.env.read (or project.image.update)project:<project-id>
Read Preview details or operationproject.preview.read or project.preview.deployproject:<project-id>
Remove a Previewproject.preview.deleteproject:<project-id>
Read Preview costsproject.billing.readproject:<project-id>; optional

Therefore, automation running the complete lifecycle needs exactly the five scopes in the previous example. Do not add project.preview.configure if the automation does not change Preview settings.

IP allowlists

When creating the key, enter fixed IPs that may call the API. When the list is not empty, requests from other IPs are rejected with 403 and code: "API_KEY_IP_NOT_ALLOWED".

Use IP allowlists when automation runs on:

  • self-hosted runners;
  • internal servers;
  • corporate NAT;
  • jobs with a known egress IP.

The field accepts literal IPv4 and IPv6 addresses. CIDR is not accepted. IPv4 addresses represented in IPv6 form (such as ::ffff:203.0.113.10) are compared as the corresponding IPv4 address.

Revocation and rotation

Revoke a key when:

  • it is no longer used;
  • its owner left the team (when a member is removed from the organization, or deletes their account, the API Keys and AI keys they created are revoked automatically);
  • the source IP changed;
  • a leak is suspected;
  • the permissions became too broad.

For safe rotation, create a new key, update the automation, validate usage, and revoke the old key.

Next steps

Last updated on

On this page