Skip to Content
Docs
API

Personal Access Tokens

A personal access token (PAT) lets a script, the DocsGPT CLI or a CI/CD pipeline act on your account without a browser session. Unlike an agent API key, which can only talk to one agent, a PAT manages resources: it can create and update agents, upload sources, edit prompts and tools, and run agents for benchmarking.

Every token is limited in three ways:

  • Scopes decide which parts of the API the token may call.
  • Resource restrictions (optional) narrow a token to specific agents, sources, prompts, tools or workflows.
  • Expiry ends the token’s life automatically.

Creating a token

  1. Open Settings → Access Tokens in the DocsGPT web app.
  2. Choose Create token, give it a name, and select the scopes it needs.
  3. Optionally restrict it to specific resources and pick an expiry.
  4. Copy the token. It starts with dgpt_pat_ and is shown once. DocsGPT stores only a hash of it, so a lost token cannot be recovered. Revoke it and create a new one.
  5. Optionally, select Create tool for agents to let your agents use the token. See Let an agent work in your account.

Tokens can only be created, regenerated and revoked from a signed-in session. A token cannot create, list, regenerate or revoke tokens, so a leaked token cannot mint a replacement for itself.

Using a token

Send the token as a bearer credential:

export DOCSGPT_URL=https://docsgpt.example.com
export DOCSGPT_TOKEN=dgpt_pat_...

curl -H "Authorization: Bearer $DOCSGPT_TOKEN" "$DOCSGPT_URL/api/user/me"

GET /api/user/me works with any valid token and reports what the token may do, which makes it a convenient first step in a pipeline:

{
  "success": true,
  "user_id": "alice@example.com",
  "roles": ["user"],
  "auth_method": "pat",
  "token": {
    "id": "0b6c...",
    "name": "ci-deploy",
    "scopes": ["agents:read", "agents:write"],
    "resource_filter": {}
  }
}

Applying agent definitions

Agents can be exported to YAML and applied back, which makes them reviewable and deployable like any other configuration. With the CLI:

docsgpt-cli agents export <agent-id> -o support-bot.agent.yaml
docsgpt-cli agents apply -f support-bot.agent.yaml --dry-run
docsgpt-cli agents apply -f support-bot.agent.yaml

Or with the API directly (agents:write):

curl -X POST "$DOCSGPT_URL/api/import_agent/plan" \
  -H "Authorization: Bearer $DOCSGPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -Rs '{yaml: .}' support-bot.agent.yaml)"

Sources are matched by name, and when several of your sources share a name the oldest one wins. A pipeline that re-uploads documentation on every push should therefore upload with docsgpt-cli sources upload ... --wait --replace (which removes the older same-named sources) and run agents apply afterwards, or the agent stays bound to the first upload.

/api/import_agent/plan is a dry run that reports whether the agent would be created or updated and how each referenced source, tool and prompt resolves. /api/import_agent applies it. An agent is matched by metadata.id, then metadata.slug; when nothing matches, a new draft agent is created.

GitHub Actions example

