Log in Create workspace
Skip to content

API reference

Operator - API Credentials

Issue and retire narrowly scoped machine credentials without exposing stored secrets.

Jump to 6 endpoints
On this page

Overview

API credentials bind a service agent to the public machine API. These session-only endpoints let operators inspect metadata, choose scopes, rotate a key, or revoke it; the usable secret is returned only when a credential is created or rotated.

A key belongs to one agent
A credential inherits workspace and service-agent identity; it is not an operator login. Public routes then enforce its explicit scopes, such as traces:write or gateway:check. Later list and detail reads expose the prefix and lifecycle fields, never the original secret.
Rotation is a handoff
Rotation returns a replacement secret once, links it to the previous credential, and revokes the old credential in the same transaction. Plan the cutover, store the new value immediately, and deploy it without expecting an overlap window.

Before you begin

  • A signed-in browser session with a selected workspace backed by an active membership is required; an archived workspace remains readable but rejects mutations. Every /api/v1/operator endpoint rejects API credentials and bearer tokens, regardless of their scopes.
  • Use an owner or admin membership for create, update, rotate, and revoke operations. Any role on an active membership can read credential metadata.
  • Create the service agent first and decide which public API scopes its runtime actually needs.

How it works

  1. Inventory before changing

    List a service agent's credentials and compare name, scopes, expiry, last_used_at, and revoked_at. Revoked credentials are omitted from the normal list, so use the known credential detail when investigating historical metadata.

  2. Apply least privilege

    Create or rotate from /app/agents/credentials, capture the one-time secret in an approved secret store, and validate the intended public endpoint. Revoke unused keys after the new deployment is healthy.

Examples

These examples are illustrative. Replace the sample values with your own. Keep credentials in environment variables or a secret manager, never in client-side code.

Inspect an agent's active credentials

This same-origin snippet selects the first visible service agent, then reads its credential metadata. It never prints a usable secret.

