Skip to main content
Documentation

Documentation menu

SDK examples

Call the API with curl, fetch, the OpenAI Python and Node SDKs and the Anthropic SDKs by overriding the base URL.

Last updated 2026-11-04

You do not need a special client. Point an official SDK at the base URL, give it your key, and use a model id from GET /v1/models. The examples read the key from the AIP_API_KEY environment variable.

curl

bash
curl -sS https://api.ticonai.com/v1/chat/completions \
  -H "Authorization: Bearer $AIP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [{ "role": "user", "content": "Hello!" }],
    "max_tokens": 64
  }'

fetch (Node 18 and later, or any runtime with fetch)

ts
const res = await fetch("https://api.ticonai.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.AIP_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "your-model-id",
    messages: [{ role: "user", content: "Hello!" }],
    max_tokens: 64,
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(JSON.stringify(await res.json()));

OpenAI SDK for Python

Install with pip install openai. Set base_url to the base URL, which ends in /v1.

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.ticonai.com/v1",
    api_key=os.environ["AIP_API_KEY"],
)

response = client.chat.completions.create(
    model="your-model-id",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=64,
)
print(response.choices[0].message.content)

Streaming with the same client:

python
stream = client.chat.completions.create(
    model="your-model-id",
    messages=[{"role": "user", "content": "Count to five."}],
    max_tokens=64,
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

OpenAI SDK for Node.js

Install with npm install openai.

ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.ticonai.com/v1",
  apiKey: process.env.AIP_API_KEY,
});

const response = await client.chat.completions.create({
  model: "your-model-id",
  messages: [{ role: "user", content: "Hello!" }],
  max_tokens: 64,
});
console.log(response.choices[0].message.content);

Anthropic SDK for Python

Install with pip install anthropic. The Anthropic SDK adds /v1/messages itself, so set base_url to the origin without /v1.

python
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.ticonai.com",
    api_key=os.environ["AIP_API_KEY"],
)

message = client.messages.create(
    model="your-model-id",
    max_tokens=64,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)

Anthropic SDK for Node.js

Install with npm install @anthropic-ai/sdk.

ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.ticonai.com",
  apiKey: process.env.AIP_API_KEY,
});

const message = await client.messages.create({
  model: "your-model-id",
  max_tokens: 64,
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(message.content[0].type === "text" ? message.content[0].text : "");

Notes

  • The key is accepted as Authorization: Bearer and as x-api-key, which is what the OpenAI and Anthropic SDKs send by default.
  • SDK retries are fine for 429 and 5xx. For non-streaming calls, also send an Idempotency-Key header so a retry cannot bill twice: both SDKs let you add default or per-request headers. See Idempotency.
  • Errors raised by the SDKs wrap the HTTP status and body described in Errors.