Environments and keys

Sandbox and production, your API keys, and how to authenticate.

Environments

SandboxProduction
PurposeBuilding and testing. Doesn't issue real protection.Live orders.
API base URLhttps://api.sandbox.helloteak.com/v1https://api.helloteak.com/v1
Widgetsandbox: true in configuresandbox omitted or false
Teak Dashboarddashboard.sandbox.helloteak.comProvided when you go live
KeysSandbox keysProduction keys
Statusstatus.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:

KeyFormatWhere it's used
Public keypk_...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 keysk_...On your server only. Exchanged, with the public key, for a short-lived access token. See Create an access token.
Keep your secret key on your server

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:

  1. Call Create an access token with your public and secret keys.
  2. Send the token on each call as Authorization: Bearer <token>.
  3. 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

CallFromAuthenticates with
The widget's quote and the customer's choiceThe customer's browserYour public key, as the widget's apiKey
Create an access tokenYour serverYour public and secret keys
Submit an order, Retrieve order details, Void a contract, Cancel a contractYour serverAn access token
The Programs API, and confirming the orderYour server, on the server-to-server pathAn 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:


Did this page help you?