All articles
December 3, 2026

How to Secure API Tokens for Docs Automation

secure-api-tokens-cover.png

DocStar lets your scripts, CI jobs and AI agents work with your documentation through API tokens, and a token that leaks gives someone else the same access. The safest setup is simple: use as few tokens as possible, give each tool its own, keep every token in a secret store instead of a chat or a file, and let your AI agent do the generating, storing and rotating so nobody copies keys around by hand. This guide shows how to do that with DocStar, agent first.

#

Why API tokens for docs need care

In DocStar, scripts, CI jobs and agents prove they may change your docs with a personal API token. It starts with hm_, and it is powerful on purpose. In the words of our API Tokens help page, a token gives full access to the collections in the workspace it was created in. That is exactly what makes automation easy, and exactly why a token pasted into a Slack thread, an issue or a committed .env file is a real risk.

Here is how DocStar tokens behave, so you can plan around them:

Property How it works in DocStar
Who can create one Only the workspace Owner. Admins and Members don't see the Auth Key option.
How many Up to 5 active tokens per workspace
Names Unique within the workspace, including revoked tokens
Expiry None. A token works until you revoke it.
Visibility Shown once at creation. DocStar stores only a fingerprint, and the value is never shown again.
Scope One workspace only, with full access to its collections
Revoking Takes effect immediately and can't be undone
A bad or revoked token Returns 403 "Invalid API token"

Two lines in that table shape everything below. Tokens don't expire, so rotation is your job (or your agent's). And there are only five, so each one should have a clear owner and purpose.

#

The safest token is the one you don't need

Before creating any token, check whether the job needs one at all. With DocStar, most interactive work doesn't.

Your AI assistant signs in instead. When you connect Claude Code, Cursor, Codex or another assistant to the DocStar MCP at https://mcp.docstar.io/mcp (or from your assistant's connector directory), the first time it needs your workspace you sign in to DocStar in your browser. There is no API key to copy. The assistant works only with the workspaces and collections your account can access, with the same permissions you have, and it asks before it changes anything. See Work with AI Assistants (MCP).

So the rule of thumb is:

  • A person working with an assistant: browser sign-in through the DocStar MCP. No token.

  • Unattended automation (GitHub Sync, CI, scheduled scripts): one API token per tool, stored as a secret.

  • An assistant that can't connect to MCP: an Auth Key as a fallback, treated like any other automation token.

#

Let your AI agent handle tokens (the main path)

The riskiest moment in a token's life is the handoff: copying it from one screen and pasting it into another, where it can land in chat history, a terminal log or a screenshot. With DocStar, your coding agent can do the whole handoff without the value ever appearing in the conversation.

#

Step 1: Connect your agent to DocStar

Add the DocStar MCP to your coding agent and sign in once in the browser. Open the agent in the repository you want to sync.

#

Step 2: Give it one prompt

