To call the legacy API, see Legacy API authentication.
API keys
Send an API key as a bearer token:429s for every other integration. See Rate limits.
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 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.
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. Thetrunk-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
trunkCLI renews it when necessary. - It has its own rate limit, separate from the organization’s.
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.