Skip to main content

Authentication

All PolarGrid API requests require authentication using an API key.

API Keys

API keys are created in the PolarGrid Console and start with pg_.

Creating a Key

  1. Go to Settings → API Keys in the console
  2. Click Generate New Key
  3. Give it a descriptive name (e.g., “Production App”, “Development”)
  4. Select permissions: read-only, read-write, or admin
  5. Copy the key immediately — it won’t be shown again

Using Your Key

Include your API key in the Authorization header:
Authorization: Bearer pg_your_api_key
curl -X POST https://api.ymq-01.edge.polargrid.ai:55111/v1/chat/completions \
  -H "Authorization: Bearer pg_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"model": "llama-3.1-8b", "messages": [{"role": "user", "content": "Hi"}]}'

Environment Variables

We recommend storing your API key in an environment variable:
export POLARGRID_API_KEY="pg_your_api_key"
The SDKs automatically read from this variable:
// No need to pass apiKey if POLARGRID_API_KEY is set
const client = await PolarGrid.create();

JWT Token Exchange

Under the hood, the SDKs exchange your API key for a short-lived JWT token. This happens automatically — you don’t need to manage tokens yourself. The JWT is cached and refreshed every 30 minutes. If you’re making raw HTTP requests, you can use the API key directly in the Authorization header.

Permission Levels

LevelDescription
read-onlyCan make inference requests only
read-writeCan make requests and manage models
adminFull access including API key management

Security Best Practices

Never commit API keys to source control or expose them in client-side code.
  • Use environment variables for API keys
  • Rotate keys periodically
  • Use separate keys for development and production
  • Use read-only keys when possible
  • Revoke keys immediately if compromised

CLI Authentication

The CLI supports two authentication methods:

Browser Login (Interactive)

polargrid login
Opens your browser for OAuth authentication. Best for development.

API Key (CI/CD)

export POLARGRID_API_KEY="pg_your_api_key"
polargrid test inference --region montreal --prompt "Hello"
No login needed — just set the environment variable.