Railyard side of PY1.4 (ADR RY-0003). Acceptance: 1. Bridge `ai` gives a Scribase project environment one key (ry_ai_..., shown once, to the Scribase control plane only, stored here as SHA-256; `rotate` revokes the old one) and a one-time link to /connect/ai (15 minutes), the only place a provider key is typed. It is sealed with AES-256-GCM under RAILYARD_CREDENTIALS_KEY, bound to org and provider, and only a four-character hint is ever read back. 2. BYOK only: POST /api/v1/ai/chat/completions (OpenAI-compatible) refuses with 403 byok_required when the org has not connected the provider the model names, and never calls Relay then. When it does call, the customer's key fills that provider's slot and every other slot carries a refusal marker, so Relay (caller credential wins) can never use our keys, not even on failover; a test pins the slot list to Relay's PROVIDER_KEY_SLOTS. Credentials in a request body are refused. 3. Daily and monthly token caps per key (429 with the period); usage (atomic rpc) and one trace per call (model, provider, status, tokens, latency), read per project key by the bridge `ai_usage` route for the Scribase tab; Relay traces carry tensorzero::tags for the same filter. 4. Copy says "your provider bills you directly"; no credits are included anywhere (copy lint over the connect page and every gateway message). apps/relay/config/tenants/README.md records the tenant rules. Migration: apps/console/db/migrations/0003_ai_gateway.sql (idempotent; applied twice to a scratch local cluster by test/migration.test.ts). Env: RELAY_URL (var), RELAY_TENANT_KEY, RAILYARD_CREDENTIALS_KEY (secrets). Tests: console 63/63 (gateway 6, bridge 12, migration 3, repo 5), tsc clean, tests/contract 3/3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.5 KiB
TypeScript
53 lines
2.5 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
const PROVIDERS = [
|
|
{ id: "anthropic", label: "Anthropic" },
|
|
{ id: "openai", label: "OpenAI" },
|
|
{ id: "groq", label: "Groq" },
|
|
{ id: "openrouter", label: "OpenRouter" },
|
|
];
|
|
|
|
// The secure connect page for the AI gateway (PY1.4). The link from the
|
|
// terminal works once for 15 minutes. The provider key is sealed before it is
|
|
// stored and is never shown again; your provider bills you directly.
|
|
export default function ConnectAiPage({ searchParams }: { searchParams: { t?: string; done?: string; hint?: string; error?: string } }) {
|
|
const done = PROVIDERS.find((p) => p.id === searchParams.done);
|
|
return (
|
|
<main className="center">
|
|
<section className="card" style={{ width: 460 }}>
|
|
<h1>Connect an AI provider</h1>
|
|
{done ? (
|
|
<p>
|
|
{done.label} is connected (key ending {searchParams.hint ?? ""}). Go back to your terminal. Your provider bills you directly.
|
|
</p>
|
|
) : searchParams.t ? (
|
|
<form method="post" action="/api/connect/ai" className="stack" autoComplete="off">
|
|
<input type="hidden" name="t" value={searchParams.t} />
|
|
<label>
|
|
Provider
|
|
<select name="provider" required defaultValue="anthropic">
|
|
{PROVIDERS.map((p) => (
|
|
<option key={p.id} value={p.id}>
|
|
{p.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Provider key
|
|
<input type="password" name="key" required minLength={8} autoComplete="off" spellCheck={false} aria-label="Provider key" />
|
|
</label>
|
|
<button className="primary" type="submit">Connect</button>
|
|
<p className="muted">Sealed before it is stored and never shown again. Calls use only this key; your provider bills you directly.</p>
|
|
</form>
|
|
) : (
|
|
<p className="muted">Open this page from the link your terminal printed.</p>
|
|
)}
|
|
{searchParams.error === "expired" ? <p className="error">This link was used already or expired. Start again from your terminal.</p> : null}
|
|
{searchParams.error === "invalid" ? <p className="error">That did not work. Check the provider and the key, then try again.</p> : null}
|
|
{searchParams.error === "not_configured" ? <p className="error">The AI gateway is not set up on this deployment yet.</p> : null}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|