API keys
Send an API key as a bearer token:The organization API token (Settings → Organization → General → API Token) works only with the v1 API. The Trunk Analytics CLI and
trunk-io/analytics-uploader don’t accept API keys yet, so keep using the organization API token with them.429s. See Rate limits.
Create an API key
Only an organization admin can create an API key. In the Trunk app:- Navigate to Settings → Developer → API Keys and click the Create Key button.
- Name the key after what will use it, such as
ci-submitorgrafana. Names must be unique among your organization’s active keys. - Select the permissions the key needs. None are selected by default.
- 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.
trunk_v2_, so you can add that prefix to your secret scanner. To trace a leaked value to its key, match its first characters in the API Keys list, which also shows who created each key.
Permissions
Every key can read your organization’s merge queues, so a dashboard or Prometheus scrape needs no permissions. Each permission below 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. A request that the key isn’t permitted to make returns
403 INSUFFICIENT_PERMISSIONS and changes nothing.
Permissions apply only to merge queues and test-results uploads. Any API key can call the other Flaky Tests and Dynamic CI endpoints, including writes.
Change or delete a key
An organization admin manages keys in the same API Keys list.- To change a key’s permissions, open the key and edit them. Its value stays the same, and the change applies within a minute.
- To delete a leaked or unused key, open the key’s menu and click Delete. Deletion takes effect on the next request. Deleting can’t be undone.
GitHub Actions
A GitHub Actions job can upload impacted targets without an API key. Thetrunk-io/login action exchanges the run’s GitHub credential for a short-lived Trunk login, which can upload impacted targets for that repository and nothing else. See Upload impacted targets from GitHub Actions for setup, forks, and security.
The x-trunk-token header
Endpoint pages also list x-trunk-token. This header carries a short-lived Trunk login that Trunk’s own tools use: the trunk CLI after trunk auth login, and trunk-io/login. Use an API key instead, and never send both headers on one request.
Authentication errors
Trunk checks credentials at its edge, so authentication failures may lack the API’s 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.