Skip to content

Authentication

Every request carries one bearer token in the Authorization header. AYNA accepts three kinds:

Token Looks like Lifetime Get it from
API key ak_ + 32 characters Until revoked, or a date you set Pairing an app with a pilot, or the API keys endpoints
Access token A JWT (eyJ...) 60 minutes Exchanging an API key at /auth/verify-key
OAuth access token aat_... 1 hour An OAuth sign-in by an AYNA user
Terminal window
curl https://app.ayna.com/api/v1/auth/profile \
-H "Authorization: Bearer ak_your_api_key"

Every token belongs to one organization and can only see that organization’s records.

API keys are issued when an app is paired with a pilot: the pilot is signed in to AYNA, approves the app, and the app receives a key. There are two ways to pair, both described in Connect an app to a pilot:

  • Access code: generate a code on the pilot in AYNA, type it into the app.
  • Device login: the app shows a code, the pilot approves it at app.ayna.com/link/.

The key is returned once, in the pairing response. Store it as a secret.

An app that would rather not send its key on every call can swap it for a short-lived access token and a refresh token:

Terminal window
curl -X POST https://app.ayna.com/api/v1/auth/verify-key \
-H "Content-Type: application/json" \
-d '{"api_key": "ak_your_api_key"}'
{
"success": true,
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"token_type": "Bearer",
"expires_in": 3600
}
}

Use the access_token as the bearer token. Before it expires, get a new one with the refresh token, which lasts 7 days:

Terminal window
curl -X POST https://app.ayna.com/api/v1/auth/refresh \
-H "Content-Type: application/json" \
-d '{"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGc..."}'

With a key that belongs to a user, you can create more named keys, list them and revoke them:

Terminal window
# Create a key (shown once in the response)
curl -X POST https://app.ayna.com/api/v1/auth/api-keys \
-H "Authorization: Bearer $AYNA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Nightly export", "expires_in_days": 90}'
# List keys (prefixes only, never the full key)
curl https://app.ayna.com/api/v1/auth/api-keys \
-H "Authorization: Bearer $AYNA_TOKEN"
# Revoke a key
curl -X DELETE https://app.ayna.com/api/v1/auth/api-keys/{api_key_id} \
-H "Authorization: Bearer $AYNA_TOKEN"

expires_in_days is optional, from 1 to 365. Without it the key lasts until revoked.

AI apps and other tools that sign a user in with OAuth get an aat_ access token instead of a key. It acts as that user, with the access the user chose (View only or View and make changes). OAuth tokens can’t call the key management or account endpoints. See Cursor and other MCP clients for the endpoints.

  • Never put a key in a web page or a mobile app bundle that others can read.
  • Use one key per app or integration, so you can revoke one without breaking the others.
  • If a key leaks, revoke it: from the pilot’s page in AYNA for a paired app, or with DELETE /auth/api-keys/{id}.