diff --git a/examples/supabase-chat/.env.local.example b/examples/supabase-chat/.env.local.example index 9fe1d19c7..5d8759a8f 100644 --- a/examples/supabase-chat/.env.local.example +++ b/examples/supabase-chat/.env.local.example @@ -3,3 +3,9 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key OPENROUTER_API_KEY=sk-or-v1-... # Optional: defaults to openai/gpt-5.5 # OPENROUTER_MODEL=openai/gpt-5.5 + +# OrcaRouter — Anthropic-compatible AI gateway (https://www.orcarouter.ai) +# Setting ORCAROUTER_API_KEY routes the example through OrcaRouter instead of +# OpenRouter (base URL https://api.orcarouter.ai/v1 is applied automatically): +# ORCAROUTER_API_KEY=sk-orca-... +# ORCAROUTER_MODEL=anthropic/claude-haiku-4.5 diff --git a/examples/supabase-chat/README.md b/examples/supabase-chat/README.md index bb6980dde..42e6541a6 100644 --- a/examples/supabase-chat/README.md +++ b/examples/supabase-chat/README.md @@ -68,6 +68,10 @@ cp .env.local.example .env.local | `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Supabase dashboard → Settings → API → anon/public key | | `OPENROUTER_API_KEY` | [openrouter.ai/keys](https://openrouter.ai/keys) | | `OPENROUTER_MODEL` _(optional)_ | Defaults to `openai/gpt-5.5` | +| `ORCAROUTER_API_KEY` _(optional)_ | Setting this routes the example through [OrcaRouter](https://www.orcarouter.ai) instead of OpenRouter | +| `ORCAROUTER_MODEL` _(optional)_ | Defaults to `anthropic/claude-haiku-4.5` | + +> Using [OrcaRouter](https://www.orcarouter.ai)? Set `ORCAROUTER_API_KEY` (and optionally `ORCAROUTER_MODEL`) and the example streams Claude models through the same OpenAI-compatible client — no code changes needed. ### 5. Install and run diff --git a/examples/supabase-chat/src/app/api/chat/route.ts b/examples/supabase-chat/src/app/api/chat/route.ts index abc679728..ccfa86e72 100644 --- a/examples/supabase-chat/src/app/api/chat/route.ts +++ b/examples/supabase-chat/src/app/api/chat/route.ts @@ -3,7 +3,15 @@ import { NextRequest } from "next/server"; import OpenAI from "openai"; import type { ChatCompletionMessageParam } from "openai/resources/chat/completions.mjs"; -const MODEL = process.env.OPENROUTER_MODEL ?? "openai/gpt-5.5"; +// Gateway selection. OpenRouter (https://openrouter.ai/api/v1) is the default; +// setting ORCAROUTER_API_KEY routes the example through OrcaRouter +// (https://api.orcarouter.ai/v1) — an Anthropic-compatible AI gateway — using +// the same OpenAI-compatible client. See .env.local.example for both options. +const ORCAROUTER_ENABLED = Boolean(process.env.ORCAROUTER_API_KEY); + +const MODEL = ORCAROUTER_ENABLED + ? process.env.ORCAROUTER_MODEL ?? "anthropic/claude-haiku-4.5" + : process.env.OPENROUTER_MODEL ?? "openai/gpt-5.5"; /** * POST /api/chat @@ -24,8 +32,12 @@ export async function POST(req: NextRequest) { const supabase = await createSupabaseServer(); const client = new OpenAI({ - apiKey: process.env.OPENROUTER_API_KEY, - baseURL: "https://openrouter.ai/api/v1", + apiKey: ORCAROUTER_ENABLED + ? process.env.ORCAROUTER_API_KEY + : process.env.OPENROUTER_API_KEY, + baseURL: ORCAROUTER_ENABLED + ? "https://api.orcarouter.ai/v1" + : "https://openrouter.ai/api/v1", }); const stream = await client.chat.completions.create({