Token BrokerDocs
Dashboard

Developer Reference

API Reference

Two separate ways to use the broker. Pick one — don’t mix.

A — JSON File Server
Get token JSON
POST /v1/json → ya29 → you call Vertex
No AI proxy. Fastest.
B — Gemini Proxy
Get AI response
POST /v1/gemini/… → broker calls Vertex
One call, no GCP auth in your code.

Base URL

All endpoints are relative to your broker host.

http://YOUR_SERVER:8001

In your app .env: BROKER_URL=http://YOUR_SERVER:8001 + BROKER_API_KEY=sk_…

Authentication

One header for both A and B. No OAuth in your code.

X-API-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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

A

JSON File Server

separate

Get a token JSON only. You call Vertex yourself. Logged as /v1/json with model.

POST /v1/json — cURL
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
Python — then call Vertex directly
import requests, os
BROKER=os.getenv("BROKER_URL")
KEY=os.getenv("BROKER_API_KEY")
tok=requests.post(f"{BROKER}/v1/json", headers={"X-API-Key":KEY}, json={"model":"gemini-1.5-flash"}).json()
# tok = {"access_token":"ya29…","model":"gemini-1.5-flash","project":"acme",...}
import requests as req
req.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 {tok['access_token']}"},
  json={"contents":[{"role":"user","parts":[{"text":"Hello"}]}]})
Response — 200
{"json_type":"token","model":"gemini-1.5-flash","access_token":"ya29...","expires_in":3600}
B

Gemini Proxy

separate

Broker does the Vertex call and returns the AI response. One call from your code.

cURL
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"}]}]}'
Python
import requests, os
r=requests.post(f"{os.getenv('BROKER_URL')}/v1/gemini/gemini-1.5-flash:generateContent",
  headers={"X-API-Key": os.getenv("BROKER_API_KEY")},
  json={"contents":[{"role":"user","parts":[{"text":"Hello"}]}]})
print(r.json()["candidates"][0]["content"]["parts"][0]["text"])
Response — 200
{"candidates":[{"content":{"parts":[{"text":"Hello!"}]}}]}
GET

/v1/models

curl http://YOUR_SERVER:8001/v1/models -H "X-API-Key: sk_..."
Loading…

Errors

401
Missing key
403
Invalid key
429
Rate limited