DEVELOPER DOCUMENTATION

One unified API key across text, vision, image, and cinema video.

Drop-in compatible with OpenAI Chat / Images / Videos, Anthropic /v1/messages, and Volcengine Ark Seedance tasks — settled transparently in USD with x-request-id trace headers on every response.

Unified Base URL

https://api.turiloop.com/v1

Auth & Traceability

Bearer sk-tl-... · x-request-id on every response

Full-Modality Protocols

Chat · /v1/messages · Vision · Images · Seedance Video

Financial Safety

Pre-hold exact settlement · 100% auto-refund on failed video tasks

Quickstart

Create a native sk-tl-... key in the Console, store it in TURILOOP_API_KEY on your server, and connect official OpenAI SDKs, Anthropic SDKs, or HTTP clients with zero code rewrite.

1. Text & Reasoning (DeepSeek / Qwen / GLM / Kimi / MiniMax)

Streaming Reasoning Chain & Prompt Caching Billing

Reasoning models (such as deepseek-reasoner, glm-5, qwen3-max, kimi-k2.5) stream step-by-step thoughts in delta.reasoning_content before delta.content. Cached input tokens (cached_tokens / cache_read_input_tokens) are automatically billed at the discounted cache rate (typically 10%–25% of standard input rates), and every response carries an x-request-id header for instant trace lookup.

import os
from openai import OpenAI

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

stream = client.chat.completions.create(
    model="deepseek-reasoner",  # or deepseek-v3.2 / qwen3-max / glm-5 / kimi-k2.5
    messages=[{"role": "user", "content": "Design an idempotent payment webhook consumer."}],
    stream=True,
    stream_options={"include_usage": True},
)

for chunk in stream:
    if chunk.choices:
        delta = chunk.choices[0].delta
        reasoning = getattr(delta, "reasoning_content", None)
        if reasoning:
            print(reasoning, end="", flush=True)
        if delta.content:
            print(delta.content, end="", flush=True)

2. Native /v1/messages (Claude Code / Cline / Roo Code Direct Setup)

The gateway natively implements the Anthropic Messages specification, including multi-turn tool_use, thinking blocks, and prompt cache accounting — point CLI and IDE agents straight at Turiloop.

Anthropic Messages Native Endpoint
POST/v1/messages
OpenAI Chat Completions Endpoint
POST/v1/chat/completions
Claude Code / Cline / Roo Code Zero-Rewrite Direct Setup

Turiloop natively implements POST /v1/messages (including streaming tool_use, thinking blocks, and prompt cache accounting). Connect CLI and IDE coding agents in 30 seconds:

# Claude Code CLI (zero code rewrite — native /v1/messages)
export ANTHROPIC_BASE_URL="https://api.turiloop.com"
export ANTHROPIC_API_KEY="$TURILOOP_API_KEY"
export ANTHROPIC_MODEL="qwen3-coder-plus"   # or deepseek-v3.2 / glm-5 / kimi-k2.5
claude
  • Cline / Roo Code: Choose 'Anthropic' or 'OpenAI Compatible' provider; set Base URL to https://api.turiloop.com (for Anthropic protocol) or https://api.turiloop.com/v1 (for OpenAI protocol).
  • Cursor / Continue: Add custom API key sk-tl-... with Base URL https://api.turiloop.com/v1 and model ID qwen3-coder-plus or deepseek-v3.2.
  • Per-key Spend Guard: Configure daily/monthly USD caps and model allowlists in Console -> API Keys for team safety.
import os
import anthropic

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

msg = client.messages.create(
    model="qwen3-coder-plus",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Refactor this function for strict type safety."}],
)
print(msg.content[0].text)

Vision Understanding & Multi-Image Input (Qwen-VL / GLM-4.5V / Kimi-VL)

Pass HTTPS image URLs or inline Base64 Data URIs (data:image/png;base64,...) inside messages[].content[]. The gateway strips raw Base64 bytes during pre-hold estimation so multi-megabyte high-res images never inflate token holds.

  • Supported formats: PNG, JPEG, WebP, GIF via HTTPS URL or data:image/<ext>;base64,<payload>.
  • Resolution control: Set image_url.detail to 'high' for dense OCR/diagrams or 'auto' for general visual Q&A.
  • Recommended models: qwen3-vl-plus (fast OCR & UI), glm-4.5v (visual reasoning), kimi-k2.5 (long-context multimodal).
