modelflaredev commited on
Commit
80e33f1
·
verified ·
1 Parent(s): b7c9e47

Update openai-sdk README.md and index.html

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +68 -28
README.md CHANGED
@@ -4,13 +4,15 @@ emoji: 🔌
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: static
7
- pinned: false
8
  license: mit
9
- short_description: Switch base_url to Modelflare — one-line OpenAI SDK setup
10
  ---
11
 
12
  # OpenAI SDK → Modelflare (one-line switch)
13
 
14
- Point any OpenAI-compatible client at Modelflare. Create a key at [modelflare.dev](https://modelflare.dev/), then set `base_url` to `https://modelflare.dev/v1`.
15
 
16
- Full docs: [docs.modelflare.dev](https://docs.modelflare.dev/) · Hub landing: [Modelflare/start](https://huggingface.co/spaces/Modelflare/start)
 
 
 
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: static
7
+ pinned: true
8
  license: mit
9
+ short_description: One-line OpenAI SDK switch — bilingual guide
10
  ---
11
 
12
  # OpenAI SDK → Modelflare (one-line switch)
13
 
14
+ Point any OpenAI-compatible client at Modelflare. Create a key at [modelflare.dev](https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide), then set `base_url` to `https://modelflare.dev/v1`.
15
 
16
+ - Full docs: [docs.modelflare.dev](https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide)
17
+ - Hub landing: [Modelflare/start](https://huggingface.co/spaces/Modelflare/start)
18
+ - Collection: [Getting Started](https://huggingface.co/collections/Modelflare/modelflare-getting-started)
index.html CHANGED
@@ -4,10 +4,11 @@
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
  <title>OpenAI SDK → Modelflare</title>
 
7
  <style>
8
  :root {
9
  --bg:#0b1020; --card:#121a2f; --text:#e8ecf7; --muted:#9aa6c2;
10
- --accent:#8b5cf6; --accent2:#ec4899; --border:rgba(255,255,255,.08); --ok:#34d399;
11
  }
12
  *{box-sizing:border-box}
13
  body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1000px 500px at 0% 0%,#2a1850 0%,transparent 50%),var(--bg);color:var(--text);line-height:1.55}
@@ -22,14 +23,16 @@
22
  a.primary{background:linear-gradient(135deg,var(--accent),var(--accent2));color:#fff}
23
  a.ghost{border:1px solid var(--border);color:var(--text)}
24
  h2{font-size:18px;margin:28px 0 10px}
25
- ol{color:var(--muted);padding-left:1.2em}
26
- ol li{margin:6px 0}
27
  pre{background:#070b16;border:1px solid var(--border);border-radius:14px;padding:14px 16px;overflow:auto;font-size:12.5px;color:#d7def0;position:relative}
28
  .copy{position:absolute;top:8px;right:8px;font-size:11px;border:1px solid var(--border);background:#121a2f;color:var(--muted);border-radius:8px;padding:4px 8px;cursor:pointer}
29
  .note{background:var(--card);border:1px solid var(--border);border-radius:14px;padding:14px 16px;color:var(--muted);font-size:14px;margin-top:16px}
30
  .note strong{color:var(--ok)}
 
31
  code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
32
  .hidden{display:none}
 
33
  </style>
34
  </head>
35
  <body>
@@ -44,8 +47,9 @@
44
  <p class="lead">从 Hugging Face 过来?先拿 key,再改 <code>base_url</code>。文本 / 图片 / 视频同一把钥匙,带分组故障转移与用量成本记录。</p>
45
  <div class="cta">
46
  <a class="btn primary" href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">打开控制台领取 API Key</a>
47
- <a class="btn ghost" href="https://docs.modelflare.dev/" target="_blank" rel="noopener">完整文档</a>
48
  <a class="btn ghost" href="https://huggingface.co/collections/Modelflare/modelflare-getting-started" target="_blank" rel="noopener">Getting Started 合集</a>
 
49
  </div>
50
  <h2>三步接入</h2>
51
  <ol>
@@ -53,11 +57,16 @@
53
  <li>把 OpenAI 客户端的 <code>base_url</code> 改成 <code>https://modelflare.dev/v1</code>。</li>
54
  <li>模型名用你分组里实际开通的 id(例如 Grok 分组用 <code>grok-4.7</code>)。</li>
55
  </ol>
 
 
 
 
56
  <h2>Python</h2>
57
- <pre><button class="copy" type="button">复制</button><code>from openai import OpenAI
 
58
 
59
  client = OpenAI(
60
- api_key="YOUR_MODELFLARE_KEY",
61
  base_url="https://modelflare.dev/v1",
62
  )
63
 
@@ -66,6 +75,15 @@ r = client.chat.completions.create(
66
  messages=[{"role": "user", "content": "Hello from Hugging Face"}],
67
  )
68
  print(r.choices[0].message.content)</code></pre>
 
 
 
 
 
 
 
 
 
69
  <h2>Node.js / TypeScript</h2>
70
  <pre><button class="copy" type="button">复制</button><code>import OpenAI from "openai";
71
 
@@ -84,9 +102,15 @@ console.log(r.choices[0].message.content);</code></pre>
84
  -H "Authorization: Bearer $MODELFLARE_API_KEY" \
85
  -H "Content-Type: application/json" \
86
  -d '{"model":"grok-4.7","messages":[{"role":"user","content":"ping"}]}'</code></pre>
 
 
 
 
 
 
 
87
  <div class="note">
88
  <strong>从 Hub 来的访客:</strong>注册后即可在控制台看价、开 key、看用量。
89
- Coding agents(Codex / Claude Code 等)配置见文档站。
90
  可互动 Chat Demo 需 Hugging Face PRO 后上线;现在请用控制台与 API 试用。
91
  </div>
92
  </section>
@@ -96,8 +120,9 @@ console.log(r.choices[0].message.content);</code></pre>
96
  <p class="lead">Coming from Hugging Face? Get a key, then set <code>base_url</code>. One key for text, image, and video — with group failover and per-request cost tracking.</p>
97
  <div class="cta">
98
  <a class="btn primary" href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">Open Console → Get API Key</a>
99
- <a class="btn ghost" href="https://docs.modelflare.dev/" target="_blank" rel="noopener">Docs</a>
100
  <a class="btn ghost" href="https://huggingface.co/collections/Modelflare/modelflare-getting-started" target="_blank" rel="noopener">Getting Started collection</a>
 
101
  </div>
102
  <h2>Three steps</h2>
103
  <ol>
@@ -105,11 +130,16 @@ console.log(r.choices[0].message.content);</code></pre>
105
  <li>Point your OpenAI client at <code>https://modelflare.dev/v1</code>.</li>
106
  <li>Use a model id enabled on your group (e.g. <code>grok-4.7</code> on a Grok group).</li>
107
  </ol>
 
 
 
 
108
  <h2>Python</h2>
109
- <pre><button class="copy" type="button">Copy</button><code>from openai import OpenAI
 
110
 
111
  client = OpenAI(
112
- api_key="YOUR_MODELFLARE_KEY",
113
  base_url="https://modelflare.dev/v1",
114
  )
115
 
@@ -118,6 +148,15 @@ r = client.chat.completions.create(
118
  messages=[{"role": "user", "content": "Hello from Hugging Face"}],
119
  )
120
  print(r.choices[0].message.content)</code></pre>
 
 
 
 
 
 
 
 
 
121
  <h2>Node.js / TypeScript</h2>
122
  <pre><button class="copy" type="button">Copy</button><code>import OpenAI from "openai";
123
 
@@ -136,33 +175,34 @@ console.log(r.choices[0].message.content);</code></pre>
136
  -H "Authorization: Bearer $MODELFLARE_API_KEY" \
137
  -H "Content-Type: application/json" \
138
  -d '{"model":"grok-4.7","messages":[{"role":"user","content":"ping"}]}'</code></pre>
 
 
 
 
 
 
 
139
  <div class="note">
140
  <strong>HF visitors:</strong> sign up on the console for pricing, keys, and usage.
141
- Coding-agent setups live in the docs. Interactive Chat Spaces need HF PRO; use the console + API for now.
142
  </div>
143
  </section>
144
  </div>
145
  <script>
146
- const zh = document.getElementById('zh');
147
- const en = document.getElementById('en');
148
- document.querySelectorAll('.lang button').forEach(btn => {
149
- btn.addEventListener('click', () => {
150
- document.querySelectorAll('.lang button').forEach(b => b.classList.remove('on'));
151
  btn.classList.add('on');
152
- const l = btn.dataset.lang;
153
- zh.classList.toggle('hidden', l !== 'zh');
154
- en.classList.toggle('hidden', l !== 'en');
155
  });
156
  });
157
- document.querySelectorAll('pre .copy').forEach(btn => {
158
- btn.addEventListener('click', async () => {
159
- const code = btn.parentElement.querySelector('code').innerText;
160
- try {
161
- await navigator.clipboard.writeText(code);
162
- const t = btn.textContent;
163
- btn.textContent = btn.textContent.includes('Copy') ? 'Copied' : '已复制';
164
- setTimeout(() => btn.textContent = t, 1200);
165
- } catch (_) {}
166
  });
167
  });
168
  </script>
 
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
  <title>OpenAI SDK → Modelflare</title>
7
+ <meta name="description" content="One-line OpenAI SDK switch to Modelflare. Bilingual Python, Node, curl, streaming examples." />
8
  <style>
9
  :root {
10
  --bg:#0b1020; --card:#121a2f; --text:#e8ecf7; --muted:#9aa6c2;
11
+ --accent:#8b5cf6; --accent2:#ec4899; --border:rgba(255,255,255,.08); --ok:#34d399; --warn:#fbbf24;
12
  }
13
  *{box-sizing:border-box}
14
  body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1000px 500px at 0% 0%,#2a1850 0%,transparent 50%),var(--bg);color:var(--text);line-height:1.55}
 
23
  a.primary{background:linear-gradient(135deg,var(--accent),var(--accent2));color:#fff}
24
  a.ghost{border:1px solid var(--border);color:var(--text)}
25
  h2{font-size:18px;margin:28px 0 10px}
26
+ ol,ul{color:var(--muted);padding-left:1.2em}
27
+ ol li,ul li{margin:6px 0}
28
  pre{background:#070b16;border:1px solid var(--border);border-radius:14px;padding:14px 16px;overflow:auto;font-size:12.5px;color:#d7def0;position:relative}
29
  .copy{position:absolute;top:8px;right:8px;font-size:11px;border:1px solid var(--border);background:#121a2f;color:var(--muted);border-radius:8px;padding:4px 8px;cursor:pointer}
30
  .note{background:var(--card);border:1px solid var(--border);border-radius:14px;padding:14px 16px;color:var(--muted);font-size:14px;margin-top:16px}
31
  .note strong{color:var(--ok)}
32
+ .tip{border-left:3px solid var(--warn);padding-left:12px;margin:12px 0;color:var(--muted);font-size:14px}
33
  code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
34
  .hidden{display:none}
35
+ a{color:#c4b5fd}
36
  </style>
37
  </head>
38
  <body>
 
47
  <p class="lead">从 Hugging Face 过来?先拿 key,再改 <code>base_url</code>。文本 / 图片 / 视频同一把钥匙,带分组故障转移与用量成本记录。</p>
48
  <div class="cta">
49
  <a class="btn primary" href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">打开控制台领取 API Key</a>
50
+ <a class="btn ghost" href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">完整文档</a>
51
  <a class="btn ghost" href="https://huggingface.co/collections/Modelflare/modelflare-getting-started" target="_blank" rel="noopener">Getting Started 合集</a>
52
+ <a class="btn ghost" href="https://huggingface.co/spaces/Modelflare/start" target="_blank" rel="noopener">落地页</a>
53
  </div>
54
  <h2>三步接入</h2>
55
  <ol>
 
57
  <li>把 OpenAI 客户端的 <code>base_url</code> 改成 <code>https://modelflare.dev/v1</code>。</li>
58
  <li>模型名用你分组里实际开通的 id(例如 Grok 分组用 <code>grok-4.7</code>)。</li>
59
  </ol>
60
+ <div class="tip">模型 id 必须在当前 key 所属分组里已开通;否则会 404 / 无权限。价目与可用性以控制台为准。</div>
61
+ <h2>环境变量(推荐)</h2>
62
+ <pre><button class="copy" type="button">复制</button><code>export MODELFLARE_API_KEY="mf-..."
63
+ # base_url 固定为 https://modelflare.dev/v1</code></pre>
64
  <h2>Python</h2>
65
+ <pre><button class="copy" type="button">复制</button><code>import os
66
+ from openai import OpenAI
67
 
68
  client = OpenAI(
69
+ api_key=os.environ["MODELFLARE_API_KEY"],
70
  base_url="https://modelflare.dev/v1",
71
  )
72
 
 
75
  messages=[{"role": "user", "content": "Hello from Hugging Face"}],
76
  )
77
  print(r.choices[0].message.content)</code></pre>
78
+ <h2>流式输出(Python)</h2>
79
+ <pre><button class="copy" type="button">复制</button><code>stream = client.chat.completions.create(
80
+ model="grok-4.7",
81
+ messages=[{"role": "user", "content": "Say hi in one line"}],
82
+ stream=True,
83
+ )
84
+ for chunk in stream:
85
+ delta = chunk.choices[0].delta.content or ""
86
+ print(delta, end="", flush=True)</code></pre>
87
  <h2>Node.js / TypeScript</h2>
88
  <pre><button class="copy" type="button">复制</button><code>import OpenAI from "openai";
89
 
 
102
  -H "Authorization: Bearer $MODELFLARE_API_KEY" \
103
  -H "Content-Type: application/json" \
104
  -d '{"model":"grok-4.7","messages":[{"role":"user","content":"ping"}]}'</code></pre>
105
+ <h2>常见问题</h2>
106
+ <ul>
107
+ <li><strong>401</strong>:检查 key 是否完整、是否多了空格;环境变量是否生效。</li>
108
+ <li><strong>模型不可用</strong>:换到该分组已开通的模型 id,或在控制台换分组。</li>
109
+ <li><strong>图片 / 视频</strong>:同一把 key,但请求字段走原生合约,见文档站 Image / Video 章节。</li>
110
+ <li><strong>Coding agents</strong>:Codex / Claude Code / Gemini CLI 配置见文档站。</li>
111
+ </ul>
112
  <div class="note">
113
  <strong>从 Hub 来的访客:</strong>注册后即可在控制台看价、开 key、看用量。
 
114
  可互动 Chat Demo 需 Hugging Face PRO 后上线;现在请用控制台与 API 试用。
115
  </div>
116
  </section>
 
120
  <p class="lead">Coming from Hugging Face? Get a key, then set <code>base_url</code>. One key for text, image, and video — with group failover and per-request cost tracking.</p>
121
  <div class="cta">
122
  <a class="btn primary" href="https://modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">Open Console → Get API Key</a>
123
+ <a class="btn ghost" href="https://docs.modelflare.dev/?utm_source=huggingface&utm_medium=space&utm_campaign=sdk_guide" target="_blank" rel="noopener">Docs</a>
124
  <a class="btn ghost" href="https://huggingface.co/collections/Modelflare/modelflare-getting-started" target="_blank" rel="noopener">Getting Started collection</a>
125
+ <a class="btn ghost" href="https://huggingface.co/spaces/Modelflare/start" target="_blank" rel="noopener">Landing</a>
126
  </div>
127
  <h2>Three steps</h2>
128
  <ol>
 
130
  <li>Point your OpenAI client at <code>https://modelflare.dev/v1</code>.</li>
131
  <li>Use a model id enabled on your group (e.g. <code>grok-4.7</code> on a Grok group).</li>
132
  </ol>
133
+ <div class="tip">Model ids must be enabled on the key’s group — otherwise you get 404 / unauthorized. Live prices and availability live in the console.</div>
134
+ <h2>Environment variable (recommended)</h2>
135
+ <pre><button class="copy" type="button">Copy</button><code>export MODELFLARE_API_KEY="mf-..."
136
+ # base_url is always https://modelflare.dev/v1</code></pre>
137
  <h2>Python</h2>
138
+ <pre><button class="copy" type="button">Copy</button><code>import os
139
+ from openai import OpenAI
140
 
141
  client = OpenAI(
142
+ api_key=os.environ["MODELFLARE_API_KEY"],
143
  base_url="https://modelflare.dev/v1",
144
  )
145
 
 
148
  messages=[{"role": "user", "content": "Hello from Hugging Face"}],
149
  )
150
  print(r.choices[0].message.content)</code></pre>
151
+ <h2>Streaming (Python)</h2>
152
+ <pre><button class="copy" type="button">Copy</button><code>stream = client.chat.completions.create(
153
+ model="grok-4.7",
154
+ messages=[{"role": "user", "content": "Say hi in one line"}],
155
+ stream=True,
156
+ )
157
+ for chunk in stream:
158
+ delta = chunk.choices[0].delta.content or ""
159
+ print(delta, end="", flush=True)</code></pre>
160
  <h2>Node.js / TypeScript</h2>
161
  <pre><button class="copy" type="button">Copy</button><code>import OpenAI from "openai";
162
 
 
175
  -H "Authorization: Bearer $MODELFLARE_API_KEY" \
176
  -H "Content-Type: application/json" \
177
  -d '{"model":"grok-4.7","messages":[{"role":"user","content":"ping"}]}'</code></pre>
178
+ <h2>Troubleshooting</h2>
179
+ <ul>
180
+ <li><strong>401</strong>: key truncated / whitespace / env not loaded.</li>
181
+ <li><strong>Model unavailable</strong>: switch to an id enabled on that group, or change groups in the console.</li>
182
+ <li><strong>Image / video</strong>: same key, native request fields — see Image / Video docs.</li>
183
+ <li><strong>Coding agents</strong>: Codex / Claude Code / Gemini CLI setups are in the docs.</li>
184
+ </ul>
185
  <div class="note">
186
  <strong>HF visitors:</strong> sign up on the console for pricing, keys, and usage.
187
+ Interactive Chat Spaces need HF PRO; use the console + API for now.
188
  </div>
189
  </section>
190
  </div>
191
  <script>
192
+ const zh=document.getElementById('zh'), en=document.getElementById('en');
193
+ document.querySelectorAll('.lang button').forEach(btn=>{
194
+ btn.addEventListener('click',()=>{
195
+ document.querySelectorAll('.lang button').forEach(b=>b.classList.remove('on'));
 
196
  btn.classList.add('on');
197
+ const l=btn.dataset.lang;
198
+ zh.classList.toggle('hidden',l!=='zh');
199
+ en.classList.toggle('hidden',l!=='en');
200
  });
201
  });
202
+ document.querySelectorAll('pre .copy').forEach(btn=>{
203
+ btn.addEventListener('click',async()=>{
204
+ const code=btn.parentElement.querySelector('code').innerText;
205
+ try{await navigator.clipboard.writeText(code);const t=btn.textContent;btn.textContent=t.includes('Copy')?'Copied':'已复制';setTimeout(()=>btn.textContent=t,1200)}catch(_){}
 
 
 
 
 
206
  });
207
  });
208
  </script>