Set up DocStar GitHub Sync for this repo. Generate a new DocStar API token named "GitHub Sync acme-api Dec 2026" (use this repo's name and the current month), save it straight into the GitHub secret DOCSTAR_API_KEY with gh secret set, and never print the token in chat, logs or files. Then list my existing DocStar API tokens and tell me which ones look unused, duplicated or unclear. Don't revoke anything without asking me first.

#

Step 3: What the agent does

  • Creates the token through the DocStar API. The value is returned once.

  • Stores it as the DOCSTAR_API_KEY repository secret, which is where the GitHub Sync workflow expects it. The DocStar quickstart your agent follows says to save the key as a GitHub secret and never commit it or show it in chat.

  • Adds the workflow and docstar.md, so every push that changes api-docs/ or docs/ syncs to your collection.

  • Lists your tokens with their name, status, created and revoked dates (never their values) and flags anything worth a look.

  • Asks before revoking. Revoking is immediate and permanent, so the decision stays with you.

[Screenshot: Coding agent listing DocStar API tokens and asking which ones to revoke]

#

Step 4: Your part

The agent does the mechanics. You make the calls only a person can:

  • Is this token still needed? You know whether the contractor's script still runs or the old staging pipeline is gone.

  • Who owns it? Since only the Owner can create tokens, decide with your Owner which tools deserve one of the five slots.

  • When to revoke. Approve each revoke the agent proposes, ideally after the replacement is working.

#

Store tokens like passwords

Wherever a token lives, it should be somewhere built for secrets:

Where the token is used Where to keep it
GitHub Sync / GitHub Actions Repository secret DOCSTAR_API_KEY
Other CI systems That system's secret store
Your own scripts A password manager or your tool's secret settings
Never Public docs, chats, issues, code repositories, screenshots

Send it only in the Authorization header (Authorization: Bearer hm_...), never in a URL, where it can end up in logs and browser history.

The same thinking runs through the rest of DocStar:

  • The DocStar CLI keeps sign-in tokens in ~/.docstar/credentials.json, readable only by you. It never reads your environment or .env files, and docstar-cli config get shows saved keys only by their last 4 characters.

  • MCP Logs for your collection's MCP server mask tokens, API keys and other secret values, keep calls for two weeks, and are visible only to people with edit access to the collection.

#

Rotate tokens on a schedule

DocStar tokens don't expire, so a token created today still works in three years unless someone revokes it. Rotation closes that window. Your agent makes it a two-minute job:

Rotate the DocStar token used by GitHub Sync in this repo. Generate a new token named "GitHub Sync acme-api Mar 2027" (this repo's name and the current month), replace the DOCSTAR_API_KEY secret with it, push a small docs change to confirm the sync run succeeds, then ask me before revoking the old token.

The order matters: new token, update the secret, confirm it works, then revoke the old one. That way nothing breaks between steps. Because names must be unique, even among revoked tokens, a date in the name keeps every rotation clean and tells you at a glance how old a token is.

A sensible rhythm:

  • On a schedule (for example quarterly) for every automation token.

  • Immediately when someone who had access leaves, when a token may have been exposed, or when a tool is retired.

#

Give each tool its own token

One shared token for everything is convenient until you need to revoke it and three pipelines break. With one token per tool:

  • You can revoke one without touching the others.

  • The name tells you exactly what breaks if you revoke it.

  • If one leaks, the blast radius is one tool.

For a wider view of who should be able to do what, see Documentation Roles and Permissions.

#

Your users' tokens: per-user sign-in on your MCP server

Tokens matter on the other side too. When you publish your API docs in DocStar, the collection gets its own hosted MCP server, so your customers' AI assistants can call your API. You don't want them pasting long-lived keys into prompts.

With Sign-in for API calls, the first time an assistant calls your API, the user signs in with their own account on your platform, and every call runs with their own permissions. Your OAuth app's client secret is stored only on the MCP server and never shown again, and DocStar checks the user's token against your token validation URL on every MCP request. Entering those OAuth details is one of the few steps only a person can do. We cover the full setup in Securing Your DocStar MCP Server.

#

Keep it current

Token hygiene isn't a one-time cleanup. Build it into the work you already do:

  • New repo or tool: ask your agent to create a dedicated, dated token and store it as a secret in the same step. Never reuse one.

  • Offboarding: add "review DocStar tokens" to your checklist and ask your agent to list them, so you can revoke anything the person set up.

  • Quarterly: run the rotation prompt above for each automation token.

  • Audit trail: DocStar's activity logs show page events such as edits, moves, publishing and deletions with the team member responsible, so you can trace what changed after an incident.

For the bigger picture of docs as part of your pipeline, read Make Your Docs Part of Your Stack.

#

Prefer to click?

You can manage tokens by hand too. Click your workspace name at the bottom of the left sidebar and open Auth Key. Under Generate New Token, enter a clear name and click Generate Token, then copy the value straight into your secret store, because it's shown only once. To revoke, click Revoke next to the token in Your API Tokens and confirm.

#

Why teams choose DocStar

  • Agents without keys. Browser sign-in to the DocStar MCP means everyday AI work needs no token at all.

  • Agents that keep secrets out of chat. Your coding agent generates the token and stores it as a GitHub secret in one prompt.

  • One collection, everything in sync. The same docs power your docs site, llms.txt, your MCP server and the CLI, and GitHub Sync updates them all on every push.

  • Secrets handled carefully everywhere. Shown-once tokens, masked MCP Logs, client secrets kept on the server, and a CLI that never reads your .env.

#

FAQ

#

Do DocStar API tokens expire?

No. A token works until you revoke it, so rotate automation tokens on a schedule and revoke any you no longer use.

#

Who can create a DocStar API token?

Only the workspace Owner. Each Owner can have up to 5 active tokens per workspace, and each token works in only one workspace.

#

Do I need a token to use DocStar from Claude Code or Cursor?

No. Connect the DocStar MCP and sign in in your browser. An Auth Key is only a fallback for assistants that can't connect to MCP.

#

What happens when I revoke a token?

It stops working immediately and any tool using it gets a 403 "Invalid API token". It can't be undone, so set up the replacement first.

#

Can my agent see the token value after it's created?

It sees it once, at creation, and the DocStar quickstart tells it to store the value as a secret without showing it in chat. DocStar itself keeps only a fingerprint.

#

Get started free

Connect your AI agent to DocStar, set up GitHub Sync with a token it stores safely, and let it keep your docs, MCP server and CLI in sync. Get started free.

secure API tokensAPI token rotationGitHub secretsdocs automationMCP sign-in