|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed } from 'vue' |
| 3 | +import { useI18n } from 'vue-i18n' |
| 4 | +const { locale } = useI18n() |
| 5 | +const isZh = computed(() => locale.value === 'zh') |
| 6 | +</script> |
| 7 | + |
| 8 | +<template> |
| 9 | + <div class="prose prose-invert max-w-none"> |
| 10 | + <template v-if="isZh"> |
| 11 | + <h1>OpenAI 兼容 API</h1> |
| 12 | + <p> |
| 13 | + Router 完整兼容 OpenAI API 格式,支持 <code>/v1/chat/completions</code> 和新增的 |
| 14 | + <code>/v1/responses</code> 端点。无论使用哪个后端 Provider,客户端都能以标准 OpenAI SDK 进行调用。 |
| 15 | + </p> |
| 16 | + |
| 17 | + <h2>支持的端点</h2> |
| 18 | + <table> |
| 19 | + <thead><tr><th>端点</th><th>说明</th></tr></thead> |
| 20 | + <tbody> |
| 21 | + <tr><td><code>/v1/chat/completions</code></td><td>标准 Chat Completions API(始终支持)</td></tr> |
| 22 | + <tr><td><code>/v1/responses</code></td><td>OpenAI Responses API(v0.9.2 新增)</td></tr> |
| 23 | + </tbody> |
| 24 | + </table> |
| 25 | + |
| 26 | + <h2>Provider Patch 重写</h2> |
| 27 | + <p> |
| 28 | + Router 内置 Provider Patch 机制,自动将 OpenAI 格式的请求转换为各 Provider 的原生格式, |
| 29 | + 并将响应转回 OpenAI 兼容格式。支持流式和非流式。 |
| 30 | + </p> |
| 31 | + <div class="not-prose my-4 rounded-lg border border-white/10 bg-surface-50 p-4"> |
| 32 | + <code class="text-sm font-mono text-gray-300 block leading-loose"> |
| 33 | + OpenAI SDK 请求 → Router 接收<br> |
| 34 | + → Provider Patch 转换(OpenAI → 供应商原生格式)<br> |
| 35 | + → 发送到供应商<br> |
| 36 | + → 响应 Patch 转换(供应商格式 → OpenAI)<br> |
| 37 | + → 返回给客户端 |
| 38 | + </code> |
| 39 | + </div> |
| 40 | + |
| 41 | + <h2>Response Cleaner</h2> |
| 42 | + <p> |
| 43 | + 自动清理供应商响应中的非标准字段,确保返回的 JSON 结构与 OpenAI 规范一致,避免客户端解析错误。 |
| 44 | + </p> |
| 45 | + |
| 46 | + <h2>使用方式</h2> |
| 47 | + <p> |
| 48 | + 客户端无需任何修改,将 <code>base_url</code> 指向 Router 即可。 |
| 49 | + 例如:<code>http://localhost:9981/v1</code>。Claude Code、Cursor、OpenAI SDK 等均可直接使用。 |
| 50 | + </p> |
| 51 | + </template> |
| 52 | + |
| 53 | + <template v-else> |
| 54 | + <h1>OpenAI Compatible API</h1> |
| 55 | + <p> |
| 56 | + The Router is fully compatible with OpenAI API format, supporting both |
| 57 | + <code>/v1/chat/completions</code> and the new <code>/v1/responses</code> endpoint. |
| 58 | + Clients use the standard OpenAI SDK regardless of the backend provider. |
| 59 | + </p> |
| 60 | + |
| 61 | + <h2>Supported Endpoints</h2> |
| 62 | + <table> |
| 63 | + <thead><tr><th>Endpoint</th><th>Description</th></tr></thead> |
| 64 | + <tbody> |
| 65 | + <tr><td><code>/v1/chat/completions</code></td><td>Standard Chat Completions API (always supported)</td></tr> |
| 66 | + <tr><td><code>/v1/responses</code></td><td>OpenAI Responses API (new in v0.9.2)</td></tr> |
| 67 | + </tbody> |
| 68 | + </table> |
| 69 | + |
| 70 | + <h2>Provider Patch Rewrite</h2> |
| 71 | + <p> |
| 72 | + The Router has a built-in Provider Patch mechanism that automatically converts |
| 73 | + OpenAI-format requests to each Provider's native format, and converts responses back |
| 74 | + to OpenAI-compatible format. Both streaming and non-streaming are supported. |
| 75 | + </p> |
| 76 | + <div class="not-prose my-4 rounded-lg border border-white/10 bg-surface-50 p-4"> |
| 77 | + <code class="text-sm font-mono text-gray-300 block leading-loose"> |
| 78 | + OpenAI SDK request → Router receives<br> |
| 79 | + → Provider Patch (OpenAI → Provider native format)<br> |
| 80 | + → Send to Provider<br> |
| 81 | + → Response Patch (Provider format → OpenAI)<br> |
| 82 | + → Return to client |
| 83 | + </code> |
| 84 | + </div> |
| 85 | + |
| 86 | + <h2>Response Cleaner</h2> |
| 87 | + <p> |
| 88 | + Automatically strips non-standard fields from provider responses, ensuring |
| 89 | + returned JSON matches the OpenAI spec and avoiding client-side parse errors. |
| 90 | + </p> |
| 91 | + |
| 92 | + <h2>Usage</h2> |
| 93 | + <p> |
| 94 | + No client-side changes needed — point <code>base_url</code> to the Router. |
| 95 | + Example: <code>http://localhost:9981/v1</code>. Works with Claude Code, Cursor, OpenAI SDK, etc. |
| 96 | + </p> |
| 97 | + </template> |
| 98 | + </div> |
| 99 | +</template> |
0 commit comments