Spaces:
Running

modelflaredev commited on
Commit
47813cf
·
verified ·
1 Parent(s): 3e4259c

Upload 7 files

Browse files
README.md CHANGED
@@ -1,10 +1,19 @@
1
  ---
2
- title: Blog
3
- emoji: 👀
4
- colorFrom: red
5
- colorTo: yellow
6
  sdk: static
 
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: Modelflare Blog
3
+ emoji: 📝
4
+ colorFrom: indigo
5
+ colorTo: pink
6
  sdk: static
7
+ app_file: index.html
8
  pinned: false
9
+ license: mit
10
+ short_description: "Engineering notes and guides for Modelflare and Castaly"
11
  ---
12
 
13
+ # Modelflare Blog
14
+
15
+ Articles on the Modelflare API gateway and the Castaly studio, published as a static Space. Open `index.html` for the article list.
16
+
17
+ - Console: https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog
18
+ - Docs: https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog
19
+ - Business: business@modelflare.dev
api-recipes-streaming-fallback.html ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Modelflare API recipes: streaming, routing fallback, images, and async video | Modelflare Blog</title>
7
+ <meta name="description" content="Request examples for streaming chat, gateway-side fallback with group failover and Smart API Keys, client-side model fallback, image generation, and the asynchronous video task flow.">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <article><h1>Modelflare API recipes: streaming, routing fallback, images, and async video</h1>
43
+ <p class="lead">Request examples for streaming chat, gateway-side fallback with group failover and Smart API Keys, client-side model fallback, image generation, and the asynchronous video task flow.</p>
44
+ <hr />
45
+ <p>The recipes below use <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">Modelflare</a>'s OpenAI-compatible base URL, <code>https://modelflare.dev/v1</code>, and a placeholder key. Each model ID must be enabled on the key's routing group; check <code>GET /v1/models</code> or <a href="https://modelflare.dev/pricing?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">Models &amp; Pricing</a> before sending requests.</p>
46
+ <pre><code class="language-python">from openai import OpenAI
47
+ client = OpenAI(api_key=&quot;YOUR_MODELFLARE_API_KEY&quot;, base_url=&quot;https://modelflare.dev/v1&quot;)
48
+ </code></pre>
49
+ <h2>Streaming chat completions</h2>
50
+ <p>The streaming request follows the <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">Modelflare/api-examples</a> dataset: it sets <code>"stream": true</code> on Chat Completions and consumes server-sent events the same way the OpenAI SDK does with <code>stream=True</code>. The Modelflare documentation does not include a separate streaming example.</p>
51
+ <pre><code class="language-python">stream = client.chat.completions.create(
52
+ model=&quot;gpt-5.6-sol&quot;,
53
+ messages=[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Say hi in one line&quot;}],
54
+ stream=True,
55
+ )
56
+ for chunk in stream:
57
+ delta = chunk.choices[0].delta.content if chunk.choices else None
58
+ if delta:
59
+ print(delta, end=&quot;&quot;, flush=True)
60
+ </code></pre>
61
+ <p>The equivalent curl request:</p>
62
+ <pre><code class="language-bash">curl -N https://modelflare.dev/v1/chat/completions \
63
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
64
+ -H &quot;Content-Type: application/json&quot; \
65
+ -d '{&quot;model&quot;:&quot;gpt-5.6-sol&quot;,&quot;messages&quot;:[{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;Say hi in one line&quot;}],&quot;stream&quot;:true}'
66
+ </code></pre>
67
+ <p>Streaming interacts with failover in one specific way. Once a streamed response has written content bytes to the client, the gateway does not replay the request on another route; heartbeats alone do not count as content. A stream that fails after content has started must be retried by the client.</p>
68
+ <h2>Fallback at the gateway</h2>
69
+ <p>Modelflare implements fallback in the routing layer, so the request body does not change.</p>
70
+ <p>An ordinary key names a primary routing group and, optionally, fallback groups in priority order. The chain is configured in API Keys and can be reordered there. The gateway moves to the next group when the current group has no channel for the requested model, when the group is at its rate limit for the account, or when every channel priority in the group has returned a retryable error. It does not fail over on client errors (malformed JSON, an invalid parameter, context length exceeded), on a cancelled client connection, on a request pinned to one channel, or on a stream that has already sent content. The request is billed at the multiplier of the group that served it, and that group is recorded in the consume log. A key whose primary group is a limited-time campaign route must have at least one fallback group before it can be saved.</p>
71
+ <p>A Smart API Key is bound to <code>auto</code>. On each request it collects the groups the account can use, keeps those that serve the requested model, orders them by the key's strategy (Balanced, the default; Stability first; or Low price first), and tries them in order. Smart API Keys do not take a manual fallback list. Client code is unchanged: same base URL, same <code>Authorization: Bearer</code> header.</p>
72
+ <h2>Fallback across models in client code</h2>
73
+ <p>Switching to a different model after a failure is application logic, not a gateway feature. A minimal version:</p>
74
+ <pre><code class="language-python">from openai import APIStatusError
75
+
76
+ MODELS = [&quot;gpt-5.6-sol&quot;, &quot;YOUR_SECOND_MODEL_ID&quot;] # exact IDs your key can access
77
+
78
+ def chat_with_fallback(messages):
79
+ last = None
80
+ for m in MODELS:
81
+ try:
82
+ return client.chat.completions.create(model=m, messages=messages)
83
+ except APIStatusError as e:
84
+ last = e
85
+ if e.status_code in (400, 401, 403): # bad request, bad key, model/group not allowed
86
+ raise
87
+ raise last
88
+ </code></pre>
89
+ <p>Status codes 400, 401, and 403 indicate a malformed request, an invalid key, or a model or group the key may not use. They are raised immediately rather than masked by a retry.</p>
90
+ <h2>Image generation</h2>
91
+ <pre><code class="language-bash">curl https://modelflare.dev/v1/images/generations \
92
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
93
+ -H &quot;Content-Type: application/json&quot; \
94
+ -d '{
95
+ &quot;model&quot;: &quot;gpt-image-2&quot;,
96
+ &quot;prompt&quot;: &quot;A white cat runs through a neon-lit street in the rain&quot;,
97
+ &quot;size&quot;: &quot;1024x1024&quot;, &quot;n&quot;: 1
98
+ }'
99
+ </code></pre>
100
+ <p><code>gpt-image-2</code> returns Base64 image data in <code>data[].b64_json</code>. This endpoint serves GPT Images, Wan Image, and Seedream; the accepted fields vary by model and are listed on each <a href="https://docs.modelflare.dev/models/image/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">image model page</a>. Gemini image models use the native <code>POST /v1/models/{model}:generateContent</code> endpoint instead. Requests sent to the wrong family are rejected with <code>400 unsupported_endpoint</code>. Use a Smart API Key or a key on the <code>media</code> group.</p>
101
+ <h2>Asynchronous video</h2>
102
+ <p>Video generation is a three-step task: create, poll, download.</p>
103
+ <pre><code class="language-bash"># 1) create a task (Seedance example; the body differs per family)
104
+ curl https://modelflare.dev/v1/videos \
105
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
106
+ -H &quot;Content-Type: application/json&quot; \
107
+ -d '{
108
+ &quot;model&quot;: &quot;seedance-2.5&quot;,
109
+ &quot;content&quot;: [{&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: &quot;A cat walks through a sunlit room&quot;}],
110
+ &quot;resolution&quot;: &quot;720p&quot;,
111
+ &quot;duration&quot;: 5,
112
+ &quot;ratio&quot;: &quot;16:9&quot;
113
+ }'
114
+ # save &quot;id&quot; from the response (compatibility responses may use &quot;task_id&quot;)
115
+
116
+ # 2) poll while status is &quot;queued&quot; or &quot;in_progress&quot;; stop at &quot;completed&quot; or &quot;failed&quot;
117
+ curl https://modelflare.dev/v1/videos/TASK_ID \
118
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot;
119
+
120
+ # 3) download
121
+ curl --fail --location \
122
+ https://modelflare.dev/v1/videos/TASK_ID/content \
123
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
124
+ --output seedance-result.mp4
125
+ </code></pre>
126
+ <p>Task creation can return an ID before provider validation finishes, so a later poll may report <code>failed</code>; keep the request ID for investigation. The request body depends on the model family (Seedance, Wan, Kling, MiniMax, HappyHorse) and is documented on each <a href="https://docs.modelflare.dev/models/video/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">video model page</a>. Result URLs can expire, so store the file promptly.</p>
127
+ <h2>Responses API</h2>
128
+ <p><code>POST /v1/responses</code> is the endpoint used by Codex and Grok Build. The documentation does not show a raw request body; the request below comes from the <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">Modelflare/api-examples</a> dataset.</p>
129
+ <pre><code class="language-bash">curl https://modelflare.dev/v1/responses \
130
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
131
+ -H &quot;Content-Type: application/json&quot; \
132
+ -d '{&quot;model&quot;: &quot;gpt-5.6-sol&quot;, &quot;input&quot;: &quot;Reply with one sentence confirming the model.&quot;}'
133
+ </code></pre>
134
+ <h2>References</h2>
135
+ <p>The <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">Modelflare/api-recipes</a> Space and the <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">Modelflare/api-examples</a> dataset contain these requests. Background reading: <a href="https://docs.modelflare.dev/guides/endpoints/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">Which endpoint to call</a>, <a href="https://docs.modelflare.dev/guides/features/group-failover/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">Group failover</a>, and <a href="https://docs.modelflare.dev/guides/features/smart-api-key/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=api-recipes-streaming-fallback">Smart API Key</a>. Higher limits or volume arrangements: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>.</p>
136
+ <hr />
137
+ <p><strong>中文摘要:</strong> 本文汇总 Modelflare 常用请求示例,包括:Chat Completions 流式输出(内容开始返回后网关不再切换路由);网关侧回退,即普通 key 的分组故障转移,以及 Smart API Key 按“均衡”“稳定优先”“低价优先”策略自动选路;在客户端切换模型的重试写法;图片生成;视频任务的创建、轮询和下载流程;以及 Responses 接口请求示例。</p></article><p><a href="index.html">&larr; All articles</a></p>
138
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
139
+ </html>
castaly-image-video-studio.html ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Castaly: an AI video and image studio built on Modelflare | Modelflare Blog</title>
7
+ <meta name="description" content="Castaly is a browser studio for AI image and video generation. Models are compared by specification and price, generations are paid from a wallet shared with Modelflare, and every model is also available through the Modelflare API."><meta property="og:image" content="images/cover.jpg">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <article><h1>Castaly: an AI video and image studio built on Modelflare</h1>
43
+ <p class="lead">Castaly is a browser studio for AI image and video generation. Models are compared by specification and price, generations are paid from a wallet shared with Modelflare, and every model is also available through the Modelflare API.</p>
44
+ <p><img alt="Orbital ring city, generated with gemini-3-pro-image" src="images/cover.jpg" /></p>
45
+ <p>Cover: "Orbital ring city", generated in Castaly with <code>gemini-3-pro-image</code> (2K, 16:9), cropped to 1200x630.</p>
46
+ <hr />
47
+ <p><a href="https://castaly.modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Castaly</a> is an AI video and image studio. It generates video and images with leading models, shows their specifications and prices side by side, and exposes each model's parameters directly. It runs on the <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Modelflare</a> gateway, so the models used in the studio are the same ones available from code.</p>
48
+ <h2>Choosing a model</h2>
49
+ <p>World-building, character work, and action shots each depend on different model strengths. Castaly organizes the choice by task and then compares specification and cost across candidates. Each result keeps the model and specification it was generated with and is stored in the user's library. The homepage's "Make any video" section shows eight examples, each a real output from a model Castaly runs; opening one starts a new generation from the same prompt.</p>
50
+ <p><img alt="A humpback whale floating above a wheat field" src="images/fig1-whale-over-wheat.jpg" />
51
+ <em>"Whale over wheat", <code>gpt-image-2.5-flare</code>, 1536 × 1024.</em></p>
52
+ <h2>Available models</h2>
53
+ <p>Castaly uses the image and video models in the Modelflare catalog, which the <a href="https://docs.modelflare.dev/models/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">documentation</a> lists as 14 image models and 28 video models. The workbench lists only the models enabled for the signed-in account. The general-purpose models include:</p>
54
+ <table>
55
+ <thead>
56
+ <tr>
57
+ <th>Type</th>
58
+ <th>Family</th>
59
+ <th>Model IDs</th>
60
+ </tr>
61
+ </thead>
62
+ <tbody>
63
+ <tr>
64
+ <td>Image</td>
65
+ <td>OpenAI Images</td>
66
+ <td><code>gpt-image-2.5-sunburst</code>, <code>gpt-image-2.5-flare</code>, <code>gpt-image-2</code></td>
67
+ </tr>
68
+ <tr>
69
+ <td>Image</td>
70
+ <td>Gemini Image</td>
71
+ <td><code>gemini-3-pro-image</code>, <code>gemini-3.1-flash-image</code>, <code>gemini-3.1-flash-lite-image</code>, <code>gemini-2.5-flash-image</code></td>
72
+ </tr>
73
+ <tr>
74
+ <td>Image</td>
75
+ <td>Wan, Seedream</td>
76
+ <td><code>wan2.7-image</code>, <code>wan2.7-image-pro</code>, <code>seedream-5-0-lite-260128</code></td>
77
+ </tr>
78
+ <tr>
79
+ <td>Video</td>
80
+ <td>Seedance</td>
81
+ <td><code>seedance-2.5</code>, <code>seedance-2.0</code>, <code>seedance-2.0-fast</code>, <code>seedance-2.0-mini</code></td>
82
+ </tr>
83
+ <tr>
84
+ <td>Video</td>
85
+ <td>Wan</td>
86
+ <td><code>wan3.0-video-prime</code>, <code>wan3.0-video</code>, <code>wan2.7-t2v</code>, <code>wan2.7-i2v</code>, <code>wan2.7-r2v</code></td>
87
+ </tr>
88
+ <tr>
89
+ <td>Video</td>
90
+ <td>Kling</td>
91
+ <td><code>kling-3.0</code>, <code>kling-3.0-omni</code>, <code>kling-3.0-turbo</code>, <code>kling-o1</code>, <code>kling-2.6</code>, <code>kling-2.5-turbo</code></td>
92
+ </tr>
93
+ <tr>
94
+ <td>Video</td>
95
+ <td>MiniMax, HappyHorse</td>
96
+ <td><code>MiniMax-H3</code>, <code>happyhorse-1.1-t2v</code>, <code>happyhorse-1.1-i2v</code>, <code>happyhorse-1.1-r2v</code></td>
97
+ </tr>
98
+ </tbody>
99
+ </table>
100
+ <p>The studio itself is for images and video. Language models such as GPT, Claude, and Grok are used through the Modelflare API and billed per million tokens, with separate input and output rates.</p>
101
+ <p><img alt="An empty room whose window holds back an ocean" src="images/fig2-ocean-behind-glass.jpg" />
102
+ <em>"An ocean behind the glass", Seedream 5.0 Lite, 2560 × 1440.</em></p>
103
+ <h2>Workflow</h2>
104
+ <p>Users sign in with a Modelflare account; the Castaly account, wallet, and usage history are the Modelflare ones. In the workbench, choose image or video, then a model. The price per image, per second, or per task appears next to the selector. Write a prompt, optionally attach a reference file or a library asset, and set the aspect ratio, resolution, quantity, or duration in the settings panel.</p>
105
+ <p>Each task is settled in USD from the shared wallet. The estimate and the actual cost of every task are shown under Creations. Finished images can be saved to the library and reused as references, and results can be published to the community with or without their prompt and settings. Published work can be withdrawn at any time from the My page.</p>
106
+ <p><img alt="A rainy Tokyo alley at night with neon reflections" src="images/fig3-rainy-tokyo-alley.jpg" />
107
+ <em>"Rainy Tokyo alley", <code>wan2.7-image-pro</code>, 2K.</em></p>
108
+ <h2>Pricing</h2>
109
+ <p>Castaly charges per generation, with no subscription and no minimum. Each image or video is billed on actual model usage; browsing, comparing, and writing prompts are free. Resolution, duration, size, and quality determine the rate, and the price updates before generation. Funds go into a single wallet that also pays for direct API calls, and the balance does not expire. Current per-model prices are published on the <a href="https://castaly.modelflare.dev/pricing/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">pricing page</a>.</p>
110
+ <h2>Community</h2>
111
+ <p>The <a href="https://castaly.modelflare.dev/community/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Community</a> page shows generated video and images together with the prompts and settings that produced them. Any prompt can be copied, and any work can be remixed in the studio.</p>
112
+ <p><img alt="A salt flat whose horizon peels up to reveal night" src="images/fig4-horizon-lifted.jpg" />
113
+ <em>"The horizon, lifted", Seedream 5.0 Lite, 2560 × 1440.</em></p>
114
+ <h2>Calling the same models from code</h2>
115
+ <p>The Modelflare gateway handles model access, balance, and usage. To call the same models from code, get a key from the My page, then either install the <a href="https://docs.modelflare.dev/guides/clients/media-skill/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Modelflare Media Skill</a> or copy the request from a workbench result, and set the key in the environment. Accounts created through Castaly already have a key named <code>Castaly</code> that routes across every group enabled for the account. Each workbench generation includes a "Reproduce this in your own agent" panel containing the install message, the skill package, and a task brief.</p>
116
+ <pre><code class="language-bash">export MODELFLARE_API_KEY=&quot;YOUR_MODELFLARE_API_KEY&quot;
117
+ # video is async: create a task, poll GET /v1/videos/TASK_ID, then download /content
118
+ curl https://modelflare.dev/v1/videos \
119
+ -H &quot;Authorization: Bearer $MODELFLARE_API_KEY&quot; \
120
+ -H &quot;Content-Type: application/json&quot; \
121
+ -d '{
122
+ &quot;model&quot;: &quot;seedance-2.5&quot;,
123
+ &quot;content&quot;: [{&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: &quot;A cat walks through a sunlit room&quot;}],
124
+ &quot;resolution&quot;: &quot;720p&quot;,
125
+ &quot;duration&quot;: 5,
126
+ &quot;ratio&quot;: &quot;16:9&quot;
127
+ }'
128
+ </code></pre>
129
+ <h2>Enterprise</h2>
130
+ <p>Castaly Enterprise provides higher limits, priority support, and volume pricing for teams generating video and images through Castaly and the Modelflare API. Contact <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>.</p>
131
+ <h2>References</h2>
132
+ <p>Studio: <a href="https://castaly.modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">castaly.modelflare.dev</a>. Documentation: <a href="https://castaly.modelflare.dev/docs/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Castaly docs</a>. Pricing: <a href="https://castaly.modelflare.dev/pricing/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=castaly-image-video-studio">Castaly pricing</a>. Modelflare on Hugging Face: <a href="https://huggingface.co/Modelflare" target="_top">organization</a>, <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a>, <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a>. Business inquiries: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>.</p>
133
+ <hr />
134
+ <p><strong>中文摘要:</strong> Castaly 是基于 Modelflare 网关的 AI 视频与图片创作平台,支持按任务比较模型的规格与价格,并可直接调整各项生成参数。底层目录包括 14 个图片模型(GPT Images、Gemini、Wan、Seedream)和 28 个视频模型(Seedance、Wan、Kling、MiniMax、HappyHorse)。平台按次计费,无订阅、无最低消费;钱包与 Modelflare 共用,余额不过期。工作室中的模型均可通过 Modelflare API 或 Media Skill 在代码中调用。企业与商务合作请联系 business@modelflare.dev。</p></article><p><a href="index.html">&larr; All articles</a></p>
135
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
136
+ </html>
coding-agents-modelflare.html ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Configuring coding agents with Modelflare: Claude Code, Codex, OpenCode, Gemini CLI, CC-Switch, and Grok Build | Modelflare Blog</title>
7
+ <meta name="description" content="Claude Code connects through Anthropic Messages at `https://modelflare.dev`, Codex, OpenCode, and Grok Build through `https://modelflare.dev/v1`, and Gemini CLI through `GOOGLE_GEMINI_BASE_URL`. All of them use the same Modelflare key.">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <article><h1>Configuring coding agents with Modelflare: Claude Code, Codex, OpenCode, Gemini CLI, CC-Switch, and Grok Build</h1>
43
+ <p class="lead">Claude Code connects through Anthropic Messages at <code>https://modelflare.dev</code>, Codex, OpenCode, and Grok Build through <code>https://modelflare.dev/v1</code>, and Gemini CLI through <code>GOOGLE_GEMINI_BASE_URL</code>. All of them use the same Modelflare key.</p>
44
+ <hr />
45
+ <p>Coding agents expect different wire protocols. Claude Code uses Anthropic Messages, Codex and Grok Build use the OpenAI Responses API, OpenCode uses an OpenAI-compatible provider, and Gemini CLI uses the native Gemini API. <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">Modelflare</a> serves all of them behind one key. This guide gives the configuration for each client, taken from the Modelflare documentation.</p>
46
+ <p>Note the base URL difference. <code>ANTHROPIC_BASE_URL</code> is <code>https://modelflare.dev</code> without <code>/v1</code>, because Claude Code appends the Messages path itself. OpenAI-style clients use <code>https://modelflare.dev/v1</code>.</p>
47
+ <h2>API key</h2>
48
+ <p>In the <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">console</a>, create an API key in a non-default group that can access the model the agent will use. The guides below use <code>claude-opus-4-8</code> and <code>claude-sonnet-5</code> for Claude Code, <code>gpt-5.6-sol</code> for Codex and OpenCode, and <code>grok-4.5</code> for Grok Build. A Smart API Key is an alternative: it resolves a routing group on each request across every model the account can use, so no group needs to be chosen.</p>
49
+ <h2>Claude Code</h2>
50
+ <p>The installer installs the official CLI when needed, asks for the key once, backs up and merges existing user settings, and verifies both configured models:</p>
51
+ <pre><code class="language-bash">curl -fsSL https://modelflare.dev/install/claude.sh | sh
52
+ # Windows PowerShell: irm https://modelflare.dev/install/claude.ps1 | iex
53
+ </code></pre>
54
+ <p>For a manual setup, write the following to <code>~/.claude/settings.json</code>:</p>
55
+ <pre><code class="language-json">{
56
+ &quot;env&quot;: {
57
+ &quot;ANTHROPIC_BASE_URL&quot;: &quot;https://modelflare.dev&quot;,
58
+ &quot;ANTHROPIC_AUTH_TOKEN&quot;: &quot;YOUR_MODELFLARE_API_KEY&quot;,
59
+ &quot;ANTHROPIC_MODEL&quot;: &quot;claude-opus-4-8&quot;,
60
+ &quot;ANTHROPIC_DEFAULT_OPUS_MODEL&quot;: &quot;claude-opus-4-8&quot;,
61
+ &quot;ANTHROPIC_DEFAULT_SONNET_MODEL&quot;: &quot;claude-sonnet-5&quot;,
62
+ &quot;ANTHROPIC_DEFAULT_HAIKU_MODEL&quot;: &quot;claude-sonnet-5&quot;
63
+ }
64
+ }
65
+ </code></pre>
66
+ <p>Restrict the file with <code>chmod 600 ~/.claude/settings.json</code>, start <code>claude</code> in a trusted project directory, and send "Reply with one sentence confirming the active model." A normal reply confirms the setup.</p>
67
+ <h2>Codex</h2>
68
+ <p>The installer is <code>curl -fsSL https://modelflare.dev/install/codex.sh | sh</code>. For a manual setup, create <code>~/.codex/config.toml</code>:</p>
69
+ <pre><code class="language-toml">cli_auth_credentials_store = &quot;file&quot;
70
+ model_provider = &quot;modelflare&quot;
71
+ model = &quot;gpt-5.6-sol&quot;
72
+ model_reasoning_effort = &quot;xhigh&quot;
73
+ disable_response_storage = true
74
+ model_supports_reasoning_summaries = true
75
+
76
+ [model_providers.modelflare]
77
+ name = &quot;Modelflare&quot;
78
+ base_url = &quot;https://modelflare.dev/v1&quot;
79
+ wire_api = &quot;responses&quot;
80
+ requires_openai_auth = true
81
+ </code></pre>
82
+ <p>and <code>~/.codex/auth.json</code>:</p>
83
+ <pre><code class="language-json">{
84
+ &quot;auth_mode&quot;: &quot;apikey&quot;,
85
+ &quot;OPENAI_API_KEY&quot;: &quot;YOUR_MODELFLARE_API_KEY&quot;
86
+ }
87
+ </code></pre>
88
+ <p>Keep both files private (<code>chmod 600 config.toml auth.json</code> on macOS and Linux). Do not add a provider <code>auth</code> command block; current Codex releases require <code>requires_openai_auth = true</code> for this API-key path.</p>
89
+ <p>Run <code>codex --model gpt-5.6-sol</code> and send "Reply with one sentence confirming the active model and provider." If a ChatGPT login screen appears, quit every Codex session and reopen the CLI. A <code>model_not_found</code> error means the key's group cannot serve <code>gpt-5.6-sol</code>.</p>
90
+ <h2>OpenCode</h2>
91
+ <p>Add <code>opencode.json</code> to the project directory:</p>
92
+ <pre><code class="language-json">{
93
+ &quot;$schema&quot;: &quot;https://opencode.ai/config.json&quot;,
94
+ &quot;model&quot;: &quot;modelflare/gpt-5.6-sol&quot;,
95
+ &quot;provider&quot;: {
96
+ &quot;modelflare&quot;: {
97
+ &quot;npm&quot;: &quot;@ai-sdk/openai-compatible&quot;,
98
+ &quot;name&quot;: &quot;Modelflare&quot;,
99
+ &quot;options&quot;: { &quot;baseURL&quot;: &quot;https://modelflare.dev/v1&quot; },
100
+ &quot;models&quot;: { &quot;gpt-5.6-sol&quot;: { &quot;name&quot;: &quot;GPT 5.6 Sol&quot; } }
101
+ }
102
+ }
103
+ }
104
+ </code></pre>
105
+ <p>Start <code>opencode</code>, enter <code>/connect</code>, choose Other, set the provider id to <code>modelflare</code>, and paste the key. Select the model with <code>/models</code>.</p>
106
+ <h2>Gemini CLI</h2>
107
+ <pre><code class="language-bash">npm install -g @google/gemini-cli@latest
108
+ export GEMINI_API_KEY=&quot;YOUR_MODELFLARE_API_KEY&quot;
109
+ export GOOGLE_GEMINI_BASE_URL=&quot;https://modelflare.dev&quot;
110
+ gemini --model YOUR_MODEL_ID # use an ID from the Modelflare catalog
111
+ </code></pre>
112
+ <p>If the CLI prompts for an authentication method, choose Use Gemini API key.</p>
113
+ <h2>CC-Switch</h2>
114
+ <p>CC-Switch stores Codex, OpenAI-compatible, and Claude Code profiles and switches between them without manual file edits. On the Modelflare API Keys page, open a key's action menu, select Import to CC Switch, choose Claude Code or Codex, and confirm the primary model. Then enable the imported provider in CC-Switch; the import does not switch the active provider automatically. To add the provider manually, create a Universal Provider with the Custom Gateway preset and set the API URL to <code>https://modelflare.dev</code>. The import link contains the API key, so use it only on a trusted device.</p>
115
+ <h2>Grok Build</h2>
116
+ <p>Grok Build uses the Responses API. Its guide uses a key that can access <code>grok-4.5</code>, the key in the <code>MODELFLARE_API_KEY</code> environment variable, and this <code>~/.grok/config.toml</code>:</p>
117
+ <pre><code class="language-toml">[models]
118
+ default = &quot;modelflare-grok&quot;
119
+
120
+ [model.modelflare-grok]
121
+ model = &quot;grok-4.5&quot;
122
+ base_url = &quot;https://modelflare.dev/v1&quot;
123
+ name = &quot;Modelflare Grok 4.5&quot;
124
+ env_key = &quot;MODELFLARE_API_KEY&quot;
125
+ api_backend = &quot;responses&quot;
126
+ </code></pre>
127
+ <p>Test the connection with <code>grok -p "Reply only: Modelflare connected" -m modelflare-grok</code>.</p>
128
+ <p>Other tools that accept an OpenAI-compatible base URL can be pointed at <code>https://modelflare.dev/v1</code>.</p>
129
+ <h2>Image and video generation from an agent</h2>
130
+ <p>The Modelflare Media Skill is an installable <code>SKILL.md</code> package for Claude Code, Codex, and other agents that read skills. With it, an agent can select an image or video model, quote the price, submit the request, wait for video tasks, and save the result. To install it, send the agent: "Install this skill: https://modelflare.dev/skills/modelflare-media/modelflare-media.zip (or use the attached zip), then read its SKILL.md. If you do not support skills, extract it anywhere and follow SKILL.md. My key is in the environment variable MODELFLARE_API_KEY." The skill reads the live catalog and each model's documentation page at call time and requires Node.js 18 or newer. See the <a href="https://docs.modelflare.dev/guides/clients/media-skill/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">Media Skill guide</a>.</p>
131
+ <h2>References</h2>
132
+ <p>The <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">Modelflare/coding-agents</a> Space collects these setups. Related Spaces are <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">Modelflare/openai-sdk</a>, <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">Modelflare/api-recipes</a>, and <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">Modelflare/start</a>. Full client guides: <a href="https://docs.modelflare.dev/guides/clients/claude-code/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">Claude Code</a>, <a href="https://docs.modelflare.dev/guides/clients/codex/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">Codex</a>, <a href="https://docs.modelflare.dev/guides/clients/gemini-cli/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=coding-agents-modelflare">Gemini CLI</a>. For team or enterprise arrangements, contact <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>.</p>
133
+ <hr />
134
+ <p><strong>中文摘要:</strong> 同一个 Modelflare API key 可用于多种编码工具。Claude Code 使用 Anthropic 协议,<code>ANTHROPIC_BASE_URL</code> 设为 <code>https://modelflare.dev</code>(不带 /v1);Codex、Grok Build(Responses 协议)和 OpenCode 使用 <code>https://modelflare.dev/v1</code>;Gemini CLI 通过 <code>GOOGLE_GEMINI_BASE_URL</code> 配置。CC-Switch 支持从 API Keys 页面直接导入配置。本文所列配置均与官方文档一致。此外,安装 Media Skill 后,agent 可以直接调用图片和视频模型。</p></article><p><a href="index.html">&larr; All articles</a></p>
135
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
136
+ </html>
index.html CHANGED
@@ -1,19 +1,44 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Modelflare Blog | Modelflare Blog</title>
7
+ <meta name="description" content="Engineering notes and setup guides for Modelflare and Castaly."><meta property="og:image" content="images/cover.jpg">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <h1>Modelflare Blog</h1><p class="lead">Engineering notes and setup guides for Modelflare, the API gateway for text, image, and video models, and for Castaly, the studio built on it.</p><div class="list"><a class="card" href="introducing-modelflare.html"><div><h2>Introducing Modelflare: one API key for text, image, and video models</h2><p>Modelflare is an API gateway that serves text, image, and video models behind one key, with OpenAI-compatible, Anthropic, and Gemini endpoints and per-request cost records.</p></div></a><a class="card" href="openai-sdk-one-line.html"><div><h2>Switching the OpenAI SDK to Modelflare (Python, JavaScript, curl)</h2><p>Existing OpenAI SDK code works with Modelflare after changing the base URL to <code>https://modelflare.dev/v1</code> and supplying a Modelflare key.</p></div></a><a class="card" href="coding-agents-modelflare.html"><div><h2>Configuring coding agents with Modelflare: Claude Code, Codex, OpenCode, Gemini CLI, CC-Switch, and Grok Build</h2><p>Claude Code connects through Anthropic Messages at <code>https://modelflare.dev</code>, Codex, OpenCode, and Grok Build through <code>https://modelflare.dev/v1</code>, and Gemini CLI through <code>GOOGLE_GEMINI_BASE_URL</code>. All of them use the same Modelflare key.</p></div></a><a class="card" href="api-recipes-streaming-fallback.html"><div><h2>Modelflare API recipes: streaming, routing fallback, images, and async video</h2><p>Request examples for streaming chat, gateway-side fallback with group failover and Smart API Keys, client-side model fallback, image generation, and the asynchronous video task flow.</p></div></a><a class="card" href="castaly-image-video-studio.html"><img src="images/cover.jpg" alt="Castaly cover: orbital ring city"><div><h2>Castaly: an AI video and image studio built on Modelflare</h2><p>Castaly is a browser studio for AI image and video generation. Models are compared by specification and price, generations are paid from a wallet shared with Modelflare, and every model is also available through the Modelflare API.</p></div></a></div>
43
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
44
  </html>
introducing-modelflare.html ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Introducing Modelflare: one API key for text, image, and video models | Modelflare Blog</title>
7
+ <meta name="description" content="Modelflare is an API gateway that serves text, image, and video models behind one key, with OpenAI-compatible, Anthropic, and Gemini endpoints and per-request cost records.">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <article><h1>Introducing Modelflare: one API key for text, image, and video models</h1>
43
+ <p class="lead">Modelflare is an API gateway that serves text, image, and video models behind one key, with OpenAI-compatible, Anthropic, and Gemini endpoints and per-request cost records.</p>
44
+ <hr />
45
+ <p><a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=introducing-modelflare">Modelflare</a> is a unified API gateway for text, image, and video models. One API key covers OpenAI-compatible chat, the Responses API, Anthropic Messages, image generation, and asynchronous video. Usage and cost are recorded for every request. This post covers the endpoints, how keys and routing groups work, and how to send a first request.</p>
46
+ <h2>What the gateway provides</h2>
47
+ <p>Chat Completions, Responses, Anthropic Messages, Images, and Video share the same authentication and routing groups. Applications built on the OpenAI SDK change the base URL to <code>https://modelflare.dev/v1</code> and keep the rest of their code. Image and video families that have their own request formats, such as GPT Images, Gemini native image, and the async video models, keep their native fields; the <a href="https://docs.modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=introducing-modelflare">documentation</a> describes each contract separately instead of mapping them onto a single schema.</p>
48
+ <p>The catalog lists 14 image models (GPT Images, Gemini Image, Wan, Seedream) and 28 video models (Seedance, Wan, Kling, MiniMax, HappyHorse). Text models from GPT, Claude, Grok, and others are served over the OpenAI-compatible and Anthropic contracts.</p>
49
+ <h2>Endpoints</h2>
50
+ <table>
51
+ <thead>
52
+ <tr>
53
+ <th>Family</th>
54
+ <th>Endpoint</th>
55
+ <th>Typical use</th>
56
+ </tr>
57
+ </thead>
58
+ <tbody>
59
+ <tr>
60
+ <td>Chat Completions</td>
61
+ <td><code>POST /v1/chat/completions</code></td>
62
+ <td>OpenAI-compatible chat</td>
63
+ </tr>
64
+ <tr>
65
+ <td>Responses</td>
66
+ <td><code>POST /v1/responses</code></td>
67
+ <td>Codex, Grok Build</td>
68
+ </tr>
69
+ <tr>
70
+ <td>Anthropic Messages</td>
71
+ <td><code>ANTHROPIC_BASE_URL=https://modelflare.dev</code></td>
72
+ <td>Claude Code</td>
73
+ </tr>
74
+ <tr>
75
+ <td>Images</td>
76
+ <td><code>POST /v1/images/generations</code></td>
77
+ <td>GPT Images, Wan Image, Seedream</td>
78
+ </tr>
79
+ <tr>
80
+ <td>Gemini native</td>
81
+ <td><code>POST /v1/models/{model}:generateContent</code></td>
82
+ <td>Gemini image models (Gemini CLI builds the same path under <code>/v1beta</code>, served only on <code>modelflare.dev</code>)</td>
83
+ </tr>
84
+ <tr>
85
+ <td>Video</td>
86
+ <td><code>POST /v1/videos</code>, poll <code>GET /v1/videos/{task_id}</code>, download <code>GET /v1/videos/{task_id}/content</code></td>
87
+ <td>Seedance, Wan, Kling, MiniMax, HappyHorse</td>
88
+ </tr>
89
+ <tr>
90
+ <td>Models</td>
91
+ <td><code>GET /v1/models</code></td>
92
+ <td>Models your key can call</td>
93
+ </tr>
94
+ </tbody>
95
+ </table>
96
+ <p>The base URL is <code>https://modelflare.dev/v1</code>. Anthropic clients use the site origin, <code>https://modelflare.dev</code>, without <code>/v1</code>, because the Claude Code CLI appends the Messages path itself. Gemini CLI reads <code>GOOGLE_GEMINI_BASE_URL=https://modelflare.dev</code>. China-facing EdgeOne traffic can use <code>https://origin.modelflare.dev/v1</code>. Choose the host before sending a request; an in-flight POST should not be redirected between hosts.</p>
97
+ <h2>First request</h2>
98
+ <p>Every request carries <code>Authorization: Bearer YOUR_MODELFLARE_API_KEY</code>.</p>
99
+ <pre><code class="language-bash">curl https://modelflare.dev/v1/chat/completions \
100
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
101
+ -H &quot;Content-Type: application/json&quot; \
102
+ -d '{&quot;model&quot;: &quot;gpt-5.6-sol&quot;, &quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Hello&quot;}]}'
103
+ </code></pre>
104
+ <p>Replace <code>gpt-5.6-sol</code> with any model your key can access. To list the models available to a key:</p>
105
+ <pre><code class="language-bash">curl https://modelflare.dev/v1/models -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot;
106
+ </code></pre>
107
+ <h2>Models and routing groups</h2>
108
+ <p>Two identifiers decide whether a request succeeds. The model ID in the JSON body must match a public catalog ID exactly, without marketing names or date suffixes. The routing group bound to the key decides which provider channels can serve that model. Create the key in a non-default group that lists the model; if the group has no channel for it, the request fails even when the JSON is valid.</p>
109
+ <p>A Smart API Key removes the fixed group. It resolves a routing group on every request across all models the account can use, ordered by a routing strategy.</p>
110
+ <h2>Pricing</h2>
111
+ <p>Live prices, groups, and availability are published on <a href="https://modelflare.dev/pricing?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=introducing-modelflare">Models &amp; Pricing</a>; the documentation does not keep a second price list. Language models are billed per million tokens with separate input and output rates. Image and video models are billed in the unit named on each model page: per token, per image, per call, or per second.</p>
112
+ <h2>Resources on Hugging Face</h2>
113
+ <p>The <a href="https://huggingface.co/Modelflare" target="_top">Modelflare organization</a> hosts a landing Space, <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">Modelflare/start</a>; an SDK guide, <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">Modelflare/openai-sdk</a>; setup notes for coding agents, <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">Modelflare/coding-agents</a>; request recipes, <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">Modelflare/api-recipes</a>; and a dataset of example requests, <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">Modelflare/api-examples</a>.</p>
114
+ <p>Keys are created in the <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=introducing-modelflare">Modelflare console</a>. Do not place a real key in a public Space or notebook. For business and enterprise inquiries, contact <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>.</p>
115
+ <hr />
116
+ <p><strong>中文摘要:</strong> Modelflare 是面向文本、图片和视频模型的统一 API 网关,一个 API key 即可调用 OpenAI 兼容接口、Responses、Anthropic Messages、图片生成和异步视频,并按请求记录用量与费用。OpenAI 兼容入口为 <code>https://modelflare.dev/v1</code>;Anthropic 客户端使用 <code>https://modelflare.dev</code>(不带 /v1);Gemini CLI 通过 <code>GOOGLE_GEMINI_BASE_URL</code> 配置。目前目录收录 14 个图片模型和 28 个视频模型,实时价格以 Models &amp; Pricing 页面为准。商务合作请联系 business@modelflare.dev。</p></article><p><a href="index.html">&larr; All articles</a></p>
117
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
118
+ </html>
openai-sdk-one-line.html ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Switching the OpenAI SDK to Modelflare (Python, JavaScript, curl) | Modelflare Blog</title>
7
+ <meta name="description" content="Existing OpenAI SDK code works with Modelflare after changing the base URL to `https://modelflare.dev/v1` and supplying a Modelflare key.">
8
+ <style>
9
+ :root{--bg:#0b1020;--card:#121a2f;--text:#e8ecf7;--muted:#9aa6c2;--accent:#8b5cf6;--accent2:#ec4899;--border:rgba(255,255,255,.08)}
10
+ *{box-sizing:border-box}
11
+ body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1200px 600px at 10% -10%,#2a1850 0%,transparent 50%),radial-gradient(900px 500px at 100% 0%,#3b0f2e 0%,transparent 45%),var(--bg);color:var(--text);min-height:100vh;line-height:1.65}
12
+ .wrap{max-width:860px;margin:0 auto;padding:28px 18px 64px}
13
+ header.top{display:flex;flex-wrap:wrap;gap:14px;align-items:center;justify-content:space-between;margin-bottom:28px;font-size:14px}
14
+ header.top a{color:var(--muted);text-decoration:none}header.top a:hover{color:#fff}
15
+ header.top .brand{color:#fff;font-weight:700;font-size:16px}
16
+ header.top nav{display:flex;flex-wrap:wrap;gap:14px}
17
+ h1{font-size:clamp(26px,4.6vw,38px);line-height:1.2;margin:0 0 12px}
18
+ h2{font-size:22px;margin:36px 0 10px}h3{font-size:17px;margin:24px 0 8px;color:#d6c7ff}
19
+ p,li{color:#cfd6e8}a{color:#c4b5fd}
20
+ .lead{color:var(--muted);font-size:17px}
21
+ article img{max-width:100%;height:auto;border-radius:12px;border:1px solid var(--border);display:block;margin:18px auto 6px}
22
+ article p em:only-child{display:block;text-align:center;color:var(--muted);font-size:14px}
23
+ pre{background:#070b16;border:1px solid var(--border);border-radius:12px;padding:0;overflow-x:auto}
24
+ pre code.hljs{background:transparent;padding:14px 16px;font-size:13.5px;line-height:1.55}
25
+ code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em}
26
+ p code,li code,td code{background:rgba(139,92,246,.14);padding:1px 5px;border-radius:5px}
27
+ table{border-collapse:collapse;width:100%;font-size:14px;margin:14px 0;display:block;overflow-x:auto}
28
+ th,td{border:1px solid var(--border);padding:8px 10px;text-align:left;vertical-align:top}th{background:var(--card)}
29
+ hr{border:0;border-top:1px solid var(--border);margin:32px 0}
30
+ .list{display:grid;gap:14px}
31
+ .card{display:flex;gap:16px;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:18px;text-decoration:none;color:inherit}
32
+ .card:hover{border-color:rgba(139,92,246,.5)}
33
+ .card img{width:200px;height:105px;object-fit:cover;border-radius:10px;flex-shrink:0}
34
+ .card h2{font-size:18px;margin:0 0 6px;color:#fff}.card p{margin:0;color:var(--muted);font-size:14px}
35
+ footer{margin-top:48px;padding-top:18px;border-top:1px solid var(--border);color:var(--muted);font-size:13px}
36
+ footer a{color:var(--muted)}
37
+ @media(max-width:600px){.card{flex-direction:column}.card img{width:100%;height:auto;aspect-ratio:1200/630}}
38
+ </style>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/styles/github-dark.min.css"><script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script><script>document.addEventListener("DOMContentLoaded",()=>hljs.highlightAll());</script>
40
+ </head>
41
+ <body><div class="wrap"><header class="top"><a class="brand" href="index.html">Modelflare Blog</a><nav><a href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">modelflare.dev</a><a href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Docs</a><a href="https://castaly.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=blog">Castaly</a><a href="https://huggingface.co/Modelflare" target="_top">Hugging Face org</a></nav></header>
42
+ <article><h1>Switching the OpenAI SDK to Modelflare (Python, JavaScript, curl)</h1>
43
+ <p class="lead">Existing OpenAI SDK code works with Modelflare after changing the base URL to <code>https://modelflare.dev/v1</code> and supplying a Modelflare key.</p>
44
+ <hr />
45
+ <p><a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=openai-sdk-one-line">Modelflare</a>'s Chat Completions endpoint is compatible with the official OpenAI SDKs. Switching an application requires two changes: the base URL and the API key. This guide shows both for Python, JavaScript, and curl, and lists the errors you are most likely to see.</p>
46
+ <h2>Create a key</h2>
47
+ <p>In the <a href="https://modelflare.dev/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=openai-sdk-one-line">Modelflare console</a>, open API Keys and create a key in a non-default group that lists the model you plan to call. No single group is required.</p>
48
+ <h2>Set the base URL</h2>
49
+ <h3>Python</h3>
50
+ <pre><code class="language-python">from openai import OpenAI
51
+
52
+ client = OpenAI(
53
+ api_key=&quot;YOUR_MODELFLARE_API_KEY&quot;,
54
+ base_url=&quot;https://modelflare.dev/v1&quot;, # &lt;- the one-line change
55
+ )
56
+
57
+ response = client.chat.completions.create(
58
+ model=&quot;gpt-5.6-sol&quot;,
59
+ messages=[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Hello&quot;}],
60
+ )
61
+ print(response.choices[0].message.content)
62
+ </code></pre>
63
+ <h3>JavaScript (Node.js)</h3>
64
+ <pre><code class="language-javascript">import OpenAI from &quot;openai&quot;;
65
+
66
+ const client = new OpenAI({
67
+ apiKey: &quot;YOUR_MODELFLARE_API_KEY&quot;,
68
+ baseURL: &quot;https://modelflare.dev/v1&quot;, // &lt;- the one-line change
69
+ });
70
+
71
+ const response = await client.chat.completions.create({
72
+ model: &quot;gpt-5.6-sol&quot;,
73
+ messages: [{ role: &quot;user&quot;, content: &quot;Hello&quot; }],
74
+ });
75
+ console.log(response.choices[0].message.content);
76
+ </code></pre>
77
+ <h3>curl</h3>
78
+ <pre><code class="language-bash">curl https://modelflare.dev/v1/chat/completions \
79
+ -H &quot;Authorization: Bearer YOUR_MODELFLARE_API_KEY&quot; \
80
+ -H &quot;Content-Type: application/json&quot; \
81
+ -d '{
82
+ &quot;model&quot;: &quot;gpt-5.6-sol&quot;,
83
+ &quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Hello&quot;}]
84
+ }'
85
+ </code></pre>
86
+ <p>The examples use <code>gpt-5.6-sol</code>, the model from the Modelflare quickstart. Any model ID available to the key's group can be used instead.</p>
87
+ <h2>Keep the key out of your code</h2>
88
+ <p>Do not embed the key in a browser bundle, mobile app, or public repository. Load it from a secret store or the process environment.</p>
89
+ <h2>Find a model ID</h2>
90
+ <p>The models endpoint returns the IDs the current key can call:</p>
91
+ <pre><code class="language-python">for m in client.models.list():
92
+ print(m.id)
93
+ </code></pre>
94
+ <p>The response is not a price list. Prices, groups, and protocol labels are on <a href="https://modelflare.dev/pricing?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=openai-sdk-one-line">Models &amp; Pricing</a>. Use the exact ID shown there, not a provider marketing name, a date suffix, or a nearby variant.</p>
95
+ <h2>Common errors</h2>
96
+ <p>A <code>401</code> means the key is missing, malformed, or revoked; recopy it and confirm it has not been deleted or disabled. A <code>403</code> means the key is valid but the selected model or group is not allowed. A request with valid JSON that still fails with <code>model_not_found</code> usually means the key's group has no channel for that model; edit the key and choose a group that lists it. Image and video requests sent to the wrong endpoint family return <code>400</code> with <code>unsupported_endpoint</code>; image and video models use <code>/v1/images/generations</code> and <code>/v1/videos</code>, as described in the <a href="https://docs.modelflare.dev/guides/endpoints/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=openai-sdk-one-line">endpoint guide</a>.</p>
97
+ <h2>Hosts</h2>
98
+ <p>The default host is <code>https://modelflare.dev/v1</code>. China-facing EdgeOne traffic can use <code>https://origin.modelflare.dev/v1</code>. Choose the host before sending a request, and do not redirect an in-flight POST from one host to the other.</p>
99
+ <h2>Other endpoints on the same key</h2>
100
+ <p>The same key works with the Responses API (<code>POST /v1/responses</code>, used by Codex), Anthropic Messages (used by Claude Code), image generation, and asynchronous video. The <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">Modelflare/openai-sdk</a> Space contains this guide in English and Chinese. <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">Modelflare/api-recipes</a> and the <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">Modelflare/api-examples</a> dataset cover the other endpoints, and <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">Modelflare/start</a> links to everything else. For business inquiries, contact <a href="mailto:business@modelflare.dev">business@modelflare.dev</a>. The full reference is at <a href="https://docs.modelflare.dev/quickstart/?utm_source=huggingface&amp;utm_medium=space&amp;utm_campaign=openai-sdk-one-line">docs.modelflare.dev</a>.</p>
101
+ <hr />
102
+ <p><strong>中文摘要:</strong> 已接入 OpenAI SDK 的应用,将 <code>base_url</code> 改为 <code>https://modelflare.dev/v1</code> 并换用 Modelflare API key 即可,其余代码无需改动。本文提供 Python、JavaScript 和 curl 示例,说明如何通过 <code>models.list()</code> 查询可用模型 ID,并列出 401、403、<code>model_not_found</code> 和 <code>unsupported_endpoint</code> 等常见错误。API key 所在分组须开通目标模型;面向中国大陆的 EdgeOne 流量可使用 <code>origin.modelflare.dev/v1</code>。商务合作请联系 business@modelflare.dev。</p></article><p><a href="index.html">&larr; All articles</a></p>
103
+ <footer>Modelflare on Hugging Face: <a href="https://huggingface.co/spaces/Modelflare/start" target="_top">start</a> · <a href="https://huggingface.co/spaces/Modelflare/openai-sdk" target="_top">openai-sdk</a> · <a href="https://huggingface.co/spaces/Modelflare/coding-agents" target="_top">coding-agents</a> · <a href="https://huggingface.co/spaces/Modelflare/api-recipes" target="_top">api-recipes</a> · <a href="https://huggingface.co/datasets/Modelflare/api-examples" target="_top">api-examples dataset</a><br>Business: <a href="mailto:business@modelflare.dev">business@modelflare.dev</a></footer></div></body>
104
+ </html>