Authorization request header. This makes integration straightforward: generate a key once, store it securely, and include it with every call.
This page covers the Public API only. For browser session login and a side-by-side comparison of both methods, see Authentication.
Creating an API Key
API keys are managed from your Terminus Hub account settings. Navigate to Account → API Keys to generate a new key. Each key is shown only once at creation time. Copy it immediately and store it in a secure location such as a secrets manager or environment variable.API keys are prefixed with
thub_ to make them easy to identify in logs and configuration files. If a key does not start with thub_, it is not a valid Public API key.Sending the Authorization Header
Include your API key on every request using theAuthorization header with the Bearer scheme:
thub_xxxxx with your actual API key. The header is required for all endpoints. There are no public, unauthenticated routes in the Public API.
Code Examples
The examples below show how to authenticate in three common environments. Replacethub_xxxxx with your API key.
Authentication errors
When authentication fails, the API responds with HTTP 401 and anerror object whose type is authentication_error. For a missing, malformed, or unrecognized key, code is null and message is Invalid API key.
What causes an authentication error
A401 authentication_error is returned whenever the key isn’t recognized, most often because the key is missing, was mistyped or truncated, has been revoked, or doesn’t begin with Bearer thub_. Authentication failures don’t carry a finer-grained code (it is null), so branch on the HTTP status and error.type rather than on a code.
Security Best Practices
Protecting your API key is critical, because anyone who holds it can make requests on your behalf.- Use environment variables: store keys in environment variables (e.g.,
TERMINUS_API_KEY) and read them at runtime rather than hard-coding them in source files. - Use one key per integration: every key carries the same full account access, so create a separate key for each integration. You can then revoke one without disrupting the others.
- Rotate keys periodically: regularly cycle your API keys as a precaution, even if there is no known compromise.
- Never commit keys to version control: add secrets files to
.gitignoreand audit your repository history if a key was accidentally committed.