javascript
const agentsResponse = await fetch("/api/v1/operator/service_agents", {
  credentials: "same-origin",
  headers: {"Accept": "application/json"}
});
const agentsBody = await agentsResponse.json();
if (!agentsResponse.ok) throw new Error(`${agentsResponse.status}: ${agentsBody.detail}`);
const serviceAgent = agentsBody.service_agents[0];
if (!serviceAgent) throw new Error("Create a service agent before listing credentials");
const response = await fetch(`/api/v1/operator/service_agents/${encodeURIComponent(serviceAgent.id)}/credentials`, {
  credentials: "same-origin",
  headers: {"Accept": "application/json"}
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${body.detail}`);
console.log(body);
What to expect

200 OK. The response wrapper is {"api_credentials": []} when the selected agent has no active credentials; populated items include prefix and scopes but no secret.

Troubleshooting

A scoped machine key still gets 401
That is intentional: operator routes authenticate only the browser session. Sign in and select a workspace through an active membership instead of adding Authorization or x-agent-api-key headers.
An agent or credential is 404
IDs are resolved inside the current workspace. Check the workspace switcher and the UUID; an object from another workspace is deliberately indistinguishable from a missing object.

Endpoint reference

Ready to integrate? Open an endpoint for its required permissions, request fields, response format, and status codes. The examples above explain the workflow; these details define each individual request.

GET
/api/v1/operator/service_agents/:service_agent_id/credentials Web Session

List service agent credentials

Description

Returns the service agent's live (unrevoked, unarchived) API credentials, newest first. Revoked and archived credentials are omitted; GET /api/v1/operator/service_agents/:id includes the full credential history.

Auth

Web Session
Parameters
Name In Type Required Description
service_agent_id path string Yes Service agent UUID
Responses
200

List of credentials

Returns: ApiCredentialList

Example
{
  "api_credentials": [
    {
      "id": "b3ec0b4e-64be-44f3-a5f6-e6f54c8bf190",
      "inserted_at": "2026-02-15T10:00:00Z",
      "last_used_at": "2026-03-27T09:12:10Z",
      "name": "Production API key",
      "prefix": "agk_prod",
      "scopes": [
        "traces:write",
        "gateway:check"
      ],
      "service_agent_id": "f4d49601-3477-4c9d-b896-ac08a26a3147",
      "updated_at": "2026-03-27T09:12:10Z"
    }
  ]
}
POST
/api/v1/operator/service_agents/:service_agent_id/credentials Web Session

Create API credential

Description

Creates a new API credential for a service agent.

Auth

Web Session
Request Body
Field Type Required Description
api_credential object Yes API credential attributes
api_credential.name string Yes Credential name
api_credential.expires_at datetime (ISO 8601) No Optional expiration date
api_credential.scopes array<object> Yes List of scopes to grant
Parameters
Name In Type Required Description
service_agent_id path string Yes Service agent UUID
Responses
201

Credential created (secret shown once)

Returns: ApiCredentialWithSecret

Example
{
  "id": "b3ec0b4e-64be-44f3-a5f6-e6f54c8bf190",
  "inserted_at": "2026-02-15T10:00:00Z",
  "last_used_at": "2026-03-27T09:12:10Z",
  "name": "Production API key",
  "prefix": "agk_prod",
  "scopes": [
    "traces:write",
    "gateway:check"
  ],
  "secret": "agk_prod_xY7kM2pL9vN4qR1wT5jH8mB3",
  "service_agent_id": "f4d49601-3477-4c9d-b896-ac08a26a3147",
  "updated_at": "2026-03-27T09:12:10Z"
}
404

Service agent not found

GET
/api/v1/operator/credentials/:id Web Session

Get credential details

Description

Returns details of an API credential (without the secret).

Auth

Web Session
Parameters
Name In Type Required Description
id path string Yes Credential UUID
Responses
200

Credential details

Returns: ApiCredential

Example
{
  "id": "b3ec0b4e-64be-44f3-a5f6-e6f54c8bf190",
  "inserted_at": "2026-02-15T10:00:00Z",
  "last_used_at": "2026-03-27T09:12:10Z",
  "name": "Production API key",
  "prefix": "agk_prod",
  "scopes": [
    "traces:write",
    "gateway:check"
  ],
  "service_agent_id": "f4d49601-3477-4c9d-b896-ac08a26a3147",
  "updated_at": "2026-03-27T09:12:10Z"
}
404

Credential not found

PATCH
/api/v1/operator/credentials/:id Web Session

Update credential

Description

Updates an API credential's settings.

Auth

Web Session
Request Body
Field Type Required Description
api_credential object Yes API credential attributes to update
api_credential.name string No Credential name
Parameters
Name In Type Required Description
id path string Yes Credential UUID
Responses
200

Credential updated

Returns: ApiCredential

Example
{
  "id": "b3ec0b4e-64be-44f3-a5f6-e6f54c8bf190",
  "inserted_at": "2026-02-15T10:00:00Z",
  "last_used_at": "2026-03-27T09:12:10Z",
  "name": "Production API key",
  "prefix": "agk_prod",
  "scopes": [
    "traces:write",
    "gateway:check"
  ],
  "service_agent_id": "f4d49601-3477-4c9d-b896-ac08a26a3147",
  "updated_at": "2026-03-27T09:12:10Z"
}
404

Credential not found

POST
/api/v1/operator/credentials/:id/rotate Web Session

Rotate credential secret

Description

Rotates an API credential's secret. The new secret is shown once.

Auth

Web Session
Parameters
Name In Type Required Description
id path string Yes Credential UUID
Responses
201

Secret rotated (new secret shown once)

Returns: ApiCredentialWithSecret

Example
{
  "id": "b3ec0b4e-64be-44f3-a5f6-e6f54c8bf190",
  "inserted_at": "2026-02-15T10:00:00Z",
  "last_used_at": "2026-03-27T09:12:10Z",
  "name": "Production API key",
  "prefix": "agk_prod",
  "scopes": [
    "traces:write",
    "gateway:check"
  ],
  "secret": "agk_prod_kP3mN7wQ2vR9xT4jL8hB1cY5",
  "service_agent_id": "f4d49601-3477-4c9d-b896-ac08a26a3147",
  "updated_at": "2026-03-27T09:12:10Z"
}
404

Credential not found

DELETE
/api/v1/operator/credentials/:id Web Session

Revoke credential

Description

Revokes an API credential permanently.

Auth

Web Session
Parameters
Name In Type Required Description
id path string Yes Credential UUID
Responses
204

Credential revoked

404

Credential not found

Where to go next

see also