Authentication
Create a workspace API key, store it as an environment variable, and authenticate every request as the right user.
Every AISquare request is authenticated with a workspace API key passed in the
Authorization header. This page shows how to get a key, keep it safe, and use
it from a server, a script, or the SDK.
Get a workspace key
An API key is scoped to a workspace and identifies who is making the call. You can mint keys two ways:
- From the dashboard. Open your workspace settings and create a key. Copy it once; it is shown only at creation.
- Programmatically, per user. Your backend registers each user through the registration API, which provisions the user and returns a key for them. This is the recommended path for platforms (see Per-user keys below).
Treat keys like passwords
A key grants full access to its workspace. Never commit it, never put it in client-side code, and never paste it into a browser request. Keep it on a server or in a secret store.
Store the key as an environment variable
Keep the key out of your source. Put it in an environment variable, which is also where the SDK looks for it by default.
AISQUARE_API_KEY=aisq_live_your_key_hereMake sure the file is gitignored, then load it into your shell or process manager so the variable is available at runtime.
Authenticate a request
Pass the key as a bearer token. This works for any HTTP client, in any language.
curl -X POST https://api.aisquare.com/api/v1/aistudios/experiences/flattened/ \
-H "Authorization: Bearer $AISQUARE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "ai-research-studio" }'Let the SDK read the key
The SDK reads AISQUARE_API_KEY from the environment, so you construct the
client with no arguments and it is already authenticated. Nothing about the key
appears in your code.
from aisquare import AISquare
# Reads AISQUARE_API_KEY from the environment.
client = AISquare()
experiences = client.experiences.flattened(url="ai-research-studio")
print(experiences.count)import { AISquare } from "@aisquare/sdk";
// Reads AISQUARE_API_KEY from the environment.
const client = new AISquare();
const experiences = await client.experiences.flattened({ url: "ai-research-studio" });
console.log(experiences.count);To use a key explicitly instead of the environment (for example, when you hold a different key per user), pass it to the constructor:
client = AISquare(api_key=user_api_key)Per-user keys for platforms
If you are building a platform on top of AISquare, give each of your users their own key rather than sharing one workspace account. Your backend registers the user, stores their key securely, and makes calls on their behalf.
Per-user keys keep each user's data and metrics separate, which a shared account cannot do.
| Shared account | Per-user keys |
|---|---|
| Activity is merged | Activity is tracked per user |
| Personalization is lost | Metrics like accuracy and streaks work |
| Leaderboards are skewed | Leaderboards and ranking are accurate |
Tokens for browser and SSO flows
API keys cover server-to-server calls. Two other methods cover the cases keys do not.
- JWT tokens. Exchange a key at the login endpoint for an access token (valid
7 days) and a refresh token (valid 30 days). Send the access token the same
way:
Authorization: Bearer <access_token>. Refresh it when it expires. See Token lifecycle for the full flow. - Cookie and OpenID. Browser apps can authenticate with a session cookie that rides along automatically; enterprises can connect SSO over OpenID.
| Use case | Method |
|---|---|
| Backend integration | API key |
| Browser app session | Cookie |
| Token-based flows | JWT (access + refresh) |
| Enterprise SSO | OpenID |