Cookbook

First request

Find an exact model id and send one chat completion, in curl, Python or TypeScript.

Download and configure

Install Python 3 or Node 22 and download the complete examples from the recipe archive. The archive has the files shown below, including the browser app and local stream checks. Choose an exact model ID from the public catalogue and export your inference key from a secret store.

bash
curl --fail "https://aihub.belive.sg/docs/examples/tokenhub.zip" -o tokenhub-examples.zip
unzip tokenhub-examples.zip
cd tokenhub-examples
cp .env.example .env
# Edit .env: set TOKENHUB_API_KEY and TOKENHUB_MODEL.
# Keep .env local. Scripts read process environment, not the .env file itself.
set -a
. ./.env
set +a
# Use the API base for the environment shown by this docs site.
export TOKENHUB_BASE_URL="https://tokenhub-api.belive.sg/api/v1"

1. Choose a model

The catalogue is public. List it and copy one exact author/slug id into TOKENHUB_MODEL:

bash
curl -s "https://tokenhub-api.belive.sg/api/v1/models" | python3 -c 'import json,sys; [print(m["id"]) for m in json.load(sys.stdin)["data"]]'

2. Send the request

Each program confirms the model exists, sends one message and prints the answer, the token usage and the X-Generation-Id request id. The Python and TypeScript versions have no dependencies.

#!/usr/bin/env bash
# First request with curl. Needs TOKENHUB_BASE_URL, TOKENHUB_API_KEY and TOKENHUB_MODEL.
set -euo pipefail
: "${TOKENHUB_BASE_URL:?set TOKENHUB_BASE_URL}" "${TOKENHUB_API_KEY:?set TOKENHUB_API_KEY}" "${TOKENHUB_MODEL:?set TOKENHUB_MODEL}"

# 1. Confirm the exact model id exists. The catalogue is public; no key is needed.
curl -fsS "$TOKENHUB_BASE_URL/models/$TOKENHUB_MODEL" > /dev/null \
  || { echo "model $TOKENHUB_MODEL is not in the catalogue" >&2; exit 1; }

# 2. Send one chat completion. -D - prints the response headers, including X-Generation-Id,
#    the request id to look up its cost later (GET /generation?id=…).
curl -sS -D - "$TOKENHUB_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $TOKENHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\": \"$TOKENHUB_MODEL\", \"max_tokens\": 200,
       \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one sentence.\"}]}"
echo

3. Check what it cost

Pass the printed request id to the generation lookup with the same key, or open Console → Activity.

bash
curl "https://tokenhub-api.belive.sg/api/v1/generation?id=req_…" -H "Authorization: Bearer $TOKENHUB_API_KEY"

Next: stream the answer in a chat loop.