Skip to main content

Client Setup

Basic Setup​

import { createClient } from '@tanqory/sdk'

const tanqory = createClient({
apiKey: 'pk_live_your_publishable_key',
})

Configuration Options​

OptionTypeDefaultDescription
apiKeystring--Publishable key (pk_live_... or pk_test_...)
accessTokenstring--JWT access token (for server-side pre-authenticated calls)
baseURLstringautoAPI base URL (auto-detected from environment)
environmentstringproductionproduction, staging, development
timeoutnumber30000Request timeout in milliseconds
maxRetriesnumber3Auto-retry on 429 and 5xx errors
debugbooleanfalseLog requests and responses to console
allowUnauthenticatedbooleanfalseAllow 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​

EnvironmentAccount APIStore API
Productionhttps://api.tanqory.comhttps://app.tanqory.com
Developmenthttp://localhost:4000http://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.

Never address a cell directly

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
await tanqory.auth.login('[email protected]', 'password')

// Subsequent calls are authenticated
const stores = await tanqory.stores.list()

Token Management​

The SDK manages tokens automatically:

  • Stores accessToken and refreshToken after login
  • Intercepts 401 responses 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,
})