Get started

Reference REST API 02 / 06

API keys and OAuth

Create keys, pick scopes, use OAuth for apps and assistants, and rotate or revoke access.

Runs on Writ CloudWrit Desktop

Markdown Open in Claude Open in ChatGPT

Every call to Writ Cloud's API carries a credential. Your own scripts use an API key; apps that act for other Writ users, and AI assistants, use OAuth. Both are limited to the scopes they were given.

Create an API key

  1. Open Developers → API Keys

    Click Create API Key. Only an organization's Owners and Admins can create, change or delete keys.

  2. Name it and pick an expiration

    Give it a Key name that says where it is used, such as Reporting script. For Expiration, choose 30 days, 90 days (the default), 1 year or No expiry.

  3. Choose an access level

    Read-only sees everything and changes nothing. Run automations (the default) also runs workflows, harvests, page reads and monitor checks. Full access can do everything, including delete. Custom lets you Choose each permission, and limit workflows, monitors or datasets to Only specific items.

  4. Decide on AI tools

    Allow AI tools lets the key use Writ's AI features: AI recording, site discovery and auto-repair. It is on by default for Full access only.

  5. Copy the key

    Click Create key. The key starts with wt_ and is shown only once, right after you create it. Store it in a password manager or your app's secret store.

Use a key

Send the key in the Authorization header of every request. Keep it in an environment variable such as WRIT_API_KEY, never in code you commit or in a web page.

curl "https://api.usewrit.app/api/runs?limit=5" \
  -H "Authorization: Bearer $WRIT_API_KEY"

A missing, wrong or expired key answers 401. Every call made with your keys counts against your plan's calls per minute: see Errors and limits.

Scopes

A scope is a resource and an action, written resource:action, such as workflows:execute. The four actions are read (view), write (create and change), execute (run) and delete. Not every resource has all four.

ResourceIn the key editorCoversActions
workflows Workflows Your APIs and workflows, and running them read, write, execute, delete
runs Runs Run history, results and live run state read
monitors Monitors Monitors, what they watch and the changes they find read, write, execute, delete
datasets Datasets Collected data, search and exports read, delete
crawl Crawls Harvests and saved harvests read, execute, delete
scrape Scrape & map One-off page reads and site maps execute
files Files Files you upload and files runs produce read, write, delete
personas Personas Personas and their sign-in sessions read, write, delete
secrets Secrets Vault secrets: names and details, never the values read, write, delete
agents Agents Your machines and fleet agents read, write, execute
devices Devices Linked Writ desktops and the workflows and personas they offer read, write
triggers Triggers & webhooks Automations and webhooks, and firing them read, write, execute, delete
streaming Streaming Live sessions and their OpenAI-compatible calls read, execute, delete
recorder Recorder Live recording sessions read, execute
mcp MCP The MCP server and the tools you publish on it read, write, execute, delete
marketplace Marketplace Browsing and installing ready-made APIs read, write
account Account Account, plan and usage, read-only read
transfer Import & export Packing the whole account into a file, and importing one read, write

The access levels are fixed sets of these scopes:

Access levelName in the APIScopes
Read-onlyread_onlyEvery read scope except Import & export.
Run automationsrunEvery read and execute scope except Import & export.
Full accessfullEvery scope, including delete and Import & export.

Access is denied by default. A route that is not open to keys answers 403, whatever the key holds: managing keys, billing, team members and settings are never reachable with a key. A route the key lacks the scope for answers 403 and names the missing scope.

Missing scope
HTTP/1.1 403 Forbidden

{ "detail": "API key is missing the 'datasets:read' scope" }
Route not open to keys
HTTP/1.1 403 Forbidden

{ "detail": "This endpoint cannot be called with an API key" }

Each operation in the REST API reference names the scope it needs.

OAuth for apps

Use OAuth when your app acts for Writ users other than you, or when a platform such as Zapier, Make or n8n connects to Writ. Each user approves your app on a Writ consent page and can revoke it later. There are no native Zapier, Make or n8n apps: they connect with OAuth and plain HTTP calls.

  1. Create credentials

    In Integrations, open the OAuth access tab and click Create an OAuth application, or pick Zapier, Make, n8n or Your own application in the Catalogue. Fill in Name, OAuth redirect URLs (one per line) and the Permissions the app may ask for, then click Create credentials.

  2. Keep the secret

    Writ shows the Client ID, the Client Secret and the OAuth endpoints. The secret is shown once. Redirect URLs must use HTTPS, except http://127.0.0.1 or localhost for apps on the user's computer.

  3. Send the user to the consent page

    Redirect the user to the authorization endpoint with your scopes, separated by spaces. Without a scope, the app gets all the permissions you chose. Use PKCE with S256: Writ requires it for apps without a secret and accepts it from every app.

    Authorization request
    https://api.usewrit.app/api/oauth/authorize
      ?response_type=code
      &client_id=YOUR_CLIENT_ID
      &redirect_uri=https%3A%2F%2Fyour-app.example.com%2Fcallback
      &scope=workflows%3Aread%20workflows%3Aexecute%20datasets%3Aread
      &state=RANDOM_STATE
      &code_challenge=BASE64URL_SHA256_OF_VERIFIER
      &code_challenge_method=S256
  4. Exchange the code for tokens

    Writ redirects back with code and your state. Exchange the code within 10 minutes; it works once.

    curl -X POST https://api.usewrit.app/api/oauth/token \
      -d grant_type=authorization_code \
      -d code="$CODE" \
      -d redirect_uri=https://your-app.example.com/callback \
      -d client_id="$WRIT_CLIENT_ID" \
      -d client_secret="$WRIT_CLIENT_SECRET" \
      -d code_verifier="$CODE_VERIFIER"
    200 OK
    {
      "access_token": "wto_...",
      "token_type": "bearer",
      "expires_in": 3600,
      "refresh_token": "wtr_...",
      "scope": "workflows:read workflows:execute datasets:read"
    }

