Chat

Cortex API

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/chat

Body: { threadId: string, messages: UIMessage[] }. Each message has id, role ("user" | "assistant"), and parts: [{ type: "text", text }]. Sign in with your email (magic link) to get an authenticated cortex_sid cookie; the threadId must have been created by the same account (create it in the web app). Requests without a valid session return 401.

cURL

# 1. Sign in to the web app https://jriza.in (magic link via email).
# 2. Grab the cortex_sid cookie from your browser, then stream with it.
curl -N -X POST https://jriza.in/api/chat \
  -H "Content-Type: application/json" \
  -H "Cookie: cortex_sid=YOUR_SESSION_COOKIE" \
  -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 web app, then call the API from the same browser context.
// Cookies (cortex_sid) carry the authenticated session automatically.
const res = await fetch("https://jriza.in/api/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  credentials: "include",
  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

# Use the same browser cookies so the cortex_sid session is authenticated.
s = requests.Session()
resp = s.post(
    "https://jriza.in/api/chat",
    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.