API Recipes

Modelflare API recipes (copy-paste)

Chat / streaming / list models / Responses / Anthropic / images / video. Auth: Authorization: Bearer YOUR_MODELFLARE_API_KEY. When fields vary by model, follow the linked docs pages.

Sample model IDs such as gpt-5.6-sol must be enabled on your key’s group. Live catalog = console.

Endpoint picker

FamilyEntryUse for
Chat CompletionsPOST /v1/chat/completionsOpenAI-compatible chat
ResponsesPOST /v1/responsesCodex, Grok Build
Anthropic MessagesANTHROPIC_BASE_URL=https://modelflare.devClaude Code (CLI appends path)
ImagesPOST /v1/images/generationsGPT Images / Wan / Seedream
Gemini nativePOST /v1/models/{model}:generateContentGemini image models (Gemini CLI builds the same path under /v1beta, served only on modelflare.dev)
VideoPOST /v1/videos → poll GET /v1/videos/{task_id} → GET /v1/videos/{task_id}/contentAsync video tasks
ModelsGET /v1/modelsModels the current key can call

Full table: docs → endpoints

1) Chat Completions — curl

curl https://modelflare.dev/v1/chat/completions \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.6-sol","messages":[{"role":"user","content":"ping"}]}'

2) Chat Completions — Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_MODELFLARE_API_KEY",
    base_url="https://modelflare.dev/v1",
)
r = client.chat.completions.create(
    model="gpt-5.6-sol",
    messages=[{"role": "user", "content": "Hello from Hugging Face"}],
)
print(r.choices[0].message.content)

3) Streaming chat

The docs do not include a streaming example; this follows the OpenAI SDK stream=True pattern. Once content has been sent, the gateway does not replay a stream on another route.

stream = client.chat.completions.create(
    model="gpt-5.6-sol",
    messages=[{"role": "user", "content": "Say hi in one line"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

4) List models

curl https://modelflare.dev/v1/models \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY"

5) Responses API (for Codex) — curl stub

For full Codex install and wire_api=responses, follow the docs. This is a minimal request sketch only.

curl https://modelflare.dev/v1/responses \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.6-sol","input":"Reply with one sentence confirming the model."}'

Full Codex guide →

6) Anthropic Messages

The docs document Anthropic Messages through Claude Code: set ANTHROPIC_BASE_URL=https://modelflare.dev (no /v1); the CLI appends the Messages path itself. Raw HTTP headers are not documented, so no curl sketch is shown.

Full Claude Code guide →

7) Images

Documented gpt-image-2 example. Fields vary by model; use a Smart API Key or a media group key.

curl https://modelflare.dev/v1/images/generations \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A white cat runs through a neon-lit street in the rain",
    "size": "1024x1024", "n": 1
  }'

Image models docs →

8) Video: create, poll, download

  1. POST /v1/videos creates an async task and returns id (compatibility responses may use task_id). The body is family-specific; this is the documented Seedance example.
  2. Poll GET /v1/videos/{task_id} while status is queued or in_progress; stop at completed or failed.
  3. Download GET /v1/videos/{task_id}/content; result URLs can expire, so store the file promptly.
curl https://modelflare.dev/v1/videos \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "seedance-2.5",
    "content": [{"type": "text", "text": "A cat walks through a sunlit room"}],
    "resolution": "720p",
    "duration": 5,
    "ratio": "16:9"
  }'

curl https://modelflare.dev/v1/videos/TASK_ID \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY"

curl --fail --location \
  https://modelflare.dev/v1/videos/TASK_ID/content \
  -H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
  --output seedance-result.mp4

Video models docs →

Coming from Hub? start · coding-agents · Getting Started. Gradio Chat needs HF PRO (upcoming); use console + API for now.