import base64, os
from openai import OpenAI

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

with open("invoice-scan.jpg", "rb") as f:
    b64 = base64.b64encode(f.read()).decode("utf-8")

resp = client.chat.completions.create(
    model="qwen3-vl-plus",  # Also supports glm-4.5v / kimi-k2.5
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Extract line items and total USD as JSON."},
            {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}", "detail": "high"}},
            {"type": "image_url", "image_url": {"url": "https://turiloop.com/studio-showcase/showcase-01.webp"}}
        ]
    }]
)
print(resp.choices[0].message.content)

4. Image Generation & Editing (Seedream 4.5 / Wanx / GPT-Image)

Compatible with the OpenAI Images API: pass seedream-4.5, wanx2.1-t2i-turbo, or gpt-image-2 in model; call /v1/images/generations for text-to-image and /v1/images/edits for base-image editing.

POSTText-to-image endpointhttps://api.turiloop.com/v1/images/generations
POSTImage edit endpointhttps://api.turiloop.com/v1/images/edits
import os
from openai import OpenAI

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

# 1) Text-to-Image (/v1/images/generations)
img = client.images.generate(
    model="seedream-4.5",  # seedream-4.5 / wanx2.1-t2i-turbo / gpt-image-2
    prompt="Editorial studio product shot of anodized titanium headphones on slate stone, rim light",
    size="1024x1024",
    n=1,
)
print(img.data[0].url)

# 2) Image Edit (/v1/images/edits)
with open("input.png", "rb") as f:
    edited = client.images.edit(
        model="seedream-4.5",
        image=f,
        prompt="Replace background with minimalist concrete gallery lighting",
        size="1024x1024",
    )
print(edited.data[0].url)

Common parameters: prompt description (required) · size dimensions (e.g. 1024x1024) · n variant count (billed by actual n) · response_format url or b64_json · pass PNG/JPG/WebP file in image for edits.

Async Video Generation Zone (Seedance / Wan 2.6 / Kling / HappyHorse / Hailuo / Vidu)

Turiloop supports both the Unified Standard Video API (/v1/video/generations) and the Volcengine Ark Seedance Native API (/v1/contents/generations/tasks) with one sk-tl-... key, transparent per-second tiered USD billing, zero-cost GET polling, and automatic 100% refunds on failed tasks.

POSTStandard Unified Video Endpointhttps://api.turiloop.com/v1/video/generations
POSTVolcengine Ark Seedance Native Endpointhttps://api.turiloop.com/v1/contents/generations/tasks

Mode A · Standard Unified Video API (POST /v1/video/generations + GET /v1/videos/{task_id})

Ideal when switching across Wan 2.6, Kling, HappyHorse, Hailuo, Vidu, and Seedance with a single normalized JSON schema.

import os, time, requests

API_BASE = "https://api.turiloop.com/v1"
HEADERS = {
    "Authorization": f"Bearer {os.environ['TURILOOP_API_KEY']}",
    "Content-Type": "application/json",
}

# 1. Create async video task (Wan 2.6 / Kling / HappyHorse / Hailuo / Vidu)
create_resp = requests.post(
    f"{API_BASE}/video/generations",
    headers=HEADERS,
    json={
        "model": "wan2.6-t2v",  # kling-v2-master / happyhorse-1.1-t2v / hailuo-02 / vidu-q1
        "prompt": "Anamorphic tracking shot along rain-washed Tokyo alley at dusk, 24fps film grain",
        "resolution": "1080p",
        "duration": 5,
        "aspect_ratio": "16:9",
    },
    timeout=60,
)
create_resp.raise_for_status()
task_id = create_resp.json().get("id") or create_resp.json().get("task_id")

# 2. Poll status (GET polling is $0 free; failed/cancelled tasks auto-refund 100%)
while True:
    poll = requests.get(f"{API_BASE}/videos/{task_id}", headers=HEADERS, timeout=30).json()
    status = (poll.get("status") or poll.get("task_status") or "").lower()
    if status in ("succeeded", "completed", "success", "succeed"):
        print("Video URL:", poll.get("video_url") or poll.get("metadata", {}).get("url") or poll)
        break
    if status in ("failed", "cancelled", "canceled", "expired"):
        raise RuntimeError(f"Task {status} (auto-refunded): {poll}")
    time.sleep(5)

