Skip to main content
Every request to the Trunk API needs a credential. Choose one by where the request comes from: To call the legacy API, see Legacy API authentication.

API keys

Send an API key as a bearer token:
Separate keys don’t get separate limits. Most requests share one organization-wide limit, so one busy key can cause 429s for every other integration. See Rate limits.

Create an API key

  1. In the Trunk app, navigate to Settings → Developer → API Keys and click the Create Key button.
  2. Name the key after what will use it, such as ci-submit or grafana. Names must be unique among your organization’s active keys.
  3. Select the permissions the key needs. None are selected by default.
  4. Copy the key and store it in your secret manager. The key is shown only once. If you lose it, delete it and create a new one.
Keys start with trunk_v2_, so you can add that prefix to your secret scanner. To trace a value to its key, match its first characters in the API Keys list, which also shows who created each key.

Permissions

Permissions are the scopes of an API key. A key without permissions can still:
  • Read your organization’s merge queues, pull requests, and repositories. So a dashboard or a Prometheus scrape needs no permissions.
  • Call every Flaky Tests endpoint in this reference, including writes, such as creating a test collection or a ticket.
Each permission adds writes: A request’s permissions come from its body as well as its endpoint. For example, a submit that sets a priority needs both Merge and cancel PRs and Set priority on PRs. If the key doesn’t have a permission that the request needs, the API returns 403 INSUFFICIENT_PERMISSIONS and changes nothing.

GitHub Actions

A GitHub Actions job can upload impacted targets without an API key. The trunk-io/login action exchanges the run’s own GitHub credential for a short-lived Trunk login. So there’s no Trunk secret to store, and on a public repository it also works on fork pull requests, which get no repository secrets. The credential that the action exchanges depends on the event that started the run: Other events, such as issue_comment, workflow_run, and schedule, are refused. The login has these limits:
  • It can upload impacted targets only (PUT /v2/impacted-targets), and only for the run’s own repository. For all other requests, use an API key.
  • On a fork pull request, it is good only for that pull request and its current head commit.
  • It expires after at most 15 minutes. The trunk CLI renews it when necessary.
  • It has its own rate limit, separate from the organization’s.
For the workflow, fork setup, and security details, see Upload impacted targets from GitHub Actions. The Bazel and Nx actions use this login when you set auth: github-actions.

Authentication errors

Trunk checks credentials at its edge, so some authentication failures don’t have the error envelope. Branch on the status code: Endpoint pages may show 401 with the codes AUTHENTICATION_REQUIRED or INVALID_TOKEN in the envelope. Treat those as examples of the status, not as the body you’ll always receive.