modelflaredev commited on
Commit
96b7a17
路
verified 路
1 Parent(s): 1c3b9c9

Add article: Function Calling: Responses API vs Chat Completions

Browse files
function-calling-responses-vs-chat-completions.html ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Function Calling: Responses API vs Chat Completions | Modelflare Blog</title>
7
+ <meta name="description" content="A wire-level comparison of function definitions, Call IDs, result messages, streaming arguments, authorization, idempotency, and route compatibility."><meta property="og:image" content="https://modelflare-blog.static.hf.space/images/function-calling-responses-vs-chat-completions-cover.jpg"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630"><meta property="og:title" content="Function Calling: Responses API vs Chat Completions"><meta property="og:description" content="A wire-level comparison of function definitions, Call IDs, result messages, streaming arguments, authorization, idempotency, and route compatibility."><meta property="og:type" content="article"><meta property="og:url" content="https://modelflare-blog.static.hf.space/function-calling-responses-vs-chat-completions.html"><meta property="og:site_name" content="Modelflare Blog"><meta property="article:published_time" content="2026-10-29"><link rel="canonical" href="https://modelflare.dev/articles/function-calling-responses-vs-chat-completions"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:title" content="Function Calling: Responses API vs Chat Completions"><meta name="twitter:description" content="A wire-level comparison of function definitions, Call IDs, result messages, streaming arguments, authorization, idempotency, and route compatibility."><meta name="twitter:image" content="https://modelflare-blog.static.hf.space/images/function-calling-responses-vs-chat-completions-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>Function Calling: Responses API vs Chat Completions</h1>
43
+ <p class="lead">A wire-level comparison of function definitions, Call IDs, result messages, streaming arguments, authorization, idempotency, and route compatibility.</p>
44
+ <img src="images/function-calling-responses-vs-chat-completions-cover.jpg" alt="Illustration: a request passing through one central module that fans out to several tool modules">
45
+ <hr />
46
+ <p>Disclosure: I work on <a href="https://modelflare.dev/?source=hf-blog">Modelflare</a>, an OpenAI-compatible AI API gateway. The canonical version of this guide lives on <a href="https://modelflare.dev/articles/function-calling-responses-vs-chat-completions?source=hf-blog">modelflare.dev</a>.</p>
47
+ <p>Responses and Chat Completions can both ask an application to run a function, but they represent the tool loop differently. Chat Completions puts tool definitions under <code>tools[].function</code>, returns <code>message.tool_calls</code>, and accepts results as <code>role: "tool"</code> messages. Responses uses flat function definitions, returns typed <code>function_call</code> output items, and accepts <code>function_call_output</code> items linked by <code>call_id</code>.</p>
48
+ <p>The model does not execute your application function. Your code must validate the proposed arguments, authorize the operation, execute it exactly as intended, return a result to the model, and prevent duplicate side effects when a request is retried.</p>
49
+ <h2>The tool loop has four steps</h2>
50
+ <p>The endpoint-specific JSON differs, but the application state machine is the same:</p>
51
+ <pre><code class="language-text">1. Declare an allowed function and its argument schema
52
+ 2. Receive one or more model-proposed function calls
53
+ 3. Validate, authorize, and execute each call in application code
54
+ 4. Return each result using the call's correlation ID
55
+ </code></pre>
56
+ <p>Only after step four can the model produce an answer grounded in the tool result. If the model requests another tool, the loop repeats with a new call ID.</p>
57
+ <p>The <a href="https://developers.openai.com/api/docs/guides/function-calling">OpenAI Function Calling guide</a> describes this as a multi-step exchange. Treating the first tool call as a final answer is a common integration error.</p>
58
+ <h2>Compare the wire contracts</h2>
59
+ <p>The main differences are structural rather than conceptual.</p>
60
+ <table>
61
+ <thead>
62
+ <tr>
63
+ <th>Concern</th>
64
+ <th>Responses API</th>
65
+ <th>Chat Completions</th>
66
+ </tr>
67
+ </thead>
68
+ <tbody>
69
+ <tr>
70
+ <td>Function definition</td>
71
+ <td>Flat <code>tools[]</code> item with <code>name</code>, <code>description</code>, <code>parameters</code>, <code>strict</code></td>
72
+ <td><code>tools[]</code> item with those fields nested under <code>function</code></td>
73
+ </tr>
74
+ <tr>
75
+ <td>Model-proposed call</td>
76
+ <td>Typed <code>function_call</code> output item</td>
77
+ <td>Assistant message <code>tool_calls[]</code> entry</td>
78
+ </tr>
79
+ <tr>
80
+ <td>Correlation identifier</td>
81
+ <td><code>call_id</code></td>
82
+ <td>Tool call <code>id</code>, returned as <code>tool_call_id</code></td>
83
+ </tr>
84
+ <tr>
85
+ <td>Function name</td>
86
+ <td><code>function_call.name</code></td>
87
+ <td><code>tool_calls[].function.name</code></td>
88
+ </tr>
89
+ <tr>
90
+ <td>Arguments</td>
91
+ <td>JSON string in <code>function_call.arguments</code></td>
92
+ <td>JSON string in <code>tool_calls[].function.arguments</code></td>
93
+ </tr>
94
+ <tr>
95
+ <td>Tool result</td>
96
+ <td><code>function_call_output</code> input item</td>
97
+ <td>Message with <code>role: "tool"</code></td>
98
+ </tr>
99
+ <tr>
100
+ <td>Common streamed arguments</td>
101
+ <td>Typed function-argument delta events</td>
102
+ <td>Indexed <code>delta.tool_calls[]</code> fragments</td>
103
+ </tr>
104
+ <tr>
105
+ <td>Final text</td>
106
+ <td>Typed output items and output-text helpers</td>
107
+ <td><code>choices[0].message.content</code></td>
108
+ </tr>
109
+ </tbody>
110
+ </table>
111
+ <p>Do not correlate calls by array position. Parallel calls and streamed chunks can arrive in an order that differs from the order in which your application finishes. The explicit call ID is the stable join key.</p>
112
+ <h2>Define one strict function schema</h2>
113
+ <p>The following examples expose a read-only <code>get_delivery_status</code> function. The model may request an order status, but it cannot change an order, issue a refund, or access arbitrary storage.</p>
114
+ <p>The argument schema is deliberately narrow:</p>
115
+ <pre><code class="language-json">{
116
+ &quot;type&quot;: &quot;object&quot;,
117
+ &quot;properties&quot;: {
118
+ &quot;order_id&quot;: {
119
+ &quot;type&quot;: &quot;string&quot;,
120
+ &quot;pattern&quot;: &quot;^ORDER-[0-9]{4}$&quot;
121
+ }
122
+ },
123
+ &quot;required&quot;: [&quot;order_id&quot;],
124
+ &quot;additionalProperties&quot;: false
125
+ }
126
+ </code></pre>
127
+ <p><code>strict: true</code> asks the supported model to adhere to the function argument schema. The application must still parse and validate the JSON before execution. Pattern support and other JSON Schema features can vary by model or provider, so the same compatibility gate used for <a href="https://modelflare.dev/articles/structured-outputs-openai-compatible-api?source=hf-blog">Structured Outputs</a> also applies to function arguments.</p>
128
+ <h2>Implement the loop with the Responses API</h2>
129
+ <p>This JavaScript example keeps the exchange stateless by returning the model鈥檚 output items with the function result. It uses a deterministic local function so the control flow is visible without introducing another external API.</p>
130
+ <pre><code class="language-javascript">import OpenAI from &quot;openai&quot;;
131
+
132
+ const client = new OpenAI({
133
+ apiKey: process.env.MODELFLARE_API_KEY,
134
+ baseURL: &quot;https://modelflare.dev/v1&quot;,
135
+ });
136
+
137
+ const model = process.env.MODEL_ID;
138
+ if (!model) throw new Error(&quot;MODEL_ID is required&quot;);
139
+
140
+ const orders = new Map([
141
+ [&quot;ORDER-1001&quot;, { status: &quot;in_transit&quot;, eta: &quot;2026-08-06&quot; }],
142
+ ]);
143
+
144
+ const tools = [
145
+ {
146
+ type: &quot;function&quot;,
147
+ name: &quot;get_delivery_status&quot;,
148
+ description: &quot;Return the current delivery status for one order.&quot;,
149
+ parameters: {
150
+ type: &quot;object&quot;,
151
+ properties: {
152
+ order_id: { type: &quot;string&quot;, pattern: &quot;^ORDER-[0-9]{4}$&quot; },
153
+ },
154
+ required: [&quot;order_id&quot;],
155
+ additionalProperties: false,
156
+ },
157
+ strict: true,
158
+ },
159
+ ];
160
+
161
+ function executeTool(name, rawArguments) {
162
+ if (name !== &quot;get_delivery_status&quot;) {
163
+ throw new Error(`Tool is not allowed: ${name}`);
164
+ }
165
+
166
+ const args = JSON.parse(rawArguments);
167
+ if (!/^ORDER-[0-9]{4}$/.test(args.order_id)) {
168
+ throw new Error(&quot;Invalid order_id&quot;);
169
+ }
170
+
171
+ return orders.get(args.order_id) ?? { status: &quot;not_found&quot; };
172
+ }
173
+
174
+ const first = await client.responses.create({
175
+ model,
176
+ input: &quot;Where is ORDER-1001?&quot;,
177
+ tools,
178
+ parallel_tool_calls: false,
179
+ });
180
+
181
+ const calls = first.output.filter((item) =&gt; item.type === &quot;function_call&quot;);
182
+ if (calls.length === 0) {
183
+ console.log(first.output_text);
184
+ process.exit(0);
185
+ }
186
+
187
+ const toolOutputs = calls.map((call) =&gt; ({
188
+ type: &quot;function_call_output&quot;,
189
+ call_id: call.call_id,
190
+ output: JSON.stringify(executeTool(call.name, call.arguments)),
191
+ }));
192
+
193
+ const final = await client.responses.create({
194
+ model,
195
+ input: [...first.output, ...toolOutputs],
196
+ tools,
197
+ parallel_tool_calls: false,
198
+ });
199
+
200
+ console.log(final.output_text);
201
+ </code></pre>
202
+ <p>For a stateful integration, Responses also supports continuing from a prior response where the route and storage policy permit it. A stateless example makes the complete transcript explicit and avoids assuming that every OpenAI-compatible route stores response state.</p>
203
+ <p>The critical fields are <code>call.call_id</code> on the model output and the matching <code>call_id</code> on <code>function_call_output</code>. Returning a result with the wrong ID disconnects the data from the model鈥檚 request.</p>
204
+ <h2>Implement the loop with Chat Completions</h2>
205
+ <p>The same application function can be used with Chat Completions. The tool definition and result message use the Chat wrapper.</p>
206
+ <pre><code class="language-javascript">import OpenAI from &quot;openai&quot;;
207
+
208
+ const client = new OpenAI({
209
+ apiKey: process.env.MODELFLARE_API_KEY,
210
+ baseURL: &quot;https://modelflare.dev/v1&quot;,
211
+ });
212
+
213
+ const model = process.env.MODEL_ID;
214
+ if (!model) throw new Error(&quot;MODEL_ID is required&quot;);
215
+
216
+ const orders = new Map([
217
+ [&quot;ORDER-1001&quot;, { status: &quot;in_transit&quot;, eta: &quot;2026-08-06&quot; }],
218
+ ]);
219
+
220
+ const tools = [
221
+ {
222
+ type: &quot;function&quot;,
223
+ function: {
224
+ name: &quot;get_delivery_status&quot;,
225
+ description: &quot;Return the current delivery status for one order.&quot;,
226
+ parameters: {
227
+ type: &quot;object&quot;,
228
+ properties: {
229
+ order_id: { type: &quot;string&quot;, pattern: &quot;^ORDER-[0-9]{4}$&quot; },
230
+ },
231
+ required: [&quot;order_id&quot;],
232
+ additionalProperties: false,
233
+ },
234
+ strict: true,
235
+ },
236
+ },
237
+ ];
238
+
239
+ function executeTool(name, rawArguments) {
240
+ if (name !== &quot;get_delivery_status&quot;) {
241
+ throw new Error(`Tool is not allowed: ${name}`);
242
+ }
243
+
244
+ const args = JSON.parse(rawArguments);
245
+ if (!/^ORDER-[0-9]{4}$/.test(args.order_id)) {
246
+ throw new Error(&quot;Invalid order_id&quot;);
247
+ }
248
+
249
+ return orders.get(args.order_id) ?? { status: &quot;not_found&quot; };
250
+ }
251
+
252
+ const messages = [
253
+ { role: &quot;user&quot;, content: &quot;Where is ORDER-1001?&quot; },
254
+ ];
255
+
256
+ const first = await client.chat.completions.create({
257
+ model,
258
+ messages,
259
+ tools,
260
+ parallel_tool_calls: false,
261
+ });
262
+
263
+ const assistant = first.choices[0].message;
264
+ const calls = assistant.tool_calls ?? [];
265
+ if (calls.length === 0) {
266
+ console.log(assistant.content);
267
+ process.exit(0);
268
+ }
269
+
270
+ messages.push(assistant);
271
+ for (const call of calls) {
272
+ const result = executeTool(call.function.name, call.function.arguments);
273
+ messages.push({
274
+ role: &quot;tool&quot;,
275
+ tool_call_id: call.id,
276
+ content: JSON.stringify(result),
277
+ });
278
+ }
279
+
280
+ const final = await client.chat.completions.create({
281
+ model,
282
+ messages,
283
+ tools,
284
+ parallel_tool_calls: false,
285
+ });
286
+
287
+ console.log(final.choices[0].message.content);
288
+ </code></pre>
289
+ <p>Here, the first assistant message must be appended to <code>messages</code> before its tool results. Each result uses <code>tool_call_id: call.id</code>. Omitting the assistant tool-call message or returning an unmatched ID produces an invalid conversation history.</p>
290
+ <h2>Stream arguments as fragments, not complete JSON</h2>
291
+ <p>In streaming mode, function arguments can arrive in fragments. A chunk that contains <code>{"order</code> is not invalid JSON; it is incomplete JSON.</p>
292
+ <p>The safe parser keeps one buffer per call identity:</p>
293
+ <ol>
294
+ <li>identify the call or indexed call slot from the event;</li>
295
+ <li>append each argument delta to that call鈥檚 buffer;</li>
296
+ <li>wait for the endpoint鈥檚 argument-done or completed signal;</li>
297
+ <li>parse the complete string once;</li>
298
+ <li>validate and execute only after completion.</li>
299
+ </ol>
300
+ <p>Responses uses typed events for function-call arguments and output items. Chat Completions emits fragments in <code>choices[].delta.tool_calls[]</code>, where the index identifies the in-progress entry and the final tool call carries its stable ID. Do not execute a function when the first fragment arrives.</p>
301
+ <p>The <a href="https://modelflare.dev/articles/ai-api-streaming-guide?source=hf-blog">AI API Streaming Guide</a> explains why connection, first event, first effective output, idle timeout, and completion should be measured separately.</p>
302
+ <h2>Make tool execution safe and idempotent</h2>
303
+ <p>Strict arguments improve structure, not authorization. Before executing any call:</p>
304
+ <ul>
305
+ <li>allow only registered function names;</li>
306
+ <li>parse arguments with a size limit;</li>
307
+ <li>validate the complete schema in application code;</li>
308
+ <li>authorize the current user or workload for the requested resource;</li>
309
+ <li>separate read-only tools from tools with side effects;</li>
310
+ <li>redact secrets and sensitive output before returning it to the model;</li>
311
+ <li>use a deadline and bounded downstream retries;</li>
312
+ <li>record a safe operation reference, not raw secrets or private content.</li>
313
+ </ul>
314
+ <p>For a side-effecting tool, use an idempotency key derived from a stable application request and call identity. Store the completed result before returning it to the model. If a network retry replays the same call, return the stored result rather than issuing a second refund, message, deployment, or database mutation.</p>
315
+ <p>The model-generated function name and arguments are untrusted input. A valid schema cannot grant permission, prove ownership, or replace a transaction boundary.</p>
316
+ <h2>Decide how to handle multiple calls</h2>
317
+ <p>The examples set <code>parallel_tool_calls: false</code> to keep the state machine easy to inspect. If parallel calls are enabled:</p>
318
+ <ul>
319
+ <li>correlate every result by call ID, never by completion order;</li>
320
+ <li>enforce a maximum number of calls per response;</li>
321
+ <li>apply a concurrency limit in the application;</li>
322
+ <li>define whether one failed tool cancels, blocks, or coexists with successful tools;</li>
323
+ <li>return one result for every accepted call;</li>
324
+ <li>keep side-effecting operations serialized when their order matters.</li>
325
+ </ul>
326
+ <p>Parallel execution can reduce latency for independent reads, but it increases authorization, ordering, retry, and partial-failure complexity. Enable it because the workload benefits, not because the parameter exists.</p>
327
+ <h2>Understand the Modelflare compatibility boundary</h2>
328
+ <p>Modelflare鈥檚 OpenAI compatibility code preserves strict function definitions and maps the supported function-call shapes between Responses and Chat Completions on eligible OpenAI/Codex routes. That mapping is deliberately narrower than the complete Responses tool surface.</p>
329
+ <p>Application-defined function tools can be represented in both formats. Responses-only hosted tools鈥攕uch as provider-run search, code execution, or other built-in tool types鈥攁re not equivalent to application function calling and cannot be assumed to convert into Chat Completions.</p>
330
+ <p>Other OpenAI-compatible model families are exposed through raw Chat Completions pass-through unless separately verified. For those routes, the upstream provider decides whether <code>tools</code>, <code>strict</code>, parallel calls, streaming argument fragments, and specific <code>tool_choice</code> shapes are supported.</p>
331
+ <p>Before enabling a route, run the complete loop rather than checking only whether the first request returns <code>200</code>:</p>
332
+ <table>
333
+ <thead>
334
+ <tr>
335
+ <th>Test</th>
336
+ <th>Required evidence</th>
337
+ </tr>
338
+ </thead>
339
+ <tbody>
340
+ <tr>
341
+ <td>One read-only call</td>
342
+ <td>Function name, parsed arguments, call ID, result linkage, final text</td>
343
+ </tr>
344
+ <tr>
345
+ <td>Invalid arguments</td>
346
+ <td>Explicit validation failure with no tool execution</td>
347
+ </tr>
348
+ <tr>
349
+ <td>Unknown function</td>
350
+ <td>Rejected by the application allowlist</td>
351
+ </tr>
352
+ <tr>
353
+ <td>No tool required</td>
354
+ <td>Normal final text without a fabricated call</td>
355
+ </tr>
356
+ <tr>
357
+ <td>Streaming call</td>
358
+ <td>Complete reconstructed arguments and correct call ID</td>
359
+ </tr>
360
+ <tr>
361
+ <td>Repeated request</td>
362
+ <td>One side effect or one cached result, not duplicate execution</td>
363
+ </tr>
364
+ <tr>
365
+ <td>Multiple calls</td>
366
+ <td>Correct correlation independent of completion order</td>
367
+ </tr>
368
+ <tr>
369
+ <td>Route fallback</td>
370
+ <td>Same model, protocol, tool schema, and result contract preserved</td>
371
+ </tr>
372
+ </tbody>
373
+ </table>
374
+ <p>Use <a href="https://modelflare.dev/articles/reliable-ai-api-routing?source=hf-blog">Reliable AI API Routing</a> to keep route changes explicit, and <a href="https://modelflare.dev/articles/api-key-security-cost-controls?source=hf-blog">AI API Key Security</a> to separate workloads and permissions.</p>
375
+ <h2>Choose the format by the application contract</h2>
376
+ <p>Use Responses when the application benefits from typed output items, the Responses event model, state-continuation options, or other verified Responses capabilities. Use Chat Completions when the application already owns a stable message transcript and the selected provider鈥檚 tool contract is verified. The broader endpoint decision is covered in <a href="https://modelflare.dev/articles/responses-api-vs-chat-completions?source=hf-blog">Responses API vs Chat Completions</a>.</p>
377
+ <p>The implementation standard should be the same in both cases: explicit tool allowlists, strict argument schemas, application-side validation, authorization before execution, correlation by call ID, idempotency for side effects, and a complete result returned to the model. Those controls鈥攏ot the endpoint name鈥攎ake a function-calling workflow reliable.</p>
378
+ <hr />
379
+ <p>Canonical: https://modelflare.dev/articles/function-calling-responses-vs-chat-completions</p></article><p><a href="index.html">&larr; All articles</a></p>
380
+ <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>
381
+ </html>
index.html CHANGED
@@ -39,6 +39,6 @@ footer a{color:var(--muted)}
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"><img src="images/introducing-modelflare-cover.jpg" alt="Diagram: one entry point routed to several model backends"><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"><img src="images/openai-sdk-one-line-cover.jpg" alt="Diagram: a request passing through a compatible interface"><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"><img src="images/coding-agents-modelflare-cover.jpg" alt="Diagram: a coding agent connected through a gateway to several services"><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"><img src="images/api-recipes-streaming-fallback-cover.jpg" alt="Diagram: parallel routes converging with fallback paths"><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="smart-api-key.html"><img src="images/smart-api-key-cover.jpg" alt="Illustration: a key module feeding a single route"><div><h2>Smart API Keys: one key for every model your account can use</h2><p>A Smart API Key is bound to <code>auto</code> instead of a fixed routing group. It resolves a group on each request and orders candidates by a routing strategy that you choose.</p></div></a><a class="card" href="model-groups-and-failover.html"><img src="images/model-groups-and-failover-cover.jpg" alt="Illustration: parallel routes converging on one output"><div><h2>Model groups and failover: how Modelflare routes a request</h2><p>Every request depends on two identifiers: the exact model ID in the body and the routing group on the key. Ordinary keys add ordered fallback groups that take over when a route cannot serve the request.</p></div></a><a class="card" href="usage-and-cost-records.html"><img src="images/usage-and-cost-records-cover.jpg" alt="Illustration: a balance weighing request units"><div><h2>Usage and cost records: reading what each request cost</h2><p>Modelflare records token usage and cost for every request. This guide covers where those records live, how billing units differ between text, image, and video, the cache hit guarantee, and how long logs are kept.</p></div></a><a class="card" href="media-skill-for-agents.html"><img src="images/media-skill-for-agents-cover.jpg" alt="Illustration: media inputs feeding a processing unit and a film strip"><div><h2>The Modelflare Media Skill: image and video generation from coding agents</h2><p>The Media Skill is an installable SKILL.md package. With it, Claude Code, Codex, and other skill-aware agents can choose a Modelflare image or video model, quote its price, send the request, and save the result.</p></div></a><a class="card" href="seedance-asset-library.html"><img src="images/seedance-asset-library-cover.jpg" alt="Illustration: image and media tiles feeding a central processing unit"><div><h2>The Seedance asset library: uploading reference media and using asset:// IDs</h2><p>Seedance 2.0 and 2.5 do not accept a photorealistic person or a realistic face as an image URL. Upload the media to the asset library, poll until it is <code>Active</code>, and reference it as <code>asset://&lt;ID&gt;</code> in a video request.</p></div></a><a class="card" href="codex-cli-in-depth.html"><img src="images/codex-cli-in-depth-cover.jpg" alt="Illustration: a keypad module sending requests through a panel to several backends"><div><h2>Codex CLI on Modelflare in depth: installer, config.toml, auth.json, and common problems</h2><p>Codex connects over the Responses API at <code>https://modelflare.dev/v1</code>. This guide covers the installer and the root/VPS variant with <code>MODELFLARE_ALLOW_ROOT=1</code>, every key in <code>config.toml</code>, the <code>auth.json</code> format, and the four documented problems.</p></div></a><a class="card" href="claude-code-in-depth.html"><img src="images/claude-code-in-depth-cover.jpg" alt="Illustration: a stack of request cards routed through one panel to several modules"><div><h2>Claude Code on Modelflare in depth: installer, settings.json, model slots, and troubleshooting</h2><p>Claude Code connects through Anthropic Messages with <code>ANTHROPIC_BASE_URL</code> set to <code>https://modelflare.dev</code>. This guide covers the installer and the root/VPS variant with <code>MODELFLARE_ALLOW_ROOT=1</code>, the <code>env</code> block in <code>settings.json</code>, the four model slots, and the documented error codes.</p></div></a><a class="card" href="castaly-image-video-studio.html"><img src="images/castaly-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><a class="card" href="gpt-6-1-terra-deep-analysis.html"><img src="images/gpt-6-1-terra-deep-analysis-cover.jpg" alt="Illustration: a visual input panel wired through a reasoning dial to pointer tiles, above a long context strip"><div><h2>GPT-6.1 Terra: Capabilities, Parameters, Pricing, and Model Comparison</h2><p>A source-backed guide to GPT-6.1 Terra&#x27;s visual reasoning, computer use, context limits, reasoning controls, pricing, and trade-offs against Astra, Sol, Luna, Claude Sonnet 5.5, and Gemini 3.8 Flash.</p></div></a><a class="card" href="llm-api-load-testing.html"><img src="images/llm-api-load-testing-cover.jpg" alt="Illustration for LLM API load testing guide"><div><h2>Load Test an LLM API Without Misleading Results</h2><p>Production guide: Load Test an LLM API Without Misleading Results. It includes a deterministic artifact, failure boundaries, rollout checks, and source-qualified limitations.</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>
 
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"><img src="images/introducing-modelflare-cover.jpg" alt="Diagram: one entry point routed to several model backends"><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"><img src="images/openai-sdk-one-line-cover.jpg" alt="Diagram: a request passing through a compatible interface"><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"><img src="images/coding-agents-modelflare-cover.jpg" alt="Diagram: a coding agent connected through a gateway to several services"><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"><img src="images/api-recipes-streaming-fallback-cover.jpg" alt="Diagram: parallel routes converging with fallback paths"><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="smart-api-key.html"><img src="images/smart-api-key-cover.jpg" alt="Illustration: a key module feeding a single route"><div><h2>Smart API Keys: one key for every model your account can use</h2><p>A Smart API Key is bound to <code>auto</code> instead of a fixed routing group. It resolves a group on each request and orders candidates by a routing strategy that you choose.</p></div></a><a class="card" href="model-groups-and-failover.html"><img src="images/model-groups-and-failover-cover.jpg" alt="Illustration: parallel routes converging on one output"><div><h2>Model groups and failover: how Modelflare routes a request</h2><p>Every request depends on two identifiers: the exact model ID in the body and the routing group on the key. Ordinary keys add ordered fallback groups that take over when a route cannot serve the request.</p></div></a><a class="card" href="usage-and-cost-records.html"><img src="images/usage-and-cost-records-cover.jpg" alt="Illustration: a balance weighing request units"><div><h2>Usage and cost records: reading what each request cost</h2><p>Modelflare records token usage and cost for every request. This guide covers where those records live, how billing units differ between text, image, and video, the cache hit guarantee, and how long logs are kept.</p></div></a><a class="card" href="media-skill-for-agents.html"><img src="images/media-skill-for-agents-cover.jpg" alt="Illustration: media inputs feeding a processing unit and a film strip"><div><h2>The Modelflare Media Skill: image and video generation from coding agents</h2><p>The Media Skill is an installable SKILL.md package. With it, Claude Code, Codex, and other skill-aware agents can choose a Modelflare image or video model, quote its price, send the request, and save the result.</p></div></a><a class="card" href="seedance-asset-library.html"><img src="images/seedance-asset-library-cover.jpg" alt="Illustration: image and media tiles feeding a central processing unit"><div><h2>The Seedance asset library: uploading reference media and using asset:// IDs</h2><p>Seedance 2.0 and 2.5 do not accept a photorealistic person or a realistic face as an image URL. Upload the media to the asset library, poll until it is <code>Active</code>, and reference it as <code>asset://&lt;ID&gt;</code> in a video request.</p></div></a><a class="card" href="codex-cli-in-depth.html"><img src="images/codex-cli-in-depth-cover.jpg" alt="Illustration: a keypad module sending requests through a panel to several backends"><div><h2>Codex CLI on Modelflare in depth: installer, config.toml, auth.json, and common problems</h2><p>Codex connects over the Responses API at <code>https://modelflare.dev/v1</code>. This guide covers the installer and the root/VPS variant with <code>MODELFLARE_ALLOW_ROOT=1</code>, every key in <code>config.toml</code>, the <code>auth.json</code> format, and the four documented problems.</p></div></a><a class="card" href="claude-code-in-depth.html"><img src="images/claude-code-in-depth-cover.jpg" alt="Illustration: a stack of request cards routed through one panel to several modules"><div><h2>Claude Code on Modelflare in depth: installer, settings.json, model slots, and troubleshooting</h2><p>Claude Code connects through Anthropic Messages with <code>ANTHROPIC_BASE_URL</code> set to <code>https://modelflare.dev</code>. This guide covers the installer and the root/VPS variant with <code>MODELFLARE_ALLOW_ROOT=1</code>, the <code>env</code> block in <code>settings.json</code>, the four model slots, and the documented error codes.</p></div></a><a class="card" href="castaly-image-video-studio.html"><img src="images/castaly-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><a class="card" href="gpt-6-1-terra-deep-analysis.html"><img src="images/gpt-6-1-terra-deep-analysis-cover.jpg" alt="Illustration: a visual input panel wired through a reasoning dial to pointer tiles, above a long context strip"><div><h2>GPT-6.1 Terra: Capabilities, Parameters, Pricing, and Model Comparison</h2><p>A source-backed guide to GPT-6.1 Terra&#x27;s visual reasoning, computer use, context limits, reasoning controls, pricing, and trade-offs against Astra, Sol, Luna, Claude Sonnet 5.5, and Gemini 3.8 Flash.</p></div></a><a class="card" href="llm-api-load-testing.html"><img src="images/llm-api-load-testing-cover.jpg" alt="Illustration for LLM API load testing guide"><div><h2>Load Test an LLM API Without Misleading Results</h2><p>Production guide: Load Test an LLM API Without Misleading Results. It includes a deterministic artifact, failure boundaries, rollout checks, and source-qualified limitations.</p></div></a><a class="card" href="function-calling-responses-vs-chat-completions.html"><img src="images/function-calling-responses-vs-chat-completions-cover.jpg" alt="Illustration: a request passing through one central module that fans out to several tool modules"><div><h2>Function Calling: Responses API vs Chat Completions</h2><p>A wire-level comparison of function definitions, Call IDs, result messages, streaming arguments, authorization, idempotency, and route compatibility.</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>