Repository navigation
feat: add AIMLAPI (aimlapi.com) as a model provider - #17311
Conversation
Register aimlapi.com in the provider catalog (conf/llm_factories.json) with OpenAI-compatible LiteLLM adapters (chat, embedding, image2text), dynamic /v1/models listing (rag/llm/model_meta.py AIMLAPI, classified by endpoint type), and the AIMLAPI agent-authorization endpoints (OAuth 2.0 device grant, api/apps/restful_apis/aimlapi_api.py). Production defaults; base_url and partner id are env-overridable (AIMLAPI_API_URL / AIMLAPI_PARTNER_ID).
… API key) Register aimlapi.com in the provider settings: constants + svg-icon allowlist, LIST_MODEL_PROVIDERS + a buildLocalConfig entry so the dynamic /v1/models picker shows the full catalog, and a data-driven logo. Add the OAuth device-grant "Get API key" button (owned hook + component) wired into the draft provider card, plus the authorize endpoints. Recommended badge + aimlapi-first ordering on the Available models list. Require at least one selected model before saving a list-model provider. i18n en + zh.
The provider logo is data-driven via LlmIcon (renders the SVG as an <img>), so the near-black placeholder mark was invisible on the dark provider cards and fell back to the generic icon. Ship the brand logo SVG (black badge + white hexagon/pulse mark) that reads on both light and dark backgrounds.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds AIMLAPI as a supported provider, including model metadata, LiteLLM wrappers, OAuth device authorization, Redis-backed polling, frontend key acquisition, provider configuration, UI presentation, and documentation. ChangesAIMLAPI provider integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant AimlapiGetKeyButton
participant useAimlapiAuthorize
participant RAGFlowAPI
participant AIMLAPI
participant Redis
User->>AimlapiGetKeyButton: Start authorization
AimlapiGetKeyButton->>useAimlapiAuthorize: start()
useAimlapiAuthorize->>RAGFlowAPI: POST authorization start
RAGFlowAPI->>AIMLAPI: Create device authorization
RAGFlowAPI->>Redis: Store device code and user ID
RAGFlowAPI-->>useAimlapiAuthorize: request ID and verification URI
useAimlapiAuthorize->>AIMLAPI: User completes consent in popup
useAimlapiAuthorize->>RAGFlowAPI: Poll authorization status
RAGFlowAPI->>Redis: Load device authorization
RAGFlowAPI->>AIMLAPI: Exchange device code
RAGFlowAPI-->>useAimlapiAuthorize: API key or status
useAimlapiAuthorize-->>AimlapiGetKeyButton: Update status and key
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)conf/llm_factories.jsonTraceback (most recent call last): Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| @@ -0,0 +1,192 @@ | |||
| # | |||
| # Copyright 2024 The InfiniFlow Authors. All Rights Reserved. | |||
|
RAGFlow is shifting to a Go-first architecture. New features and long-term maintenance will focus on the Go version. Sould you consider contributing the same provider to the Go codebase, as well? |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
api/apps/restful_apis/aimlapi_api.py (1)
96-141: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd logging for the success paths of this new flow.
Only failure paths are logged (
LOGGER.warningon non-2xx responses). Per repo conventions for new flows, consider addingLOGGER.infoon successful authorize-start (withrequest_id, no PII) and on poll-ready, to aid observability/debugging of this new OAuth device-grant flow in production.As per path instructions, "
**/*.py: Add logging for new flows."Also applies to: 177-192
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/apps/restful_apis/aimlapi_api.py` around lines 96 - 141, Add LOGGER.info success logs to the new OAuth device-grant flow: log authorize-start completion after validating and storing the request in the authorization-start handler, including request_id only and no PII. Also log when the polling handler reaches the ready/success state, using the existing request identifier where available. Keep existing failure logging unchanged.Source: Path instructions
web/src/pages/user-setting/setting-model/instance-card/aimlapi-get-key-button.tsx (2)
11-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename the top-level constant to PascalCase.
STATUS_TEXT_KEYshould use PascalCase, e.g.AimlapiStatusTextKey.As per coding guidelines: “Use PascalCase for React component names and top-level constants.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/pages/user-setting/setting-model/instance-card/aimlapi-get-key-button.tsx` around lines 11 - 17, Rename the top-level constant STATUS_TEXT_KEY to AimlapiStatusTextKey and update every reference to it, preserving its type and status-to-text mappings.Source: Coding guidelines
2-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
useTranslationdirectly.Replace the project wrapper with
useTranslation('setting').Proposed fix
-import { useTranslate } from '`@/hooks/common-hooks`'; +import { useTranslation } from 'react-i18next'; @@ - const { t } = useTranslate('setting'); + const { t } = useTranslation('setting');As per coding guidelines: “Prefer
useTranslationfromreact-i18nextover project-wrapped utilities such asuseTranslate.”Also applies to: 27-27
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/pages/user-setting/setting-model/instance-card/aimlapi-get-key-button.tsx` at line 2, Replace the useTranslate wrapper import and usage in the aimlapi key button component with useTranslation from react-i18next, passing the 'setting' namespace. Update all affected translation calls, including the second referenced usage, while preserving their existing keys and behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/apps/restful_apis/aimlapi_api.py`:
- Around line 83-95: Update the request-body handling around get_request_json so
only dictionary bodies are accepted before reading return_url, avoiding
attribute errors for arrays or other JSON types. Validate the client-provided
return_url in this flow and use it only when it matches the trusted verification
destination; otherwise fall back to _verification_base_url() before assigning
payload["returnUrl"].
In `@conf/llm_factories.json`:
- Around line 11-24: Consolidate the duplicate aimlapi.com entry for
openai/gpt-4o into one record using the file’s array-based model_type
convention, including both chat and image2text capabilities, and remove the
redundant image2text-only record. Update openai/gpt-4o-mini’s model_type to an
array that matches its existing IMAGE2TEXT tag while retaining chat support.
In `@web/src/hooks/use-aimlapi-authorize.ts`:
- Around line 134-149: Validate that both requestId and verificationUri are
present immediately after destructuring the start response in
useAimlapiAuthorize, before assigning refs, navigating the popup, or entering
the awaiting_consent flow. Treat a missing value as an invalid response and
follow the hook’s existing error-handling path instead of continuing with an
undefined request ID.
---
Nitpick comments:
In `@api/apps/restful_apis/aimlapi_api.py`:
- Around line 96-141: Add LOGGER.info success logs to the new OAuth device-grant
flow: log authorize-start completion after validating and storing the request in
the authorization-start handler, including request_id only and no PII. Also log
when the polling handler reaches the ready/success state, using the existing
request identifier where available. Keep existing failure logging unchanged.
In
`@web/src/pages/user-setting/setting-model/instance-card/aimlapi-get-key-button.tsx`:
- Around line 11-17: Rename the top-level constant STATUS_TEXT_KEY to
AimlapiStatusTextKey and update every reference to it, preserving its type and
status-to-text mappings.
- Line 2: Replace the useTranslate wrapper import and usage in the aimlapi key
button component with useTranslation from react-i18next, passing the 'setting'
namespace. Update all affected translation calls, including the second
referenced usage, while preserving their existing keys and behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 34bbb7d9-17de-46c7-abc4-ff273119dc5c
⛔ Files ignored due to path filters (1)
web/src/assets/svg/llm/aimlapi.svgis excluded by!**/*.svg
📒 Files selected for processing (22)
api/apps/restful_apis/aimlapi_api.pyconf/llm_factories.jsondocs/guides/models/supported_models.mdxrag/llm/__init__.pyrag/llm/chat_model.pyrag/llm/cv_model.pyrag/llm/embedding_model.pyrag/llm/model_meta.pyweb/src/components/svg-icon.tsxweb/src/constants/llm.tsweb/src/hooks/use-aimlapi-authorize.tsweb/src/locales/en.tsweb/src/locales/zh.tsweb/src/pages/user-setting/setting-model/instance-card/aimlapi-get-key-button.tsxweb/src/pages/user-setting/setting-model/instance-card/available-models.tsxweb/src/pages/user-setting/setting-model/instance-card/components/draft-mode-card.tsxweb/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsxweb/src/pages/user-setting/setting-model/provider-schema/constants.tsweb/src/pages/user-setting/setting-model/provider-schema/field-config/local-llm-configs.tsweb/src/services/llm-service.tsweb/src/utils/api.tsweb/src/utils/common-util.ts
Okay, we can look at adding this to the Go version in a |
Backend:
- llm_factories: collapse the duplicate openai/gpt-4o rows into a single
entry with an array model_type (["chat","image2text"]) and tag
gpt-4o-mini for vision too, matching the file's dual-capability
convention (the duplicate rows collide on merge-by-name at seed load).
- authorize/start: stop forwarding a client-supplied return_url to AIMLAPI
(open-redirect surface) and drop the non-dict body access; always use
the trusted verification host. The flow never depends on the
post-consent redirect — the key arrives via authenticated polling and
the popup is closed on success.
- log authorize-start success and poll-ready (request_id only, no PII).
- bump the new file's copyright header to 2026.
Frontend:
- use-aimlapi-authorize: drop the now-unused return_url argument and guard
a malformed start response (missing request_id / verification_uri)
instead of polling with an undefined id.
- aimlapi-get-key-button: use useTranslation('translation', { keyPrefix })
directly and rename the top-level constant to PascalCase, per the
frontend conventions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17311 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…17491) ### Summary The **aimlapi.com** provider added in #17311 does not identify itself on any of its outgoing requests, so its traffic cannot be attributed to the integration. This PR adds the two headers AIMLAPI expects — `X-AIMLAPI-Source` and `X-AIMLAPI-Partner-ID` — to every request the provider makes.
…nfiniflow#17491) ### Summary The **aimlapi.com** provider added in infiniflow#17311 does not identify itself on any of its outgoing requests, so its traffic cannot be attributed to the integration. This PR adds the two headers AIMLAPI expects — `X-AIMLAPI-Source` and `X-AIMLAPI-Partner-ID` — to every request the provider makes.
Summary
This PR adds aimlapi.com as a model provider, so a RAGFlow user can enter one API key in the model settings and use AIMLAPI's models across the app. AIMLAPI (aimlapi.com) is an OpenAI-compatible aggregator that serves 700+ models (LLM, embedding, vision, TTS, ASR) from many providers behind a single API.
The change mirrors the repo's existing "add provider" pattern (e.g. FuturMix / OpenRouter): provider logic lives in the same files those providers use, and shared / UI files get only registration entries.
Backend
conf/llm_factories.json— theaimlapi.comfactory entry.rag/llm/__init__.py,rag/llm/{chat,embedding,cv}_model.py— LiteLLM adapters (chat, embedding, image2text) with a production base URL, overridable viaAIMLAPI_API_URL.rag/llm/model_meta.py— anAIMLAPImodel-meta so the provider lists its full/v1/modelscatalog dynamically (classified by the endpointtype), the same way OpenRouter does.api/apps/restful_apis/aimlapi_api.py— an optional "Get API key" flow using AIMLAPI's agent-authorization (OAuth 2.0 Device Authorization Grant, RFC 8628). The device code is kept server-side (Redis); only the issued key reaches the browser.Frontend (
web/)LIST_MODEL_PROVIDERS+ abuildLocalConfigentry), and the "Get API key" button in the provider dialog. Locales added toenandzh.Configuration — production defaults are compiled in; endpoints and the partner id are overridable through
AIMLAPI_*environment variables, so the same build works across environments.Testing — the
webbuild passes; chat, embedding and dynamic model listing were smoke-tested against the live API.