Docs / API keys

Guides

API keys

Create, limit and revoke the keys your scripts use to reach your Ragnar account.

An API key acts as you. It reaches the projects you own and the projects people shared with you, personal or in a workspace, and it follows your access as it changes: lose access to a project or a workspace, and the key loses it too.

Create a key

In Ragnar, open Settings → Developers and choose New key:

  • Name: up to 80 characters, so you can tell your keys apart.
  • Permission: Read only can read chats, tasks and files and download files. Read and build can also create projects and chats, send messages and upload files. Read only is the default.
  • Expiration: never (the default), 30 days, 90 days or 1 year.
  • Monthly credit limit: how many credits the work started with this key may spend each month, from 0 to 1,000,000,000 with up to two decimals. Leave it empty for no limit.

Ragnar shows the key once, when you create it. Store it like a password. If you lose it, create a new key and revoke the old one.

One account can create up to 20 keys a day. Settings tells you how long to wait when you reach that.

Use a key

Send the key in the Authorization header of every request. A Ragnar key starts with ak_.

Header
Authorization: Bearer <your API key>

Ragnar checks the key on every request, so a revoked or expired key stops working at once:

  • A missing, revoked or expired key gets 401 INVALID_TOKEN.
  • A Read only key that sends a POST gets 403 INSUFFICIENT_SCOPE.

Projects and roles

Your role on a project still applies. A viewer can read the project's chats, tasks and folder and download its files, but cannot open a chat, send a message or upload a file: those get 403 FORBIDDEN. A project you cannot open answers as if it did not exist, with 404 NOT_FOUND. Being a member of a workspace does not by itself open its projects: the project must be yours or shared with you.

Who pays

  • A build in a workspace project spends the workspace's credits.
  • A build in a personal project spends the credits of the person who sends the message, also in a project someone shared with you. Your own plan also decides whether you can use high and xhigh effort there.

Workspaces

A key is not tied to one workspace. To create a project in a workspace, pass the workspace's id as workspace_id to POST /v1/projects. Settings → Developers lists the workspaces you belong to, each with its id and a copy button. Leave workspace_id out for a personal project.

A new personal project on the free plan is public and can be remixed, as a project made in the app is, and it joins the community gallery after its first successful build. On Pro it stays private. A workspace project stays private.

Monthly credit limit

A key's limit caps the credits its work spends in a calendar month, across all your projects. It resets on the first of each month at 00:00 UTC. Charges and refunds count in the month they happen.

When a key reaches its limit:

  • A new message gets 402 API_KEY_CREDIT_LIMIT_REACHED. So does an answer to a question of a build the key started.
  • Builds the key started pause when they next spend credits. Their tasks report paused with the reason api_key_credit_limit_reached, or out_of_credits when the credits ran out first. Continue them in Ragnar once the month resets or you raise the limit.
  • A message accepted just before the limit can end failed with the reason api_key_credit_limit_reached, because its build never started. Send it again after the reset or with a higher limit.
  • Reading, downloading and /export keep working.

While a key is not revoked, change its limit at any time with the pencil button on its row, Edit monthly credit limit. The key and this month's spending stay as they are. A limit of 0 blocks all spending.

Usage

Settings → Developers → Stats shows the requests and credits of your keys over the last 24 hours, 7 days, 30 days or 90 days. Filter it by key, key status (active, expired or revoked) or permission. Every request that passes the key check counts, polling, refusals and downloads included.

Revoke a key

Revoke a key from its row in Settings → Developers. The next request with it fails with 401 INVALID_TOKEN. Work it already started carries on under the key's monthly limit, which you can no longer change: a build that pauses at the limit can go on after the month resets.

Keep keys safe

  • Give each script its own key, and choose Read only when it does not need to build.
  • Keep keys in environment variables or a secret store, never in source control, prompts or URLs.
  • If a key leaks, revoke it and create a new one.