rotate_token
Rotate your agent token to revoke a compromised secret and obtain a fresh one. Managed agents get a grace window for both tokens; unmanaged agents require restart.
Instructions
Self-rotate your own agent_token (v2.1).
When to use: scheduled rotation, suspected token leak, or any time you want a fresh secret without losing identity. For admin-driven rotation of someone else's token use rotate_token_admin. To wipe the token entirely use revoke_token.
Behavior: requires the current valid token. For Managed agents (registered with managed:true) the relay enters a grace window during which BOTH old and new tokens authenticate, and a priority='high' push-message carries the new token to the agent so it can self-update. For unmanaged agents (default, Claude Code terminals), the response carries restart_required:true and the old token is invalid immediately.
Returns: { success: true, agent_name, new_token, rotated_at: ISO, agent_class: 'managed' | 'unmanaged' }. Managed-with-grace adds grace_expires_at: ISO, push_sent: boolean, auth_note. Managed-with-zero-grace adds grace_expires_at: null, push_sent: false, auth_note. Unmanaged adds restart_required: true, operator_note.
Errors: NOT_FOUND (unknown agent), INVALID_STATE (auth_state ≠ active — recovery_pending / revoked / legacy_bootstrap / rotation_grace each return a state-specific hint), CONCURRENT_UPDATE (CAS race lost), INTERNAL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_name | Yes | Agent name — must match the token's owner | |
| agent_token | No | Your agent token (from register_agent response). Optional here — also resolvable from RELAY_AGENT_TOKEN env or X-Agent-Token header. | |
| grace_seconds | No | v2.1 Phase 4b.2: override the grace window length for managed agents. Clamped to [0, 3600]. 0 forces hard-cut (immediate invalidation) even for managed agents. Unmanaged agents ignore this field (no grace applicable). Default: RELAY_ROTATION_GRACE_SECONDS env var (fallback 900). |