Skip to content

Create a token and make your first API call

By the end of this tutorial you have made one successful authenticated call to the Sencai Platform API, you know how the API signals version changes, and the token you used no longer exists. It takes about 10 minutes.

The token is deliberately temporary. Creating a credential to try something once and then leaving it alive is how credentials leak, so revoking it is step 4, not an afterthought.

  • The Owner or Admin role in your organization. Creating and revoking tokens both require it - see Roles & permissions. A Free organization works fine for this tutorial too - issuing and using a read-scoped token doesn’t need a paid plan.
  • A terminal with curl, or any HTTP client you prefer.
  • A few minutes with the Platform API overview if you have not read it - the request and response conventions used below come from there.

Go to Settings → Integrations → AI Agents (/gravity/settings/integrations/ai-agents). In the API keys card, click Generate key.

Give it a name you will recognize later, choose the read scope, and optionally set an expiry date as a second safety net. Read scope is all this tutorial needs: it queries data and changes nothing. Click Generate.

Copy the token immediately. It is shown once, in a reveal dialog, and cannot be retrieved after you leave the page - if you lose it, revoke it and create another. Keep it in an environment variable rather than a file:

Terminal window
export SENCAI_TOKEN="sencai_pat_..."

You should now see a row in the API keys list with the token’s name, prefix, scope, and when it was last used. Only the prefix is ever shown again. API tokens covers the full lifecycle, including expiry and the error each failure returns.

The base URL is https://api.sencai.space/api/v1. Ask the API which organization you are acting as:

Terminal window
curl https://api.sencai.space/api/v1/organisations/me \
-H "Authorization: Bearer $SENCAI_TOKEN"

A successful response wraps its result in a data object (trimmed here):

{
"data": {
"id": 42,
"documentId": "a1b2c3d4e5f6...",
"name": "Acme Cloud",
"account_tier": "professional"
}
}

Two things worth noticing. You never passed an organization identifier: a token authenticates as you and is scoped automatically to the single organization it belongs to. And errors arrive as RFC 7807 problem documents, so a failure tells you its status and detail in the body as well as on the status line.

A 401 here means the token is missing, mistyped, or already revoked. A 403 on this particular call - a read with a read-scoped token - most likely means the token’s issuer no longer qualifies (left the organization, or was demoted below Admin) or the organization itself no longer exists. Both symptom tables - in API tokens and Troubleshooting - map each status to a fix.

Run the same call with -i so you see the status line and response headers, not just the body:

Terminal window
curl -i https://api.sencai.space/api/v1/organisations/me \
-H "Authorization: Bearer $SENCAI_TOKEN"

The API is versioned by URL path, and /api/v1 is the only version today. That is why you should not expect a Deprecation, Sunset, or Link header in that output - their absence is the correct result for a current version, not a sign that something went wrong.

Those three headers are what the platform is designed to send once a version is marked deprecated, following RFC 8594: Deprecation carries the date it was deprecated, Sunset the date calls to it stop working, and Link points at a migration guide. After a sunset date passes, calls to that version are intended to be rejected with 410 Gone.

Two habits follow from that:

  1. Write /api/v1 explicitly in your integration rather than relying on a default. It costs nothing today and is the entire preparation for a second version existing later.
  2. Check Settings → API Versions (/gravity/settings/api-versions) when something changes. It lists each version with its Current badge, deprecation and sunset dates when set, the breaking-change list, and a migration guide link when one is provided.

Return to Settings → Integrations → AI Agents, find your token’s row in the API keys card, and choose Revoke API key.

Confirm it worked by running the call from step 2 again: you should now get 401 Unauthorized. Revocation takes effect immediately with no grace period, so anything still holding the token fails on its next call.

This is a soft revoke. The token stops authenticating, but its history stays in your organization’s audit trail, so the record of what it did outlives the key itself. Revoking, like creating, needs the Owner or Admin role.

  • API tokens - scopes, expiry, storage, and the full error table behind every status you saw here
  • AI agents (MCP) - the exact read and write tools a token reaches, and how to point an AI client at them
  • API versioning - how deprecation and sunset are meant to work before you depend on them
  • Troubleshooting - the 401/403 symptom table, next to everything else that commonly goes wrong