API
OpenAI-compatible endpoint
Send standard HTTPS requests to /v1/chat/completions — drop-in compatible with the OpenAI Chat Completions schema.
Anything that already speaks to OpenAI works on Token Harbor with a single base-URL swap. Grab or rotate a key on the dashboard first; keys look like
thk_live_….Non-streaming
Returns the full response in a single JSON body. Best for short completions and synchronous request paths.
import requests
response = requests.post(
url="https://tokenharbor.ai/v1/chat/completions",
headers={
"Authorization": "Bearer thk_live_PASTE_YOURS_HERE",
"Content-Type": "application/json",
},
json={
"model": "gpt-5",
"messages": [{"role": "user", "content": "Hi"}],
},
)
print(response.json()["choices"][0]["message"]["content"])Streaming
Pass stream: true and the server emits Server-Sent Events so tokens arrive as they're generated.
import requests
with requests.post(
url="https://tokenharbor.ai/v1/chat/completions",
headers={
"Authorization": "Bearer thk_live_PASTE_YOURS_HERE",
"Content-Type": "application/json",
},
json={
"model": "gpt-5",
"messages": [{"role": "user", "content": "Write a haiku about the sea."}],
"stream": True,
},
stream=True,
) as r:
for line in r.iter_lines():
if line:
print(line.decode("utf-8"))