jobs:
  deploy-agents:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Apply agent definitions
        env:
          DOCSGPT_URL: ${{ vars.DOCSGPT_URL }}
          DOCSGPT_TOKEN: ${{ secrets.DOCSGPT_TOKEN }}
        run: |
          docsgpt-cli sources upload docs/*.md --name "Product docs" --wait --replace --idempotency-key "docs-${{ github.sha }}"
          docsgpt-cli agents apply -f agents/

Reading workflow runs

A token with chat:run starts a workflow agent’s run over /stream. The first event of the stream names the run:

{"type": "workflow_run", "workflow_run_id": "6b1f0c2e-...", "step_total": 3}

With runs:read the token reads that run once it ends (or while it runs: status is running and progress says which step it is on):

curl -H "Authorization: Bearer $DOCSGPT_TOKEN" \
  "$DOCSGPT_URL/api/workflow_runs/$RUN_ID?include=steps,state,artifacts"
{
  "success": true,
  "run": {
    "id": "6b1f0c2e-...",
    "agent_id": "3f0e8f0c-...",
    "workflow_id": "9a2d...",
    "status": "completed",
    "query": "Extract the delivery terms",
    "started_at": "2026-10-29T10:00:00+00:00",
    "ended_at": "2026-10-29T10:00:12+00:00",
    "duration_ms": 12000,
    "error": null,
    "steps": [
      {"node_id": "extract", "node_type": "agent", "status": "completed", "duration_ms": 11800,
       "error": null, "tool_calls": [{"tool_name": "read_document", "action_name": "read", "status": "completed"}]}
    ],
    "state": {"query": "Extract the delivery terms", "terms": {"days": 30}},
    "state_truncated": [{"key": "report", "bytes": 81920}],
    "artifacts": [
      {"id": "c41e...", "filename": "terms.xlsx", "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
       "download_url": "/api/workflow_runs/6b1f0c2e-.../artifacts/c41e.../download"}
    ]
  }
}
  • include picks the extras: steps (each step’s status, timing, error and tool calls, and a loop node’s items with their own steps), state (the run’s final state) and artifacts (the files the run produced; its input documents are left out). Without include the run comes back with its status and timing only.
  • A state value larger than 32 KB is left out of state and listed in state_truncated. Fetch it whole with ?state_key=report.
  • error is the first failed step’s error when the run failed.

GET /api/workflow_runs/<run_id>/steps/<step_index> returns one step whole: its output and state_delta, which a stream event too large to send whole left out. step_index comes from the workflow_step event (see Step details in the stream). While the run is still going it answers 409 with "code": "step_not_saved_yet", since steps are saved when the run ends.

GET /api/workflow_runs lists the runs you started, newest first, with the same status and timing fields. Filter it with agent_id, since (an ISO 8601 moment), status (pending, running, completed or failed) and limit (1 to 100, default 20).

With artifacts:read the token downloads a file the run produced from its download_url. Without the scope the download answers 403 with "error": "insufficient_scope". artifacts:read also lets an unrestricted token list, read and download its other artifacts through /api/artifacts and /api/artifacts/<id>/download; deleting or restoring an artifact still needs a session.

A run is read by the person who started it; anyone else’s run, and a run outside a restricted token’s agents, answers 404.

Scopes

A write scope includes the matching read scope.

ScopeAllows
agents:readView agents, agent folders, guardrail events and export agent definitions
agents:writeCreate, update, delete, share and import (apply) agents, and manage agent folders and file agents in them
agents:keysRegenerate agent API keys and read incoming webhook URLs
sources:readView sources, their files, chunks and ingestion task status, and Knowledge folders
sources:writeUpload, ingest, sync, edit and delete sources and chunks, and manage Knowledge folders and file sources in them
prompts:read / prompts:writeView / create, update and delete prompts
tools:read / tools:writeView / create, update and delete tools and MCP servers
models:read / models:writeView models and your task model / manage your custom models and set your task model. A team’s custom models are read-only to a token
workflows:read / workflows:writeView / create, update and delete workflows
schedules:read / schedules:writeView / create, update, run and delete agent schedules
conversations:read / conversations:writeView / rename, delete and rate conversations
analytics:readView usage analytics and logs
teams:readView teams, members and resource shares, and list your workspaces (GET /api/workspaces)
runs:readView the workflow runs you started: status, steps, final state and the files they produced
artifacts:readDownload files your workflow runs produced, and view and download your artifacts
chat:runAsk agents, search sources and list an agent’s starters (/api/answer, /stream, /api/search, /api/agent_starters); used for benchmarking

agents:keys is separate from agents:write on purpose. Creating, publishing or adopting an agent mints its API key; a token without agents:keys gets the key back masked (1234...90ab), because an agent key keeps working after the token that saw it is revoked. Put differently: a deployment token that updates agents does not need to be able to read or rotate the secrets other systems use to call them.

Some parts of the API are never available to a token, whatever its scopes:

  • token management, the admin API and sign-in flows;
  • changing teams, their members and grants (reading them needs teams:read), and who may edit a shared resource or wiki;
  • connectors and connections, including their OAuth handshakes, and the MCP server OAuth handshake;
  • all remote device routes, not only pairing;
  • changing artifacts (deleting one or restoring a version), speech-to-text and text-to-speech;
  • conversation sharing and shared links, and file download;
  • the OpenAI-compatible /v1 API (use an agent API key) and the live event stream /api/events;
  • Activity (/api/activity/now, /api/activity/planned, /api/activity/history) and stopping a running answer (POST /api/messages/<message_id>/cancel), because they span every chat and agent of the account;
  • Draft with DocsGPT (/api/drafter/config, /api/drafter/stream, /api/drafter/topics/status), because a draft reads the whole workspace and runs the model on it;
  • the agent webhook trigger, whose URL is its own credential;
  • moving items between Personal and a team (/api/workspace_moves/plan, /api/workspace_moves), because a move changes who owns them and re-seals their credentials.

The REST API reference shows, for each endpoint, the scope a token needs or that tokens can’t call it. A token also never carries the admin role, even when its owner is an admin.

Authorization is deny by default. An endpoint that is not explicitly mapped to a scope cannot be called with a token, and answers 403 with "error": "not_available_to_tokens". A mapped endpoint called without the scope answers 403 with "error": "insufficient_scope" and names the required_scope.

Team workspaces

A token acts as you, in your Personal workspace by default. To list or create in a team workspace, send the X-DocsGPT-Workspace header (or the workspace query parameter) with the team’s id; see Work in a team workspace. The token gets what your team role allows there, within its scopes: a token of a Viewer can’t create in the team. If you leave the team, the token loses access to it on the next request.

  • GET /api/workspaces lists your workspaces and needs teams:read.
  • Moving items into or out of a team can’t be done with a token.
  • The tool for agents has a list_workspaces action when the token has teams:read, and its list and create actions (such as list_agents, create_agent, list_sources, create_prompt, list_folders and file_in_folder) take a workspace parameter: a team id from list_workspaces, or empty for Personal. A tool created before this release has no such parameter; create a new token and tool to get it.

Resource restrictions

A token can be narrowed to specific resources in any of these families: agents, sources, prompts, tools, workflows. A family that is not listed stays unrestricted within the token’s scopes.

{
  "name": "support-bot-deploy",
  "scopes": ["agents:write", "chat:run"],
  "resource_filter": { "agents": ["3f0e8f0c-5a53-4f0e-9a39-0e5f4f8d2c11"] },
  "expires_in_days": 30
}

For a restricted family the token:

  • can read, update and delete only the listed resources, and listings show only those;
  • cannot create new resources of that family, since a new resource would be outside the list;
  • cannot attach a resource outside the list to something else, for example set an agent’s source to a source the token may not use;
  • is refused (403, "error": "resource_not_allowed") wherever DocsGPT cannot prove the request stays inside the list:
    • Conversations, analytics and message replay (/api/messages/<id>/tail, /api/messages/<id>/events) are closed to every restricted token. They span all agents and contain cited source text and tool output.
    • Schedules run an agent with a free-form instruction and store the output. A token restricted to agents can list and create schedules for its agents; every other schedule route, and schedules altogether for tokens restricted on another family, are closed.
    • Workflow writes are closed to tokens restricted on sources, tools or prompts, because a workflow graph names those inside its nodes. Such a token also cannot attach a workflow to an agent unless it is restricted on workflows too, in which case only the listed workflows can be attached.
    • Workflow runs belong to the agent that ran them. A token restricted to agents lists and reads only those agents’ runs and downloads only their files; any other run, and a run started from the workflow builder’s preview, answers 404. Runs and their files are closed to tokens restricted on another family, and the /api/artifacts routes are closed to every restricted token.
    • /api/sources/paginated is closed to source-restricted tokens (use /api/sources).
    • Folders (/api/folders and the /api/agents/folders routes) aren’t on any list. A token restricted on agents can list agent folders and file the listed agents with POST /api/folders/items, but not create, rename, move or delete agent folders; a token restricted on sources gets the same for Knowledge folders and the listed sources.
    • Knowledge folders on agents and in chat: a folder brings in every source filed in it, which no list names, so a token restricted on sources is refused for a non-empty folders on POST /api/create_agent and PUT /api/update_agent/<agent_id>, and for active_folders in chat.
    • The chat prompt (/api/user/preferences): a token restricted on prompts can’t read it, since the stored pick may be outside its list. It can set it to a preset (default, creative, strict) or a prompt on its list. Sending only_if_unset is refused (403, resource_not_allowed), since the answer could carry a stored pick outside its list.
    • The chat prompt (/api/user/preferences): a token restricted on prompts never reads it, since the stored pick may be outside its list. With models:read it still reads the task model fields from the same route, and the answer leaves the chat prompt fields out; without models:read the read is refused. It can set the chat prompt to a preset (default, creative, strict) or a prompt on its list. Sending only_if_unset is refused (403, resource_not_allowed), since the answer could carry a stored pick outside its list. Setting the task model through the same route (task_model_id) needs models:write instead of prompts:write, and names no prompt, so the prompt list doesn’t limit it.

A restriction covers what the token asks for, not what an allowed resource already contains: an agent on the list runs with its own sources, prompt and tools even when the token is also restricted on those families. List an agent only if you are happy for the token to use everything that agent uses.

Restrictions and chat (chat:run):

  • A token restricted to specific agents must pass exactly one agent_id in the request body, and it must be one of the listed agents. An agent api_key or an inline workflow in the body is refused.
  • A token restricted to specific sources only may chat against those sources with active_docs. It cannot run agents, because an agent brings its own sources. Restrict the token to agents instead to allow that.
  • A token restricted on prompts or workflows must also be restricted to agents to chat.
  • A token restricted on tools cannot use chat at all, and a tools restriction cannot be combined with chat:run when the token is created. Chat executes tools (an agent’s own, or your default tools when there is no agent) and those cannot be held to a list.
  • A conversation_id must belong to the agent being run (or to no agent, for agent-less chat). Otherwise the server would continue, append to, or resume pending tool calls of another agent’s conversation.
  • Listing an agent’s starters (/api/agent_starters) takes only the agent’s api_key, so a restricted token cannot call it. The endpoint needs no token at all: the agent key is its credential.

agents:write and import: applying an agent definition can create or edit the prompt and create the tools it references and rewrite the agent’s workflow, all under agents:write alone. It does not need prompts:write, tools:write or workflows:write, so treat agents:write as able to create those, and edit the agent’s own prompt, through an import.

Restrictions and agents apply: a token restricted to specific agents can apply a definition only when it updates one of those agents. A token restricted on sources, prompts, tools or workflows cannot import agents at all, because an import resolves those references by name and may create them.

Expiry and revocation

  • A token created without an explicit lifetime expires after PAT_DEFAULT_LIFETIME_DAYS (90 by default). Users can choose any lifetime up to PAT_MAX_LIFETIME_DAYS (365 by default).
  • Non-expiring tokens are available only when the operator sets PAT_ALLOW_NON_EXPIRING=true.
  • Regenerate in Settings → Access Tokens issues a new secret for the same token and resets its expiry. The name, scopes and restrictions stay; the old secret stops working immediately, so update whatever uses it. The new lifetime defaults to the one the token was last issued with, and an expired token can be renewed this way (a revoked one cannot). This is the way to rotate a secret or extend a token without rebuilding its scopes.
  • Revoking a token in Settings → Access Tokens takes effect on the next request.
  • Admins can list a user’s tokens with GET /api/admin/users/<user_id>/tokens and revoke any token with DELETE /api/admin/tokens/<token_id>. The admin revoke sessions action also revokes all of that user’s tokens.
  • Tokens of a deactivated user (through the admin API or SCIM) stop working immediately and work again if the user is reactivated.
  • GET /api/user/tokens reports a token past its expiry as "status": "expired".
  • Token creation and revocation are recorded in the authentication audit log (pat_created, pat_regenerated, pat_revoked), visible to admins.

An expired token’s name can be reused: creating a token with that name retires the expired one.

Each user may hold up to PAT_MAX_PER_USER live tokens (25 by default). The token list shows when and from which IP address each token was last used.

Operator settings

SettingDefaultPurpose
PAT_ENABLEDtrueMaster switch. When false, tokens cannot be created and every existing token stops authenticating immediately
PAT_DEFAULT_LIFETIME_DAYS90Lifetime of a token created without an explicit expiry
PAT_MAX_LIFETIME_DAYS365Longest lifetime a user may request
PAT_ALLOW_NON_EXPIRINGfalseLet users create tokens that never expire
PAT_MAX_PER_USER25Maximum number of live tokens per user

Personal access tokens need a stable user identity, so they are available with AUTH_TYPE=oidc and with authentication disabled (single-user self-hosting). They are not available with simple_jwt or session_jwt.

Turning PAT_ENABLED off, or switching AUTH_TYPE to simple_jwt or session_jwt, is not limited to the settings page: every pipeline that uses a token starts getting 401 right away. Tokens are not deleted and work again once the setting is restored. See the Settings Reference for details.

Management API

These endpoints need a signed-in session and cannot be called with a token.

EndpointPurpose
GET /api/user/tokensList your tokens, the scope catalog and the server’s token policy
POST /api/user/tokensCreate a token. Body: name, scopes, optional resource_filter, optional expires_in_days (0 = never, when allowed). The response carries the plaintext token once
POST /api/user/tokens/<id>/regenerateNew secret and new expiry for the same token. Optional body expires_in_days; omitted = the lifetime it was last issued with. The response carries the plaintext token once
DELETE /api/user/tokens/<id>Revoke a token
POST /api/user/tokens/<id>/toolCreate an API tool that lets agents work in this account with the token. Body: the plaintext token and base_url, where agents reach the API. The tool gets an action for each endpoint the token may call; the response lists them in actions, and those that start switched off in inactive

Let an agent work in your account

Create tool for agents, offered once when a token is created, adds an API tool named DocsGPT API (token name) under Settings › Tools. Add it to an agent and the agent can do in your account what the token’s scopes allow: create and update agents, add sources and wiki pages, edit prompts, tools and workflows, manage schedules, and read conversations, logs and analytics. The token is stored, encrypted, as the tool’s Authorization header; neither the model nor the chat sees it.

The tool has one action per endpoint the token may call, so its scopes and resource restrictions decide what the agent gets: a token with prompts:write brings list_prompts, create_prompt, update_prompt and delete_prompt, and one with every scope brings about 120 actions. Each action’s description is sent to the model with every request, so give the token only the scopes the agent’s job needs. The actions are fixed when the tool is created. To change them, create a new token and tool.

Some actions start switched off, and you turn them on in the tool when you want them:

  • Deletes (delete_agent, delete_source, delete_chunk, delete_prompt, delete_tool, delete_workflow, delete_schedule, delete_conversation, delete_agent_folder), because they cannot be undone.
  • ask_agent, which runs another agent for real and spends its tokens.

A few things a token can do are never given to an agent:

  • Deleting all conversations at once.
  • Creating, changing or deleting custom models, which hold a provider key and the address every chat is sent to.
  • Uploading files, importing an agent definition and streaming chat, which an API tool cannot send.

A token cannot change a tool that holds an access token, this one included: update_tool and the other tool update endpoints answer 403. So an agent cannot switch on an action you left off, or point an action at another endpoint. Change the tool yourself, signed in, under Settings › Tools.

An agent that can change tools still cannot read or move a credential a tool stores. Stored values come back masked, a tool or MCP server pointed at another server does not keep them, and connections and their OAuth sign-ins are closed to every token.

Treat the agent like the token: anyone who can chat with an agent that has this tool can ask it to act on your account, and so can text the agent reads, such as a web page or a document in a source. Do not add the tool to an agent you share publicly, and prefer read scopes for an agent that reads content you do not control.

The tool calls the API at the address this web app uses. Agent tools can’t call localhost or private IP addresses, so on an instance reached at such an address the button reports that agents can’t reach it and creates nothing.

Good practice

  • Give each pipeline its own token with the narrowest scopes that work, and name it after where it is used.
  • Store tokens in your CI system’s secret store. Never commit them. The dgpt_pat_ prefix lets secret scanners recognise them.
  • Prefer short lifetimes for tokens used by automation you can easily re-provision.
  • Revoke a token as soon as it is no longer needed or may have been exposed.
Edit this page on GitHub

Last updated on

On this page