Call the API with Authorization: Bearer wto_.... A token reaches only the routes its scopes cover, exactly like a key. A missing scope answers 403 with a WWW-Authenticate: Bearer error="insufficient_scope" header that names it. Calls with tokens count against the user's plan's calls per minute.

Refresh and revoke tokens

Access tokens expire after expires_in seconds. Get a new pair with the refresh token. Each refresh returns a new refresh token and retires the old one; sending a retired refresh token again is refused, so always store the latest.

curl -X POST https://api.usewrit.app/api/oauth/token \
  -d grant_type=refresh_token \
  -d refresh_token="$WRIT_REFRESH_TOKEN" \
  -d client_id="$WRIT_CLIENT_ID" \
  -d client_secret="$WRIT_CLIENT_SECRET"

To sign a user out of your app, revoke the refresh token or the access token. The endpoint answers 200 either way.

Revoke a token
curl -X POST https://api.usewrit.app/api/oauth/revoke \
  -d token="$WRIT_REFRESH_TOKEN" \
  -d token_type_hint=refresh_token \
  -d client_id="$WRIT_CLIENT_ID" \
  -d client_secret="$WRIT_CLIENT_SECRET"

Endpoints and discovery

PurposeURL
Authorizationhttps://api.usewrit.app/api/oauth/authorize
Tokenhttps://api.usewrit.app/api/oauth/token
Revocationhttps://api.usewrit.app/api/oauth/revoke
Client registrationhttps://api.usewrit.app/api/oauth/register
Server metadatahttps://api.usewrit.app/.well-known/oauth-authorization-server
Resource metadata (MCP)https://api.usewrit.app/.well-known/oauth-protected-resource
GET /.well-known/oauth-authorization-server
{
  "issuer": "https://api.usewrit.app",
  "authorization_endpoint": "https://api.usewrit.app/api/oauth/authorize",
  "token_endpoint": "https://api.usewrit.app/api/oauth/token",
  "revocation_endpoint": "https://api.usewrit.app/api/oauth/revoke",
  "registration_endpoint": "https://api.usewrit.app/api/oauth/register",
  "response_types_supported": ["code"],
  "grant_types_supported": ["authorization_code", "refresh_token"],
  "code_challenge_methods_supported": ["S256"],
  "token_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic", "none"],
  "scopes_supported": ["workflows:read", "workflows:write", "..."]
}

Register a client from code

Clients can register themselves with dynamic client registration, with no step in the app. Writ's MCP clients do this. A registered client must use PKCE, and it can only ask for the scopes Writ's MCP tools need.

Register a client
curl -X POST https://api.usewrit.app/api/oauth/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "My MCP client",
    "redirect_uris": ["http://127.0.0.1:33418/callback"],
    "token_endpoint_auth_method": "none"
  }'
201 Created
{
  "client_id": "wmc_...",
  "client_id_issued_at": 1761926400,
  "client_name": "My MCP client",
  "redirect_uris": ["http://127.0.0.1:33418/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none",
  "scope": "mcp:read mcp:execute workflows:read workflows:write workflows:execute ..."
}

AI assistants and Writ Desktop

Assistants sign in with OAuth

When you add https://api.usewrit.app/mcp to Claude, ChatGPT, Cursor or another MCP client, the client finds Writ's OAuth server, registers, and opens a Writ consent page. You approve, and the client gets a token. You never paste a key. Setup for each client: Connect an AI assistant.

An assistant connected this way can read and run your workflows and data, read pages, harvest sites, sign in with your personas, manage monitors and automations, use your linked desktops and search the marketplace. It can never delete anything, read your vault secrets or files, manage your machines, export the account, or install marketplace listings.

Writ Desktop

Linking Writ Desktop to your account uses the OAuth device flow: Desktop shows a code, and you approve it in your browser (Connect a cloud account → Open the approval page). The device flow is reserved for Writ's own apps; your apps use the authorization code flow above. See Link Desktop to Writ Cloud.

Writ Desktop's own API on your computer uses separate local keys that start with wlk_, made in MCP & APIs → API Keys in the app. Cloud keys do not work there, and local keys do not work on Writ Cloud. See Desktop local API.

Rotate and revoke

To rotate a key, create a new one, put it where the old one was used, then delete the old one in Developers → API Keys with Delete key. Deleting cannot be undone, and any integration using the key stops working at once. To change what a key may do without replacing it, use Edit permissions.

Good habits for keys:

  • One key per app or script, named after it, so you can revoke one without breaking the others.
  • The smallest access level that works: Read-only for dashboards, Run automations for scripts that start runs.
  • Limit keys to Only specific items when a script uses one workflow or one dataset.
  • An expiration on every key you hand to someone else.
  • Keys in environment variables or a secret store, never in a repository, a front-end bundle or a chat.

Writ runs on your own accounts, with your own credentials and data, on sites you are authorized to use.

Next