Authentication and credentials
The difference between API keys, session tokens, and browser sessions; three ways to pass them, scope limits, and common authentication errors.
The Grape API accepts four credential types. Choose the right credential first, then decide how to pass it.
1. Four credential types
| Credential | Form | Used by | Lifetime |
|---|---|---|---|
| User-level API key | grape_... |
Scripts, CI, long-term integrations | Valid until manually revoked |
| Session token | tk_... |
During Agent task execution | Invalid after the task ends, times out, or fails; up to 6 hours |
| Browser session | Login Cookie/JWT | Web console | Invalid when the session expires |
| Takeover token | tko_... |
A local Agent taking over a running task | Invalid when the takeover session ends or expires (12 hours by default) |
Selection rules:
- A person writing scripts, CI, or external systems: use a
grape_API key - An Agent calling from within a task: use the injected
tk_ - A browser page: use the login session
Do not treat tk_ as a long-term key, and do not give grape_ to an Agent that executes tasks.
A takeover token tko_ carries repo_session + review_decide: it can call repository read/write endpoints (git-repo proxy, workspace, git-credential) and submit review verdicts (review-pass / review-reject), but cannot call other agent-self endpoints such as pending-review or awaiting-input. It has no user_scope, so the final finish must switch to a user-level credential.
2. Create and revoke API keys
Generate them in User settings → API Keys.
- The plaintext is returned only once, at creation
- The server stores only a hash and cannot recover it
- Revoke a key immediately when it is no longer used
- Use a separate key per system to simplify attribution and revocation
API keys also have create, list, and revoke endpoints with the scope user_only; see the Settings API.
3. Three ways to pass credentials
Pick one; do not send several conflicting credentials at the same time.
| Method | Header/parameter | Suitable for |
|---|---|---|
Authorization |
Bearer <api-key> |
Recommended, general |
PRIVATE-TOKEN |
<api-key> |
GitLab-style clients |
access_token |
?access_token=<api-key> |
Temporary debugging; not recommended for long-term use |
Priority:
Authorization > PRIVATE-TOKEN > access_token
Use a header file instead of putting the key on the command line
read -rs GRAPE_API_TOKEN
umask 077
AUTH_NAME="Authorization:"
AUTH_SCHEME="Bearer"
echo "$AUTH_NAME $AUTH_SCHEME $GRAPE_API_TOKEN" > ~/.grape.auth
curl -fsS -H @~/.grape.auth "https://<your-domain>/api/auth/profile"
The
access_tokenquery parameter appears in access logs, proxy logs, and browser history. Do not use it for long-term integrations.
4. Scope: which credential an endpoint accepts
Every endpoint in the OpenAPI contract carries x-token-scope, which determines the credential types it accepts:
| scope | Accepted credentials | Typical endpoints |
|---|---|---|
user_only |
grape_ API key / web JWT |
Settings, credentials, Skill writes, scene management |
session_only |
tk_ only |
Git repository passthrough, actions during Agent execution |
dual |
All three | Open reads, Issues repository views, A2A |
Notes:
- Scope is about the token type, not the way it is passed
- Calling a
user_onlyendpoint withtk_returns403 - Calling a
session_onlyendpoint withgrape_also returns403
See the corresponding resource page for the scope of a specific endpoint.
5. Common request conventions
| Header | When it is required | Description |
|---|---|---|
Authorization |
Authenticating with a header | Bearer <api-key> |
PRIVATE-TOKEN |
Authenticating GitLab-style | Put the key directly |
Content-Type |
The request has a body | application/json |
Accept |
A streaming response is required | text/event-stream |
6. Responses and errors
4xx business errors are always placed in detail:
{
"detail": {
"code": 403,
"message": "Session token not allowed on this endpoint",
"error_code": "SESSION_TOKEN_NOT_ALLOWED"
}
}
500 fallback:
{
"code": 500,
"message": "Internal Server Error",
"request_id": "..."
}
Callers branch on code / error_code; do not parse the message text.
7. Common authentication errors
| Status | Meaning | Check first |
|---|---|---|
401 |
No credential, or an invalid or expired key | Whether the header is present, and whether the key was revoked |
403 + SESSION_TOKEN_NOT_ALLOWED |
A user-level endpoint was called with tk_ |
Use grape_ or a web JWT instead |
403 + scope related |
Credential type does not match the endpoint | Check the scope on the endpoint page |
403 + account disabled |
The account is disabled or deactivated | Contact an administrator; do not retry |
429 |
Rate limit triggered | Back off according to retry_after |
8. Security practices
- Keep keys only in environment variables, a secret manager, or a file with mode 600
- Do not write keys into repositories, Issues, chat, or screenshots
- Use a separate key per system; revoke immediately when a person leaves or a system is retired
- Rotate regularly; during rotation, add the new key first and then remove the old one
- Proxies and gateways must not log
Authorizationin plaintext