Client Setup
Basic Setup
import { createClient } from '@tanqory/sdk'
const tanqory = createClient({
apiKey: 'pk_live_your_publishable_key',
})
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | -- | Publishable key (pk_live_... or pk_test_...) |
accessToken | string | -- | JWT access token (for server-side pre-authenticated calls) |
baseURL | string | auto | API base URL (auto-detected from environment) |
environment | string | production | production, staging, development |
timeout | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 3 | Auto-retry on 429 and 5xx errors |
debug | boolean | false | Log requests and responses to console |
allowUnauthenticated | boolean | false | Allow requests without auth token |
Server-Side (Pre-Authenticated)
For server-to-server calls, pass the access token directly:
const tanqory = createClient({
apiKey: 'pk_live_...',
accessToken: process.env.TANQORY_ACCESS_TOKEN,
})
// No login needed — ready to make API calls
const stores = await tanqory.stores.list()
Environment-Specific Setup
// Development
const tanqory = createClient({
apiKey: 'pk_test_...',
environment: 'development',
debug: true,
})
// Production
const tanqory = createClient({
apiKey: 'pk_live_...',
environment: 'production',
maxRetries: 3,
})
Custom Base URL
Override the API endpoint for self-hosted or regional deployments:
const tanqory = createClient({
apiKey: 'pk_live_...',
baseURL: 'https://api-custom.example.com/api/v1',
})
Base URLs by Environment
| Environment | Account API | Store API |
|---|---|---|
| Production | https://api.tanqory.com | https://app.tanqory.com |
| Development | http://localhost:4000 | http://localhost:4001 |
app.tanqory.com is not a second copy of the API — it is the address that knows
where a store lives. Store data sits in one regional cell, and this host reads
the storeId from the path and forwards to that cell; /auth/*, /stores and
/subscriptions/* go to the account API instead. One base URL, both
destinations, and no way to send a request to the wrong region.
Hosts shaped api-do-sgp1.tanqory.com are internal plumbing. Which cell a
store sits on is a placement decision the platform makes and can change, and a
request sent to the wrong cell returns a 404 indistinguishable from a deleted
record — so this fails silently and looks like missing data.
This is enforced, not just advised: check-no-direct-cell-host.mjs fails CI in
the dashboard for a literal cell host, a per-cell env var, or code that builds
one from a hostname.
Login After Client Creation
const tanqory = createClient({ apiKey: 'pk_live_...' })
// Login sets the token automatically
// Subsequent calls are authenticated
const stores = await tanqory.stores.list()
Token Management
The SDK manages tokens automatically:
- Stores
accessTokenandrefreshTokenafter login - Intercepts
401responses and refreshes the token - Retries the original request with the new token
- Emits events on token refresh and expiry
// Listen for token events
tanqory.on('token:refreshed', (tokens) => {
// Persist tokens if needed (e.g., for SSR)
})
tanqory.on('token:expired', () => {
// Redirect to login
})
Multiple Clients
Create separate clients for different contexts:
const adminClient = createClient({
apiKey: 'pk_live_...',
accessToken: adminToken,
})
const publicClient = createClient({
apiKey: 'pk_live_...',
allowUnauthenticated: true,
})