import{_ as a,c as s,o as i,ah as e}from"./chunks/framework.BJEpWshW.js";const k=JSON.parse('{"title":"API 概览","description":"","frontmatter":{},"headers":[],"relativePath":"api/overview.md","filePath":"api/overview.md"}'),d={name:"api/overview.md"};function n(l,t,h,o,r,p){return i(),s("div",null,[...t[0]||(t[0]=[e(`<h1 id="api-概览" tabindex="-1">API 概览 <a class="header-anchor" href="#api-概览" aria-label="Permalink to “API 概览”">​</a></h1><p>WebAI2API 提供兼容 OpenAI 格式的 RESTful API。</p><h2 id="基础信息" tabindex="-1">基础信息 <a class="header-anchor" href="#基础信息" aria-label="Permalink to “基础信息”">​</a></h2><ul><li><strong>Base URL</strong>: <code>http://localhost:3000</code></li><li><strong>认证方式</strong>: Bearer Token</li></ul><h3 id="请求头" tabindex="-1">请求头 <a class="header-anchor" href="#请求头" aria-label="Permalink to “请求头”">​</a></h3><div class="language-http"><button title="Copy Code" class="copy"></button><span class="lang">http</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">Authorization</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Bearer sk-your-secret-key</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">Content-Type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> application/json</span></span></code></pre></div><h2 id="api-端点列表" tabindex="-1">API 端点列表 <a class="header-anchor" href="#api-端点列表" aria-label="Permalink to “API 端点列表”">​</a></h2><h3 id="openai-兼容接口" tabindex="-1">OpenAI 兼容接口 <a class="header-anchor" href="#openai-兼容接口" aria-label="Permalink to “OpenAI 兼容接口”">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>端点</th><th>说明</th></tr></thead><tbody><tr><td>POST</td><td><code>/v1/chat/completions</code></td><td>对话生成</td></tr><tr><td>GET</td><td><code>/v1/models</code></td><td>获取模型列表</td></tr><tr><td>GET</td><td><code>/v1/cookies</code></td><td>获取 Cookie</td></tr></tbody></table><h3 id="管理接口" tabindex="-1">管理接口 <a class="header-anchor" href="#管理接口" aria-label="Permalink to “管理接口”">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>端点</th><th>说明</th></tr></thead><tbody><tr><td>GET</td><td><code>/admin/status</code></td><td>服务状态</td></tr><tr><td>GET</td><td><code>/admin/stats</code></td><td>统计信息</td></tr><tr><td>GET</td><td><code>/admin/queue</code></td><td>队列状态</td></tr><tr><td>POST</td><td><code>/admin/restart</code></td><td>重启服务</td></tr><tr><td>POST</td><td><code>/admin/stop</code></td><td>停止服务</td></tr><tr><td>GET</td><td><code>/admin/vnc/status</code></td><td>VNC 状态</td></tr><tr><td>POST</td><td><code>/admin/cache/clear</code></td><td>清理缓存</td></tr></tbody></table><h2 id="错误响应" tabindex="-1">错误响应 <a class="header-anchor" href="#错误响应" aria-label="Permalink to “错误响应”">​</a></h2><p>所有 API 错误返回统一格式：</p><div class="language-json"><button title="Copy Code" class="copy"></button><span class="lang">json</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  &quot;error&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    &quot;message&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;错误描述&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    &quot;type&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;error_type&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    &quot;code&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;ERROR_CODE&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3 id="常见错误码" tabindex="-1">常见错误码 <a class="header-anchor" href="#常见错误码" aria-label="Permalink to “常见错误码”">​</a></h3><table tabindex="0"><thead><tr><th>HTTP 状态码</th><th>错误类型</th><th>说明</th></tr></thead><tbody><tr><td>401</td><td><code>unauthorized</code></td><td>认证失败</td></tr><tr><td>400</td><td><code>invalid_request</code></td><td>请求参数错误</td></tr><tr><td>404</td><td><code>not_found</code></td><td>资源不存在</td></tr><tr><td>429</td><td><code>rate_limit</code></td><td>请求过多</td></tr><tr><td>500</td><td><code>internal_error</code></td><td>服务器内部错误</td></tr><tr><td>503</td><td><code>service_unavailable</code></td><td>服务不可用</td></tr></tbody></table><h2 id="流式响应" tabindex="-1">流式响应 <a class="header-anchor" href="#流式响应" aria-label="Permalink to “流式响应”">​</a></h2><p>对于 <code>stream: true</code> 的请求，响应使用 Server-Sent Events (SSE) 格式：</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span>data: {&quot;id&quot;:&quot;...&quot;,&quot;object&quot;:&quot;chat.completion.chunk&quot;,...}</span></span>
<span class="line"><span></span></span>
<span class="line"><span>: keep-alive</span></span>
<span class="line"><span></span></span>
<span class="line"><span>data: {&quot;id&quot;:&quot;...&quot;,&quot;object&quot;:&quot;chat.completion.chunk&quot;,...}</span></span>
<span class="line"><span></span></span>
<span class="line"><span>data: [DONE]</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">心跳保活</p><p>流式请求会自动发送心跳包防止连接超时，格式取决于配置的 <code>keepalive.mode</code>。</p></div><h2 id="相关文档" tabindex="-1">相关文档 <a class="header-anchor" href="#相关文档" aria-label="Permalink to “相关文档”">​</a></h2><ul><li><a href="/api/chat.html">Chat Completions</a> - 对话生成接口详解</li><li><a href="/api/models.html">Models</a> - 模型列表接口</li><li><a href="/api/cookies.html">Cookies</a> - Cookie 获取接口</li></ul>`,22)])])}const u=a(d,[["render",n]]);export{k as __pageData,u as default};
