Environments and keys
Sandbox and production, your API keys, and how to authenticate.
Environments
| Sandbox | Production | |
|---|---|---|
| Purpose | Building and testing. Doesn't issue real protection. | Live orders. |
| API base URL | https://api.sandbox.helloteak.com/v1 | https://api.helloteak.com/v1 |
| Widget | sandbox: true in configure | sandbox omitted or false |
| Teak Dashboard | dashboard.sandbox.helloteak.com | Provided when you go live |
| Keys | Sandbox keys | Production keys |
| Status | status.helloteak.com |
Keys only work in their own environment. Your Teak integration contact provides sandbox keys when you start, and production keys when you're ready to go live.
Your keys
You get a pair of keys for each environment:
| Key | Format | Where it's used |
|---|---|---|
| Public key | pk_... | In the customer's browser, as the widget's apiKey. Safe to include in your pages. On your server, exchanged with the secret key for an access token. |
| Secret key | sk_... | On your server only. Exchanged, with the public key, for a short-lived access token. See Create an access token. |
Store it in a secret manager or environment variable. Don't put it in browser code, mobile apps, or source control. If it's exposed, contact your Teak integration contact to replace it.
If you're a platform that sells for several businesses, you also have partner keys, used only to create a client for each business. Each client has its own keys. See Onboard clients.
Authenticating API calls
Server-side API calls use a short-lived access token:
- Call Create an access token with your public and secret keys.
- Send the token on each call as
Authorization: Bearer <token>. - Tokens expire 5 minutes after they're issued. When a call returns
401, get a new token and retry once.
curl -X POST https://api.sandbox.helloteak.com/v1/auth/token \
-H 'Content-Type: application/json' \
-d '{"public_key": "pk_...", "secret_key": "sk_..."}'{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }The widget doesn't need a token: it authenticates with your public key.
Reuse the token
If your server calls Teak only at checkout, get a new token just before you place each order. If it calls Teak often, for example the Programs API on every search, reuse one token until it's close to expiring:
const TEAK_API = 'https://api.sandbox.helloteak.com/v1';
let cached = { token: null, expiresAt: 0 };
// Pass { refresh: true } after a 401 to get a new token.
async function getTeakToken({ refresh = false } = {}) {
// Renew a minute early, so a token never expires mid-request.
if (!refresh && cached.token && Date.now() < cached.expiresAt - 60_000) return cached.token;
const res = await fetch(`${TEAK_API}/auth/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
public_key: process.env.TEAK_PUBLIC_KEY,
secret_key: process.env.TEAK_SECRET_KEY,
}),
});
if (!res.ok) throw new Error(`Teak auth failed: ${res.status}`);
cached = { token: (await res.json()).token, expiresAt: Date.now() + 5 * 60_000 };
return cached.token;
}import os
import time
import requests
TEAK_API = "https://api.sandbox.helloteak.com/v1"
_cached = {"token": None, "expires_at": 0.0}
# Pass refresh=True after a 401 to get a new token.
def get_teak_token(refresh=False):
# Renew a minute early, so a token never expires mid-request.
if not refresh and _cached["token"] and time.time() < _cached["expires_at"] - 60:
return _cached["token"]
res = requests.post(
f"{TEAK_API}/auth/token",
json={
"public_key": os.environ["TEAK_PUBLIC_KEY"],
"secret_key": os.environ["TEAK_SECRET_KEY"],
},
timeout=10,
)
res.raise_for_status()
_cached.update(token=res.json()["token"], expires_at=time.time() + 5 * 60)
return _cached["token"]If a call still returns 401, get a new token with getTeakToken({ refresh: true }) or get_teak_token(refresh=True), and retry the call once.
Which key for which call
| Call | From | Authenticates with |
|---|---|---|
| The widget's quote and the customer's choice | The customer's browser | Your public key, as the widget's apiKey |
| Create an access token | Your server | Your public and secret keys |
| Submit an order, Retrieve order details, Void a contract, Cancel a contract | Your server | An access token |
| The Programs API, and confirming the order | Your server, on the server-to-server path | An access token |
Use the same account's keys for every call on a session. Calls on a session with another account's keys return 403.
The widget tells Teak where the customer is from their browser's connection, so Teak offers protection that's available to them. On the server path, Teak sees your server's connection instead, so you send the customer's location with the Programs API. See Send the customer's location.
Next steps
With your sandbox keys, you're ready to build:
- Follow the TeakOS integration guide step by step, from sandbox to live.
- Or, to offer protection from your own server instead of the widget, follow the server-to-server guide.
- Learn how to handle errors from the Teak API, and when to retry.
Updated 1 day ago
