Docs

Integrate with the SDKs you already use.

Requests flow through Turiloop, with accounts, keys, and billing managed in one place.

Base URL

https://api.turing.yun/v1

Authentication

Bearer followed by your API key

Chat

Integrate with common SDKs

Billing

Pre-hold, then settle on actual usage

Quickstart

After creating a key, point baseURL at Turiloop and keep the key server-side.

Chat
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.TURILOOP_API_KEY,
  baseURL: "https://api.turing.yun/v1"
});

const completion = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [{ role: "user", content: "Hello, Turiloop" }]
});
Anthropic-compatible API

The gateway also implements the Anthropic Messages API (/v1/messages): clients such as Claude Code and the Anthropic SDK work out of the box, and each request is routed to the model you set in the model field. The OpenAI-compatible chat endpoint remains fully available.

Anthropic Messages
POST/v1/messages
OpenAI Chat Completions
POST/v1/chat/completions
Images

The model is fixed to gpt-image-2 and is compatible with the OpenAI image API: use /images/generations for text-to-image and /images/edits to edit from a base image.

POSTText to imagehttps://api.turing.yun/v1/images/generations
POSTImage edithttps://api.turing.yun/v1/images/edits
Text to image (generations)
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.TURILOOP_API_KEY,
  baseURL: "https://api.turing.yun/v1"
});

const image = await client.images.generate({
  model: "gpt-image-2",
  prompt: "A premium, high-tech product poster",
  size: "3840x2160",
  quality: "high",
  n: 1
});

You can also upload the file directly with curl (multipart):

curl https://api.turing.yun/v1/images/edits \
  -H "Authorization: Bearer $TURILOOP_API_KEY" \
  -F "model=gpt-image-2" \
  -F "image=@input.png" \
  -F "prompt=Replace the background with a neon street at night" \
  -F "size=3840x2160"

Common params: prompt description (required) · size up to 3840x2160 · quality low / medium / high · n number of images (currently 1) · response_format url or b64_json · for edits, image is the base image (required). A client timeout of ≥ 300s is recommended.

Base URL

All requests go to a single Turiloop API endpoint, where the gateway validates, forwards, and logs each call.

https://api.turiloop.com/v1

Authentication

Authenticate with a Bearer key. Keep the key server-side only.

Authorization: Bearer YOUR_TURILOOP_API_KEY

Streaming

Keep using the stream parameter and read incremental content over SSE.

stream: true

Billing

Balance is prepaid; overdrafts are not allowed. Large requests are held first, then settled on actual usage.

Pre-hold → Settle on usage → Refund difference

Error Codes

Common errors include insufficient balance, model unavailable, rate limiting, and service timeouts. Handle them by HTTP status code and the code field.

400Malformed requestCheck the JSON structure and required fields.
401Authentication failedVerify the key is correct, not expired, and not disabled.
402Insufficient balanceRecovers automatically after a top-up — top up anytime in the console.
403Model unavailableThe model may be disabled or not in your current group.
429Rate limitedLower concurrency or upgrade to a higher group.
500Internal server errorRetry once; if it persists, contact the admin.
502Upstream unavailableThe upstream service is briefly down; retry later.
504Request timeoutReduce max_tokens or pick a faster model.

SDK Examples

Node.js, Python, and curl all use the same base URL and key. Keep the key in server-side environment variables only.

Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TURILOOP_API_KEY"],
    base_url="https://api.turing.yun/v1"
)

chat = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Hello"}]
)
print(chat.choices[0].message.content)
curl
curl https://api.turing.yun/v1/chat/completions \
  -H "Authorization: Bearer $TURILOOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [
      {"role": "user", "content": "Hello"}
    ]
  }'

Video generation (HappyHorse)

The HappyHorse family supports text-to-video (t2v), image-to-video (i2v), reference-to-video (r2v) and video-edit. Billing is per second of output at two resolution tiers (720P / 1080P — see Pricing). Video runs as an async task: create a task to get a task_id, then poll for the result.

1. Create a video task
curl -X POST "https://api.turiloop.com/v1/video/generations" \n  -H "Authorization: Bearer $TURILOOP_API_KEY" \n  -H "Content-Type: application/json" \n  -d {
    "model": "happyhorse-1.1-t2v",
    "prompt": "A corgi surfing on a sunny beach, cinematic",
    "size": "1280*720",
    "seconds": "3"
  }
2. Poll the task result (generation usually takes 1–3 minutes)
curl "https://api.turiloop.com/v1/videos/{task_id}" \n  -H "Authorization: Bearer $TURILOOP_API_KEY"

# status: queued -> in_progress -> completed
# On completed, metadata.url holds the generated MP4 (time-limited link, download promptly)

Billing: seconds × the per-second rate of the chosen resolution, settled when the task is created; failed tasks are refunded in full automatically. Request fields: pass size as the pixel resolution "1280*720" (720P) or "1920*1080" (1080P); seconds is a string, 3-15. Models: happyhorse-1.1-t2v for text-to-video (prompt only); happyhorse-1.1-i2v for image-to-video (add image with a first-frame URL); happyhorse-1.1-r2v for reference-to-video (add images, an array of 1-9 reference URLs); happyhorse-1.0-video-edit for video editing. Task statuses: queued / in_progress / completed / failed.