Skip to content

feat: add API Route as AI provider - #144

Merged
nullure merged 1 commit into
CaviraOSS:mainfrom
DennyHo0917:feat/api-route-provider
Sep 19, 2026
Merged

nullure merged 1 commit into
CaviraOSS:mainfrom
DennyHo0917:feat/api-route-provider

Conversation

@DennyHo0917

Copy link
Copy Markdown
Contributor

Summary

Adds API Route as an AI model and embeddings provider alongside Gemini, OpenAI, Claude, Grok, Ollama, OpenRouter, and MiniMax.

API Route provides high-speed, reliable OpenAI-compatible API routing:

  • Default model: gpt-5.4-mini — fast, high-capability inference for study note generation, quizzes, and chat
  • Base URL: https://www.api-route.com/v1 (configurable via API_ROUTE_BASE_URL)

Changes

  • New file: backend/src/utils/llm/models/apiroute.ts — API Route provider using ChatOpenAI and OpenAIEmbeddings from @langchain/openai
  • Updated: backend/src/utils/llm/models/index.ts — added apiroute (and api_route, api-route aliases) to the model factory pick() switch
  • Updated: backend/src/config/env.ts — added API_ROUTE_API_KEY, API_ROUTE_MODEL, and API_ROUTE_BASE_URL configuration variables
  • Updated: .env.example — added API Route configuration block and updated LLM_PROVIDER documentation
  • Updated: README.md — added API Route to Supported AI Models list
  • New tests:
    • backend/src/utils/llm/models/__tests__/apiroute.test.ts — 13 unit tests covering model selection, custom baseURL, temperature clamping, token limits, and API key fallback
    • backend/src/utils/llm/models/__tests__/apiroute-factory.test.ts — 4 integration tests verifying provider selection, alias matching, embeddings fallback, and isolation

How it works

API Route is fully compatible with OpenAI API specifications, allowing seamless reuse of ChatOpenAI and OpenAIEmbeddings from @langchain/openai. Temperature is clamped to [0, 2].

Configuration

LLM_PROVIDER=apiroute
API_ROUTE_API_KEY=your-api-key
API_ROUTE_MODEL=gpt-5.4-mini

Test plan

  • 13 unit tests for makeLLM() and makeEmbeddings() in apiroute.test.ts
  • 4 factory integration tests in apiroute-factory.test.ts
  • Full test suite verification (npx vitest run: 32 passed, 0 failed)
  • Backend TypeScript build check (npm run build / tsc -p backend/tsconfig.json: 0 errors)

@nullure nullure left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@nullure
nullure merged commit 4b60fe5 into CaviraOSS:main Sep 19, 2026
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.

2 participants