Call Cortex from your code
A single streaming endpoint that returns Cortex's response token-by-token using the AI SDK UI message stream format.
Endpoint
POST /api/chatBody: { threadId: string, messages: UIMessage[] }. Each message has id, role ("user" | "assistant"), and parts: [{ type: "text", text }]. Requires Authorization: Bearer <access_token> from a signed-in session, and a threadId owned by that user.
cURL
curl -N -X POST https://jriza.in/api/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"threadId": "YOUR_THREAD_UUID",
"messages": [
{
"id": "1",
"role": "user",
"parts": [{ "type": "text", "text": "Design a scraper for a JS-heavy product page." }]
}
]
}'JavaScript / TypeScript
// Sign in via the app first, then read the access token from your Supabase session.
const res = await fetch("https://jriza.in/api/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
threadId,
messages: [
{
id: crypto.randomUUID(),
role: "user",
parts: [{ type: "text", text: "Build a Playwright scraper with proxy rotation." }],
},
],
}),
});
const reader = res.body!.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) break;
process.stdout.write(decoder.decode(value));
}Python
import requests, uuid
resp = requests.post(
"https://jriza.in/api/chat",
headers={"Authorization": f"Bearer {access_token}"},
json={
"threadId": thread_id,
"messages": [{
"id": str(uuid.uuid4()),
"role": "user",
"parts": [{"type": "text", "text": "ETL pipeline Shopify -> Postgres with retries."}],
}],
},
stream=True,
)
for chunk in resp.iter_content(chunk_size=None):
print(chunk.decode(), end="", flush=True)Base URL
Production endpoints are served from https://jriza.in. If you're testing against your own deployment, swap the host accordingly.