Skip to content

feat(ai-gateway): mirror synced providers to Redis and fetch /api/v1/providers#2555

Open
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
feat/sync-providers-redis-cache
Open

feat(ai-gateway): mirror synced providers to Redis and fetch /api/v1/providers#2555
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
feat/sync-providers-redis-cache

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot bot commented Apr 17, 2026

Summary

  • syncAndStoreProviders now also downloads the public OpenRouter provider list from https://openrouter.ai/api/v1/providers and persists it to models_by_provider.openrouter_providers (new jsonb column).
  • After the DB transaction succeeds, all four payloads (providers, openrouter, vercel, openrouter_providers) are mirrored to Redis under fixed keys. Writes are best-effort and do not block the DB write.
  • No consumers read from Redis yet — that will land in a follow-up.

Verification

  • pnpm typecheck
  • pnpm lint
  • pnpm format
  • pnpm drizzle generate produced a clean one-line migration (ADD COLUMN openrouter_providers jsonb).

Visual Changes

N/A

Reviewer Notes

  • New Redis key prefix is ai-gateway.sync-providers.*; no TTL since the job overwrites them on every run.
  • The /api/v1/providers response is validated with a new OpenRouterApiProvidersResponse zod schema in packages/db/src/schema-types.ts.
  • A < 10 sanity check is enforced on the provider list to match the existing guards for the other synced data.

…providers

Extends syncAndStoreProviders to also download the public OpenRouter
provider list from /api/v1/providers, persist it alongside the other
synced data in the models_by_provider table, and mirror all four payloads
to Redis so future read paths can avoid a database round-trip.

Redis writes are best-effort and do not block the transaction. Consumers
are not wired up yet.

const openrouter_data = await fetchGatewayModels(PROVIDERS.OPENROUTER);
const vercel_data = await fetchGatewayModels(PROVIDERS.VERCEL_AI_GATEWAY);
const openrouter_providers = await fetchOpenRouterApiProviders();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Ancillary provider fetch now blocks the main sync

openrouter_providers is new data with no readers yet, but this call happens before the existing snapshot write and the later < 10 guard throws if /api/v1/providers is unavailable or malformed. That means a temporary issue in the new endpoint can prevent the already-consumed data, openrouter, and vercel payloads from refreshing at all. Consider making this fetch best-effort or persisting it separately so the primary sync can still succeed.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Apr 17, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/web/src/lib/ai-gateway/providers/openrouter/openrouter-types.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers.ts
  • packages/db/src/schema-types.ts

Reviewed by gpt-5.4-20260305 · 1,149,984 tokens

kilo-code-bot bot added 2 commits April 17, 2026 14:49
Addresses review feedback: a failure in the ancillary /api/v1/providers
fetch must not prevent the primary openrouter/vercel/providers snapshot
from refreshing. Log the error and persist NULL instead.
Removes the DB migration and column for openrouter_providers. The data
from /api/v1/providers is still fetched during sync and mirrored to
Redis, but no longer persisted to Postgres.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant