fix(chat): route through LiteLLM gateway, default to protolabs/smart#3619
Conversation
## Why Ava chat was unusable: Anthropic returned `rate_limit_error` with no useful message on every call. The chat path was going direct to api.anthropic.com via @ai-sdk/anthropic. The team direction is gateway-first: no Anthropic keys, no direct calls, everything routed through https://api.proto-labs.ai/v1. ## Changes - `apps/server/src/lib/ai-provider.ts` — rewrite to use `@ai-sdk/openai-compatible` pointed at the gateway. Auth chain: GATEWAY_API_KEY env > OPENAI_API_KEY env > settings credentials. Legacy Claude aliases (`sonnet`, `opus`, `haiku`, anything starting with `claude-`) get silently remapped to `protolabs/smart` so the UI's stored "sonnet" defaults don't blow up mid-migration. - `apps/server/src/routes/chat/index.ts` — default model alias goes from `'sonnet'` to `'protolabs/smart'`. Existing fall-back chain (header > body > avaConfig.model > default) is preserved. - `apps/server/package.json` — adds `@ai-sdk/openai-compatible`. ## Kept intentionally - Export name `getAnthropicModel` is unchanged. Renaming touches ~10 call sites and adds churn without behavior change. Follow-up. - `providerOptions.anthropic` block in chat/index.ts (extended thinking, contextManagement) stays as-is. The AI SDK ignores provider-specific options when the active provider doesn't match, so these are inert under openai-compatible. Cleanup in a follow-up. - The settings UI "Claude" provider tile and Anthropic credential field can be removed in a separate UI-side PR. They're currently inert because no code path consumes the Anthropic API key anymore. ## Validation - `tsc --noEmit` clean - Local smoke test against this branch's build: - server.log: `Gateway provider initialized: baseURL=https://api.proto-labs.ai/v1` - POST /api/chat with the broken-before payload now streams `reasoning-delta` and text tokens from `protolabs/smart` - The previous Anthropic rate_limit_error path is no longer reachable from /api/chat.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Code Review — ? finding(s)
protoLabs Code Review Report
No findings recorded. |
`n/no-extraneous-import` ESLint rule (enforced in CI's lint step) flagged the `LanguageModelV3` type import from @ai-sdk/provider as extraneous because we used a transitive dep without declaring it. Adds it to apps/server's dependencies. No runtime change.
Code Review — ? finding(s)
protoLabs Code Review Report
No findings recorded. |
Why
Ava chat was unusable — Anthropic returned
rate_limit_errorwith a useless"message":"Error"on every call. The chat path was going direct toapi.anthropic.comvia@ai-sdk/anthropic. The team direction is gateway-first: no Anthropic keys, no direct calls, everything routed throughhttps://api.proto-labs.ai/v1.This PR yanks the direct-Anthropic path out of chat.
Changes
apps/server/src/lib/ai-provider.ts— rewritten to use@ai-sdk/openai-compatiblepointed at the gateway. Auth chain:GATEWAY_API_KEYenvOPENAI_API_KEYenv (alias — gateway accepts both)apiKeys.protolabsGatewayfrom settings credentialsLegacy Claude aliases (
sonnet,opus,haiku, anything starting withclaude-) are silently remapped toprotolabs/smartso the UI's stored"sonnet"defaults don't blow up mid-migration.apps/server/src/routes/chat/index.ts— default model alias goes from'sonnet'→'protolabs/smart'. Existing fall-back chain (header > body > avaConfig.model > default) is preserved.apps/server/package.json— adds@ai-sdk/openai-compatible.Validation
Before this change, that same payload returned
rate_limit_errorandNoOutputGeneratedError. The previous Anthropic-direct path is no longer reachable from/api/chat.Kept intentionally (for follow-ups)
getAnthropicModelis unchanged. Renaming touches ~10 call sites with no behavior change. Rename in a follow-up.providerOptions.anthropicblock in chat/index.ts (extended thinking,contextManagement) stays as-is. The AI SDK ignores provider-specific options when the active provider doesn't match, so these are inert under openai-compatible. Cleanup later.Operational note
The server process needs
GATEWAY_API_KEYand (optionally)GATEWAY_BASE_URLin its environment. For host-process systemd (theautomaker-host.servicefrom PR #3617), drop them into/etc/systemd/system/automaker-host.service.d/override.conf:…or pipe from Infisical at deploy time.