Mode B · Volcengine Ark Seedance Native API (POST /v1/contents/generations/tasks)

100% drop-in compatible with official ByteDance Volcengine Ark payloads — supports inline flags (--rs / --dur / --rt / --cf), first_frame + last_frame dual keyframes, and Seedance 1.5 Pro synchronized audio.

T2V
Text-to-Video

Pass type: 'text' in content[] with doubao-seedance-1-0-pro or lite-t2v.

First Frame
Image-to-Video

Append an image_url item with role: 'first_frame' to animate a still frame.

First + Last
Dual Keyframe Control

Pass both role: 'first_frame' and role: 'last_frame' for smooth shot transitions.

Native Audio
Seedance 1.5 Pro Audio

Set generate_audio: true on seedance-1.5-pro to synthesize synced Foley, ambience & speech.

import os, time, requests

API_BASE = "https://api.turiloop.com/v1"
HEADERS = {
    "Authorization": f"Bearer {os.environ['TURILOOP_API_KEY']}",
    "Content-Type": "application/json",
}

# Seedance 1.5 Pro: First + Last Frame Keyframes + Native Synchronized Audio
payload = {
    "model": "seedance-1.5-pro",  # Also: doubao-seedance-1-0-pro / doubao-seedance-1-0-lite-t2v / lite-i2v
    "content": [
        {
            "type": "text",
            "text": "雨夜东方竹林石阶,灯笼暖光摇曳,镜头平稳推进 --rs 1080p --dur 5 --rt 16:9 --cf false"
        },
        {
            "type": "image_url",
            "image_url": {"url": "https://turiloop.com/studio-showcase/showcase-01.webp"},
            "role": "first_frame"
        },
        {
            "type": "image_url",
            "image_url": {"url": "https://turiloop.com/studio-showcase/showcase-03.webp"},
            "role": "last_frame"
        }
    ],
    "generate_audio": True,
    "return_last_frame": True,
    "seed": 42
}

resp = requests.post(f"{API_BASE}/contents/generations/tasks", headers=HEADERS, json=payload, timeout=60)
resp.raise_for_status()
task_id = resp.json()["id"]

while True:
    task = requests.get(f"{API_BASE}/contents/generations/tasks/{task_id}", headers=HEADERS, timeout=30).json()
    if task.get("status") == "succeeded":
        print("MP4 URL:", task["content"]["video_url"])
        break
    if task.get("status") in ("failed", "cancelled", "expired"):
        raise RuntimeError(f"Seedance task {task.get('status')} (auto-refunded): {task}")
    time.sleep(5)

Video Parameters, Billing Tiers & Inline Flag Reference

Parameter / Inline FlagAccepted ValuesBilling & Gateway Behavior
resolution / size / --rs480p · 720p · 1080p (or 854*480 / 1280*720 / 1920*1080)Billed at the exact per-second USD rate of the selected resolution tier (defaults to 1080p when omitted).
duration / seconds / --dur4 – 12s (integer seconds; model-dependent up to 15s)Charge = duration (s) × tier USD/s × n. Non-positive or malformed duration is rejected with HTTP 400 before holding funds.
aspect_ratio / ratio / --rt16:9 · 9:16 · 1:1 · 21:9 · 4:3 · 3:4 · keep_ratioControls landscape, TikTok vertical, square, or cinema widescreen framing without changing per-second tier price.
content[].rolefirst_frame · last_frameSupports HTTPS URL or data:image/... Base64 keyframes for Seedance, Wan 2.6, Kling, and HappyHorse.
generate_audiotrue · false (Seedance 1.5 Pro)Enables native audio-visual synthesis; billed at the model's configured audio per-second USD rate.
camera_fixed / --cf · seed · watermarkboolean / int32Locks camera movement (--cf true), fixes random seed for reproducible character shots, and toggles watermark.
Zero-Cost Polling & Automatic 100% Refund Guarantee

All GET /v1/videos/{id}, GET /v1/tasks/{id}, GET /v1/contents/generations/tasks/{id}, and GET /v1/videos/{id}/content requests enforce per-account ownership isolation and strictly bill $0.00. If an async video task reaches FAILED, CANCELED, or EXPIRED on upstream, the gateway automatically and idempotently refunds 100% of the settled amount back to your USD wallet.

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.

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 support.
502Upstream unavailableThe upstream service is briefly down; retry later.
504Request timeoutReduce max_tokens or pick a faster model.