forked from gpt4free/g4f.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend_api_documentation.html
More file actions
712 lines (641 loc) · 29.6 KB
/
Copy pathbackend_api_documentation.html
File metadata and controls
712 lines (641 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<!DOCTYPE html>
<html lang="en" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>G4F - Backend API Documentation</title>
<meta name="description" content="GPT4Free documentation for G4F - Backend API Documentation. Complete guides, examples, and API reference for free AI endpoints, code generation, and AI model integration." />
<meta name="keywords" content="GPT4Free, G4F, AI documentation, free AI API, OpenAI alternative, JavaScript AI client, Python AI library, AI integration, code generation, G4F - Backend API Documentation" />
<meta name="author" content="GPT4Free Team" />
<!-- Open Graph -->
<meta property="og:type" content="article" />
<meta property="og:title" content="G4F - Backend API Documentation | GPT4Free Documentation" />
<meta property="og:description" content="GPT4Free documentation for G4F - Backend API Documentation. Free AI endpoints, examples, and comprehensive guides." />
<meta property="og:url" content="https://g4f.dev/docs/backend_api_documentation.html" />
<meta property="og:site_name" content="GPT4Free Documentation" />
<meta property="og:image" content="https://g4f.dev/dist/img/g4f.svg" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="G4F - Backend API Documentation | GPT4Free Documentation" />
<meta name="twitter:description" content="Free AI endpoints and comprehensive documentation for G4F - Backend API Documentation." />
<meta name="twitter:image" content="https://g4f.dev/dist/img/g4f.svg" />
<!-- Canonical -->
<link rel="canonical" href="https://g4f.dev/docs/backend_api_documentation.html" />
<link rel="apple-touch-icon" sizes="180x180" href="/dist/img/g4f.svg" />
<link rel="icon" type="image/png" sizes="32x32" href="/dist/img/g4f-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/dist/img/g4f-16x16.png" />
<link rel="manifest" href="/dist/img/site.webmanifest" />
<!-- GitHub Primer CSS & styles -->
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/light-74231a1f3bbb.css" />
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/dark-8a995f0bacd4.css" />
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-primitives-225433424a87.css" />
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-b8b91660c29d.css" />
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-205098e9fedd.css" />
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-177d21388df8.css" />
<style>
:root {
--accent: #8b3dff;
--background: #16101b;
--text-primary: #ddd;
--text-secondary: #9b7dff;
--card-bg: #1e152e;
--border-color: #333;
--hover-color: #a67eff;
}
body {
margin: 0;
padding: 0;
background: var(--background);
color: var(--text-primary);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
line-height: 1.6;
min-height: 100vh;
}
.container {
display: flex;
max-width: 100%;
margin: 0;
padding: 2rem;
gap: 3rem;
min-height: calc(100vh - 4rem);
}
/* Enhanced main content styling */
main {
flex: 1;
background: var(--card-bg);
border-radius: 12px;
padding: 2.5rem;
box-shadow: 0 8px 30px rgba(0,0,0,0.7);
overflow-wrap: break-word;
position: relative;
}
/* Typography improvements */
.markdown-body h1 {
font-size: 2.8rem;
margin-bottom: 1rem;
font-weight: 700;
color: var(--text-primary);
border-bottom: 3px solid var(--accent);
padding-bottom: 0.5rem;
}
.markdown-body h2 {
margin-top: 3rem;
margin-bottom: 1rem;
border-bottom: 2px solid var(--accent);
padding-bottom: 0.25rem;
color: var(--text-primary);
}
.markdown-body h3 {
margin-top: 2rem;
margin-bottom: 0.8rem;
color: var(--text-primary);
}
.markdown-body p {
margin-bottom: 1.2rem;
color: var(--text-primary);
}
/* Enhanced link styling */
.markdown-body a {
color: var(--accent);
text-decoration: none;
transition: all 0.3s ease;
font-weight: 500;
}
.markdown-body a:hover,
.markdown-body a:focus {
color: var(--hover-color);
outline: none;
text-decoration: underline;
text-shadow: 0 0 8px rgba(139, 61, 255, 0.3);
}
/* Enhanced code block styling */
.markdown-body pre {
border-radius: 12px;
padding: 1.5rem !important;
font-size: 0.95rem !important;
overflow-x: auto;
max-height: 500px;
box-shadow: inset 0 0 12px rgba(0,0,0,0.6), 0 4px 20px rgba(0,0,0,0.4);
color: #fff;
border: 1px solid #3d2a5c;
position: relative;
}
.markdown-body code {
font-family: 'SF Mono', 'Cascadia Code', 'Roboto Mono', Consolas, Liberation Mono, Menlo, monospace;
background: rgba(139, 61, 255, 0.1);
padding: 0.2em 0.4em;
border-radius: 4px;
color: #e6ccff;
font-size: 0.9em;
}
.markdown-body pre code {
background: transparent;
padding: 0;
color: var(--fgColor-default, var(--color-fg-default))
}
/* Table styling */
.markdown-body table {
border-collapse: collapse;
width: 100%;
margin: 2rem 0;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.markdown-body table th,
.markdown-body table td {
padding: 1rem;
text-align: left;
border: 1px solid var(--border-color);
}
.markdown-body table th {
background: var(--accent);
color: white;
font-weight: 600;
}
.markdown-body table tr:nth-child(even) {
background: rgba(139, 61, 255, 0.05);
}
.markdown-body table tr {
background-color: transparent;
}
/* List styling */
.markdown-body ul,
.markdown-body ol {
margin-bottom: 1.5rem;
padding-left: 2rem;
}
.markdown-body li {
margin-bottom: 0.5rem;
color: var(--text-primary);
}
/* Blockquote styling */
.markdown-body blockquote {
border-left: 4px solid var(--accent);
background: rgba(139, 61, 255, 0.1);
margin: 2rem 0;
padding: 1rem 1.5rem;
border-radius: 0 8px 8px 0;
}
/* HR styling */
.markdown-body hr {
border: none;
border-top: 2px solid var(--accent);
margin: 3rem 0;
opacity: 0.6;
}
/* Sticky table of contents */
nav#toc {
flex: 0 0 280px;
position: sticky;
top: 2rem;
background: var(--card-bg);
padding: 1.5rem;
border-radius: 12px;
box-shadow: 0 8px 30px rgba(0,0,0,0.7);
max-height: calc(100vh - 4rem);
overflow-y: auto;
font-size: 0.9rem;
line-height: 1.5;
border: 1px solid rgba(139, 61, 255, 0.2);
}
nav#toc h2 {
font-size: 1.4rem;
margin: 0 0 1.5rem 0;
border-bottom: 2px solid var(--accent);
padding-bottom: 0.5rem;
color: var(--text-primary);
}
nav#toc ul {
list-style: none;
padding-left: 0;
margin: 0;
}
nav#toc li {
margin-bottom: 0.8rem;
}
nav#toc a {
color: var(--text-secondary);
text-decoration: none;
display: block;
padding: 0.3rem 0.5rem;
border-radius: 6px;
transition: all 0.3s ease;
}
nav#toc a:hover,
nav#toc a:focus {
background: rgba(139, 61, 255, 0.1);
color: var(--hover-color);
text-decoration: none;
transform: translateX(4px);
}
/* Responsive design */
@media (max-width: 1024px) {
.container {
flex-direction: column;
padding: 1rem;
gap: 2rem;
}
nav#toc {
position: relative;
max-height: none;
order: -1;
flex: none;
}
.markdown-body h1 {
font-size: 2.2rem;
}
}
@media (max-width: 768px) {
.container {
padding: 0.5rem;
}
main {
padding: 1.5rem;
}
.markdown-body h1 {
font-size: 1.8rem;
}
.markdown-body pre {
padding: 1rem !important;
font-size: 0.85rem !important;
}
}
/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Focus indicators */
*:focus {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* Print styles */
@media print {
.container {
display: block;
}
nav#toc {
display: none;
}
main {
box-shadow: none;
background: white;
color: black;
}
}
/* Loading animation for syntax highlighting */
.highlight-loading {
position: relative;
opacity: 0.7;
}
.highlight-loading::after {
content: 'Loading syntax highlighting...';
position: absolute;
top: 1rem;
right: 1rem;
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.6);
}
/* Translate Button Style */
#translate-toggle {
display: block;
background: var(--accent);
color: #fff;
text-align: center;
padding: 0.5rem;
border-radius: 6px;
margin-bottom: 1rem;
cursor: pointer;
font-size: 0.9rem;
border: none;
}
#google_translate_element {
margin-bottom: 1rem;
}
</style>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "G4F - Backend API Documentation",
"description": "GPT4Free documentation for G4F - Backend API Documentation. Complete guides, examples, and API reference for free AI endpoints.",
"author": {
"@type": "Organization",
"@id": "https://g4f.dev/#organization",
"name": "GPT4Free",
"url": "https://g4f.dev",
"logo": {
"@type": "ImageObject",
"url": "https://g4f.dev/dist/img/g4f.svg"
}
},
"publisher": {
"@type": "Organization",
"@id": "https://g4f.dev/#organization"
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://g4f.dev/docs/backend_api_documentation.html"
},
"datePublished": "2024-01-01T00:00:00Z",
"dateModified": "2024-01-01T00:00:00Z",
"inLanguage": "en",
"isAccessibleForFree": true,
"keywords": "GPT4Free, AI documentation, free AI API, code generation",
"articleSection": "Documentation"
}
</script>
</head>
<body>
<div class="container">
<nav id="toc" aria-label="Table of contents" role="navigation">
<!-- Translation Button -->
<button id="translate-toggle">🌐 Translate Page</button>
<div id="google_translate_element" style="display:none;"></div>
<h2>Contents</h2>
<ul id="toc-list">
<!-- Table of contents will be generated here -->
</ul>
<hr style="margin: 1.5rem 0; opacity: 0.3;">
<ul>
<li><a href="/docs/" aria-label="Return to documentation home">📚 Documentation Hub</a></li>
<li><a href="/" aria-label="Return to main site">🏠 G4F Home</a></li>
</ul>
</nav>
<main role="main" class="markdown-body entry-content" itemprop="text" itemscope itemtype="https://schema.org/TechArticle">
<h1>G4F - Backend API Documentation</h1>
<h2>Overview</h2>
<p>This documentation covers the <code class="notranslate">backend_api.py</code> module in the GPT4Free project, which serves as the core backend API handler for the web interface. It provides endpoints for interacting with language models, managing files, handling conversations, and processing media.</p>
<h2>API Endpoints</h2>
<h3>Models and Providers</h3>
<h4>Get Available Models</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/models
</code></pre>
<p>Returns a list of all available models with their capabilities (image, vision, audio, video) and compatible providers.</p>
<h4>Get Provider-Specific Models</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/models/<provider>
</code></pre>
<p>Returns models available for a specific provider.</p>
<h4>Get Available Providers</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/providers
</code></pre>
<p>Returns a list of all available providers with their capabilities and authentication requirements.</p>
<h4>Get Version Information</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/version
</code></pre>
<p>Returns current and latest version information.</p>
<h3>Conversation Handling</h3>
<h4>Create Conversation</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/conversation
</code></pre>
<p>Handles conversation requests and streams responses. Supports text, images, and other media.</p>
<p><strong>Request Body:</strong></p>
<div class="highlight highlight-source-json"><pre class="notranslate">{
<span class="pl-ent">"model"</span>: <span class="pl-s"><span class="pl-pds">"</span>gpt-3.5-turbo<span class="pl-pds">"</span></span>,
<span class="pl-ent">"provider"</span>: <span class="pl-s"><span class="pl-pds">"</span>OpenAI<span class="pl-pds">"</span></span>,
<span class="pl-ent">"messages"</span>: [
{<span class="pl-ent">"role"</span>: <span class="pl-s"><span class="pl-pds">"</span>user<span class="pl-pds">"</span></span>, <span class="pl-ent">"content"</span>: <span class="pl-s"><span class="pl-pds">"</span>Hello, how are you?<span class="pl-pds">"</span></span>}
],
<span class="pl-ent">"download_media"</span>: <span class="pl-c1">true</span>
}</pre></div>
<h4>Quick Create</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/create
</code></pre>
<p>Creates a simple conversation with optional web search integration.</p>
<p><strong>Query Parameters:</strong></p>
<ul>
<li><code class="notranslate">model</code>: Model to use</li>
<li><code class="notranslate">prompt</code>: User prompt</li>
<li><code class="notranslate">provider</code>: Provider to use</li>
<li><code class="notranslate">web_search</code>: Enable web search (true/false or search query)</li>
<li><code class="notranslate">filter_markdown</code>: Filter markdown in response</li>
</ul>
<h4>Log Usage</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/usage
</code></pre>
<p>Logs usage data for analytics.</p>
<h4>Log Events</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/log
</code></pre>
<p>Logs client-side events.</p>
<h3>File Management</h3>
<h4>Manage File Buckets</h4>
<pre class="notranslate"><code class="notranslate">GET/DELETE /backend-api/v2/files/<bucket_id>
</code></pre>
<p>Retrieves or deletes file buckets.</p>
<h4>Upload Files</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/files/<bucket_id>
</code></pre>
<p>Uploads files to a bucket. Supports various file types including documents and media.</p>
<h4>Get Media Files</h4>
<pre class="notranslate"><code class="notranslate">GET /files/<bucket_id>/media/<filename>
</code></pre>
<p>Retrieves media files from a bucket.</p>
<h4>Search Media</h4>
<pre class="notranslate"><code class="notranslate">GET /search/<search>
</code></pre>
<p>Searches for media files based on search terms.</p>
<h4>Upload Cookies</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/upload_cookies
</code></pre>
<p>Uploads cookie files for authentication with providers.</p>
<h3>Chat Sharing</h3>
<h4>Get Shared Chat</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/chat/<share_id>
</code></pre>
<p>Retrieves a shared chat by ID.</p>
<h4>Save/Update Shared Chat</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/chat/<share_id>
</code></pre>
<p>Uploads or updates a shared chat.</p>
<h3>Memory Management</h3>
<h4>Add Memory Items</h4>
<pre class="notranslate"><code class="notranslate">POST /backend-api/v2/memory/<user_id>
</code></pre>
<p>Adds memory items for a user.</p>
<h4>Get Memory Items</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/memory/<user_id>
</code></pre>
<p>Retrieves memory items for a user with optional search and filtering.</p>
<h3>Media Handling</h3>
<h4>Serve Images</h4>
<pre class="notranslate"><code class="notranslate">GET /images/<path:name>
GET /media/<path:name>
</code></pre>
<p>Serves image and media files.</p>
<h4>Audio Synthesis</h4>
<pre class="notranslate"><code class="notranslate">GET /backend-api/v2/synthesize/<provider>
</code></pre>
<p>Handles audio synthesis requests for text-to-speech functionality.</p>
<h2>Usage Examples</h2>
<h3>Basic Conversation</h3>
<div class="highlight highlight-source-js"><pre class="notranslate"><span class="pl-c">// Example using fetch API</span>
<span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">'/backend-api/v2/conversation'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
<span class="pl-c1">method</span>: <span class="pl-s">'POST'</span><span class="pl-kos">,</span>
<span class="pl-c1">headers</span>: <span class="pl-kos">{</span>
<span class="pl-s">'Content-Type'</span>: <span class="pl-s">'application/json'</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-c1">body</span>: <span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
<span class="pl-c1">model</span>: <span class="pl-s">'gpt-3.5-turbo'</span><span class="pl-kos">,</span>
<span class="pl-c1">provider</span>: <span class="pl-s">'OpenAI'</span><span class="pl-kos">,</span>
<span class="pl-c1">messages</span>: <span class="pl-kos">[</span>
<span class="pl-kos">{</span><span class="pl-c1">role</span>: <span class="pl-s">'user'</span><span class="pl-kos">,</span> <span class="pl-c1">content</span>: <span class="pl-s">'What is artificial intelligence?'</span><span class="pl-kos">}</span>
<span class="pl-kos">]</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-s1">response</span> <span class="pl-c1">=></span> <span class="pl-kos">{</span>
<span class="pl-c">// Handle streaming response</span>
<span class="pl-k">const</span> <span class="pl-s1">reader</span> <span class="pl-c1">=</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-kos">.</span><span class="pl-en">getReader</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// Process chunks...</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<h3>File Upload</h3>
<div class="highlight highlight-source-js"><pre class="notranslate"><span class="pl-c">// Example using FormData</span>
<span class="pl-k">const</span> <span class="pl-s1">formData</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">FormData</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">formData</span><span class="pl-kos">.</span><span class="pl-en">append</span><span class="pl-kos">(</span><span class="pl-s">'files'</span><span class="pl-kos">,</span> <span class="pl-s1">fileObject</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">'/backend-api/v2/files/my-bucket'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
<span class="pl-c1">method</span>: <span class="pl-s">'POST'</span><span class="pl-kos">,</span>
<span class="pl-c1">body</span>: <span class="pl-s1">formData</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-s1">response</span> <span class="pl-c1">=></span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-s1">data</span> <span class="pl-c1">=></span> <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3>Using Web Search</h3>
<div class="highlight highlight-source-js"><pre class="notranslate"><span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">'/backend-api/v2/create?model=gpt-3.5-turbo&prompt=Latest news about AI&web_search=true'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
<span class="pl-c1">method</span>: <span class="pl-s">'GET'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-s1">response</span> <span class="pl-c1">=></span> <span class="pl-kos">{</span>
<span class="pl-c">// Handle streaming response with web search results</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<h2>Response Formats</h2>
<p>The API uses a consistent JSON format for responses with a <code class="notranslate">type</code> field indicating the kind of response:</p>
<ul>
<li><code class="notranslate">content</code>: Text content from the model</li>
<li><code class="notranslate">provider</code>: Information about the selected provider</li>
<li><code class="notranslate">conversation</code>: Conversation state</li>
<li><code class="notranslate">preview</code>: Preview of content</li>
<li><code class="notranslate">error</code>: Error information</li>
<li><code class="notranslate">auth</code>: Authentication requirements</li>
<li><code class="notranslate">parameters</code>: Model parameters</li>
<li><code class="notranslate">finish</code>: Finish reason</li>
<li><code class="notranslate">usage</code>: Token usage information</li>
<li><code class="notranslate">reasoning</code>: Reasoning process</li>
<li><code class="notranslate">suggestions</code>: Suggested follow-up questions</li>
<li><code class="notranslate">log</code>: Debug logs</li>
</ul>
<h2>Notes</h2>
<ul>
<li>The API supports streaming responses for real-time interaction</li>
<li>File uploads can be automatically converted to markdown if MarkItDown is available</li>
<li>Media files are stored in a dedicated directory structure with caching</li>
<li>Web search functionality enhances responses with real-world information</li>
<li>The system includes caching mechanisms for improved performance</li>
</ul>
<p>This documentation provides an overview of the main functionality in the Backend API. For more detailed information, refer to the code or reach out to the development team.</p>
<hr>
<p><a href="/docs/">Return to Documentation</a></p>
</main>
</div>
<script>
// Toggle Translation Widget
document.getElementById("translate-toggle").addEventListener("click", function() {
const el = document.getElementById("google_translate_element");
el.style.display = (el.style.display === "none") ? "block" : "none";
});
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script>
<script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script>
// Enhanced syntax highlighting with error handling
document.addEventListener('DOMContentLoaded', function() {
try {
// Generate table of contents
generateTableOfContents();
} catch (error) {
console.error('Error generating table of contents:', error);
}
});
function generateTableOfContents() {
const headings = document.querySelectorAll('main h2, main h3');
const tocList = document.getElementById('toc-list');
if (!tocList || headings.length === 0) return;
tocList.innerHTML = '';
headings.forEach(function(heading, index) {
const id = heading.id || `heading-${index}`;
if (!heading.id) {
heading.id = id;
}
const li = document.createElement('li');
const a = document.createElement('a');
a.href = `#${id}`;
a.textContent = heading.textContent;
a.setAttribute('aria-label', `Jump to ${heading.textContent}`);
if (heading.tagName === 'H3') {
li.style.marginLeft = '1rem';
li.style.fontSize = '0.9em';
}
li.appendChild(a);
tocList.appendChild(li);
});
}
// Smooth scrolling for anchor links
document.addEventListener('click', function(e) {
if (e.target.tagName === 'A' && e.target.getAttribute('href').startsWith('#')) {
e.preventDefault();
const target = document.querySelector(e.target.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
// Add copy button to code blocks
document.querySelectorAll('pre code, .highlight pre').forEach(function(block) {
const button = document.createElement('button');
button.textContent = 'Copy';
button.className = 'copy-button';
button.style.cssText = `
position: absolute;
top: 0.5rem;
right: 0.5rem;
background: rgba(139, 61, 255, 0.8);
color: white;
border: none;
padding: 0.25rem 0.5rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.8rem;
opacity: 0;
transition: opacity 0.3s ease;
`;
const pre = block.parentElement;
pre.style.position = 'relative';
pre.appendChild(button);
pre.addEventListener('mouseenter', function() {
button.style.opacity = '1';
});
pre.addEventListener('mouseleave', function() {
button.style.opacity = '0';
});
button.addEventListener('click', function() {
navigator.clipboard.writeText(block.textContent).then(function() {
button.textContent = 'Copied!';
setTimeout(function() {
button.textContent = 'Copy';
}, 2000);
});
});
});
</script>
</body>
</html>