Skip to main content

Quickstart

This guide will get you from zero to your first PolarGrid API call in under 5 minutes.

1. Get an API Key

1

Sign up

Create an account at app.polargrid.ai
2

Create API key

Go to Settings → API Keys and click Generate New Key
3

Copy your key

Your key starts with pg_. Keep it secure — you won’t see it again.

2. Make Your First Request

# Set your API key
export API_KEY="pg_your_api_key"

# Exchange your API key for a JWT
TOKEN=$(curl -s -X POST https://app.polargrid.ai/api/auth/inference-token \
  -H "Authorization: Bearer $API_KEY" | jq -r .token)

# Pick an edge node (e.g., Toronto)
EDGE="https://api.yto-01.edge.polargrid.ai"

# List available models
curl -s "$EDGE/v1/models" -H "Authorization: Bearer $TOKEN" | jq '.data[].id'

# Run a chat completion
curl -s -X POST "$EDGE/v1/chat/completions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Meta-Llama-3.1-8B-Instruct",
    "messages": [{"role": "user", "content": "Hello!"}]
  }' | jq
The SDKs handle endpoint discovery, JWT exchange, and region selection automatically. The cURL example shows the underlying flow step-by-step.

3. Choose Your Region

PolarGrid automatically routes to the fastest region when you use PolarGrid.create(). You can also specify one explicitly:
// Auto-select best region (recommended)
const client = await PolarGrid.create({ apiKey: 'pg_...' });
console.log(`Connected to: ${client.getRegionName()}`); // e.g., "Toronto"

// Or specify a region explicitly
const client = new PolarGrid({
  apiKey: 'pg_...',
  region: 'toronto'  // aliases: 'yto-01', 'yto'
});

Next Steps

Streaming Responses

Stream tokens as they’re generated

Voice AI

Text-to-speech and speech-to-text

API Reference

Full endpoint documentation

Error Handling

Handle errors gracefully