API Quickstart & Advanced Examples

We don’t ship an official SDK. Call us over plain HTTP/HTTPS using the OpenAI-style protocol.

If you already use OpenAI’s official/community SDKs, you can usually just point base_url to our gateway and swap the api_key to your Console key. (Those SDKs aren’t maintained by us.)

1) Setup

  • Base URL: https://<your-gateway>/v1

  • API Key: Create in the Console; send via header Authorization: Bearer <key>

  • model: e.g., gpt-4.1-mini, gpt-4o, DeepSeek-V3 (see Model Catalog & Pricing)

export SIGHT_API_BASE="https://<your-gateway>/v1"
export SIGHT_API_KEY="sk-************************"

2) Minimal HTTP Examplesbash

2.1 cURL

curl -X POST "$SIGHT_API_BASE/chat/completions" \
  -H "Authorization: Bearer $SIGHT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1-mini",
    "messages": [{"role":"user","content":"Hello, SightAI!"}]
  }'

2.2 Node.js (native fetch, Node 18+)

const res = await fetch(`${process.env.SIGHT_API_BASE}/chat/completions`, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SIGHT_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4.1-mini",
    messages: [{ role: "user", content: "Hello" }]
  })
});
const data = await res.json();
console.log(data.choices?.[0]?.message?.content);

2.3 Python (requests)

import os, requests
r = requests.post(
  f"{os.environ['SIGHT_API_BASE']}/chat/completions",
  headers={
    "Authorization": f"Bearer {os.environ['SIGHT_API_KEY']}",
    "Content-Type": "application/json"
  },
  json={
    "model":"gpt-4.1-mini",
    "messages":[{"role":"user","content":"Hello"}]
  },
  timeout=60
)
print(r.status_code, r.json()["choices"][0]["message"]["content"])

3) Streaming (SSE)

3.1 Node.js (manual SSE parsing)

const res = await fetch(`${process.env.SIGHT_API_BASE}/chat/completions`, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SIGHT_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4.1-mini",
    stream: true,
    messages: [{ role: "user", content: "Say hi in 3 words." }]
  })
});

const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";

while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split("\n");
  buffer = lines.pop() || "";
  for (const line of lines) {
    if (!line.startsWith("data: ")) continue;
    const payload = line.slice(6).trim();
    if (!payload || payload === "[DONE]") continue;
    const json = JSON.parse(payload);
    const piece = json.choices?.[0]?.delta?.content || "";
    if (piece) process.stdout.write(piece);
  }
}

3.2 Python (requests stream)

import os, requests, json
resp = requests.post(
  f"{os.environ['SIGHT_API_BASE']}/chat/completions",
  headers={
    "Authorization": f"Bearer {os.environ['SIGHT_API_KEY']}",
    "Content-Type": "application/json"
  },
  json={
    "model":"gpt-4.1-mini",
    "stream": True,
    "messages":[{"role":"user","content":"Say hi in 3 words."}]
  },
  stream=True, timeout=300
)
for line in resp.iter_lines():
  if not line: 
    continue
  if line.startswith(b"data: "):
    payload = line[6:].strip()
    if payload == b"[DONE]":
      break
    chunk = json.loads(payload)
    piece = chunk.get("choices",[{}])[0].get("delta",{}).get("content","")
    if piece:
      print(piece, end="", flush=True)

4) Security & Go-Live Tips

  • Do not expose your API key in the browser; route calls from your backend.

  • Configure timeouts, retries, and concurrency limits to avoid cost spikes and 429s.

  • When you need structured output, prefer models with native json_schema; otherwise use json_object + client-side validation.

Last updated