Token BrokerDocs
Dashboard

Developer Reference

API Reference

One endpoint to get your token. Use it to call Gemini directly.

Base URL

All calls are relative to your broker host. Replace YOUR_SERVER.

http://YOUR_SERVER:8001

Authentication

One header. Get sk_… from admin: Dashboard → Projects → Generate.

X-API-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

401 = missing, 403 = invalid. Keys are project-scoped.

POST

/v1/json — JSON File Server

separate

Lightweight vault. Validates sk_…, mints 55m-cached ya29 from the stored SA, logs model, and returns the token JSON. No AI call.

Request — JSON server
curl -X POST http://YOUR_SERVER:8001/v1/json \
  -H "X-API-Key: sk_..." \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-1.5-flash"}'
# also: POST /v1/json/gemini-1.5-flash  — same
Response — 200 (not raw SA)
{
  "json_type": "token",
  "model": "gemini-1.5-flash",
  "project": "acme",
  "access_token": "ya29....",
  "expires_in": 3600
}

Private key never leaves server. Logged to Logs → Model.

POST

/v1/gemini/{model}:generateContent — Gemini Proxy

separate

Full proxy. Broker does the Vertex call for you and returns the AI response. Same X-API-Key + model allowlist, but broker handles auth + proxy.

curl -X POST http://YOUR_SERVER:8001/v1/gemini/gemini-1.5-flash:generateContent \
  -H "X-API-Key: sk_..." \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"role":"user","parts":[{"text":"Hello"}]}]}'
Response — 200 (Vertex proxied)
{"candidates":[{"content":{"parts":[{"text":"Hello!"}]}}]}
POST

/v1/token — Alias

Same as JSON server, kept for backwards compat. Use /v1/json for new code.

curl -X POST http://YOUR_SERVER:8001/v1/token \
  -H "X-API-Key: sk_..." \
  -d '{"model":"gemini-1.5-flash"}'

Example — add to your code

Get token, then call Vertex directly. No proxy needed.

Python
import requests, os

BROKER = os.getenv("BROKER_URL")  # http://YOUR_SERVER:8001
KEY = os.getenv("BROKER_API_KEY") # sk_...

# 1) Get token JSON
tok = requests.post(f"{BROKER}/v1/token",
  headers={"X-API-Key": KEY},
  json={"model":"gemini-1.5-flash"}).json()
access = tok["access_token"]

# 2) Call Gemini directly
r = requests.post(
  f"https://us-central1-aiplatform.googleapis.com/v1/projects/{tok['project_id']}/locations/us-central1/publishers/google/models/gemini-1.5-flash:generateContent",
  headers={"Authorization": f"Bearer {access}"},
  json={"contents":[{"role":"user","parts":[{"text":"Hello"}]}]})
print(r.json()["candidates"][0]["content"]["parts"][0]["text"])
Node
const tok = await fetch(`${process.env.BROKER_URL}/v1/token`, {
  method:"POST",
  headers:{"X-API-Key": process.env.BROKER_API_KEY, "Content-Type":"application/json"},
  body: JSON.stringify({model:"gemini-1.5-flash"})
}).then(r=>r.json());

const res = await fetch(
  `https://us-central1-aiplatform.googleapis.com/v1/projects/${tok.project_id}/locations/us-central1/publishers/google/models/gemini-1.5-flash:generateContent`,
  {method:"POST", headers:{Authorization:`Bearer ${tok.access_token}`},
   body: JSON.stringify({contents:[{role:"user", parts:[{text:"Hello"}]}]})}
);
console.log((await res.json()).candidates[0].content.parts[0].text);
.env for your app
BROKER_URL=http://YOUR_SERVER:8001
BROKER_API_KEY=sk_xxxxxxxxxxxxxxxx
# that's it — no SA JSON in your repo

Errors

401
Missing key
403
Invalid key
400
Model not allowed