From a518ce8f8a82cc8589a4e8e5af87b4d8db43968d Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Date: Fri, 3 Jul 2026 00:40:07 -0300 Subject: [PATCH] feat(providers): add Qiniu OpenAI-compatible provider (#5966) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(providers): add Qiniu OpenAI-compatible provider Wires Qiniu (七牛云) AI inference gateway as a BYOK API-key provider. Qiniu proxies many upstream models (DeepSeek V3/V4, Claude, Kimi and more) behind a single key, so it ships with an empty static seed and relies on passthroughModels + the live /v1/models catalog instead of a single stale hardcoded model id. - metadata: src/shared/constants/providers/apikey/gateways.ts - registry entry: open-sse/config/providers/registry/qiniu/index.ts (format openai, executor default, bearer auth, baseUrl https://api.qnaigc.com/v1/chat/completions, modelsUrl https://api.qnaigc.com/v1/models) - added to NAMED_OPENAI_STYLE_PROVIDERS so model import serves the live catalog and falls back to the (empty) local catalog on error, same pattern as the existing dgrid/zenmux/orcarouter gateways - tests: tests/unit/qiniu-provider.test.ts (metadata, registry resolution, passthrough validation, live /v1/models fetch + fallback) Co-authored-by: JiangZhuo Inspired-by: https://github.com/decolua/9router/pull/911 * chore(changelog): restore release entries + add qiniu bullet * test(golden): regenerate translate-path for qiniu provider * test(providers): bump APIKEY count 160β†’161 for qiniu --------- Co-authored-by: JiangZhuo --- CHANGELOG.md | 1 + open-sse/config/providers/index.ts | 2 + .../config/providers/registry/qiniu/index.ts | 15 ++ .../[id]/models/discovery/providerSets.ts | 4 + src/shared/constants/config.ts | 1 + .../constants/providers/apikey/gateways.ts | 14 ++ tests/snapshots/provider/translate-path.json | 23 +++ tests/unit/providers-constants-split.test.ts | 12 +- tests/unit/qiniu-provider.test.ts | 148 ++++++++++++++++++ 9 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 open-sse/config/providers/registry/qiniu/index.ts create mode 100644 tests/unit/qiniu-provider.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 92943a9e33..c095a17d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - **feat(providers):** add NVIDIA NIM image generation (FLUX models). (thanks @eng2007) - **feat(providers):** add Augment (Auggie CLI) as a local no-auth provider. (thanks @chamdanilukman) - **feat(providers):** add ModelScope as an OpenAI-compatible (API-key) provider. (thanks @tn5052) +- **feat(providers):** add Qiniu as an OpenAI-compatible (API-key) provider. (thanks @JackChiang233) ### πŸ”§ Bug Fixes diff --git a/open-sse/config/providers/index.ts b/open-sse/config/providers/index.ts index 32850c900f..17eb23d21b 100644 --- a/open-sse/config/providers/index.ts +++ b/open-sse/config/providers/index.ts @@ -41,6 +41,7 @@ import { yiProvider } from "./registry/yi/index.ts"; import { deepseekProvider } from "./registry/deepseek/index.ts"; import { deepseek_webProvider } from "./registry/deepseek/web/index.ts"; import { dgridProvider } from "./registry/dgrid/index.ts"; +import { qiniuProvider } from "./registry/qiniu/index.ts"; import { kimi_coding_apikeyProvider } from "./registry/kimi/coding-apikey/index.ts"; import { kimi_codingProvider } from "./registry/kimi/coding/index.ts"; import { kimiProvider } from "./registry/kimi/index.ts"; @@ -215,6 +216,7 @@ export const REGISTRY: Record = { deepseek: deepseekProvider, "deepseek-web": deepseek_webProvider, dgrid: dgridProvider, + qiniu: qiniuProvider, "kimi-coding-apikey": kimi_coding_apikeyProvider, "kimi-coding": kimi_codingProvider, kimi: kimiProvider, diff --git a/open-sse/config/providers/registry/qiniu/index.ts b/open-sse/config/providers/registry/qiniu/index.ts new file mode 100644 index 0000000000..1bbf5021d8 --- /dev/null +++ b/open-sse/config/providers/registry/qiniu/index.ts @@ -0,0 +1,15 @@ +import type { RegistryEntry } from "../../shared.ts"; + +export const qiniuProvider: RegistryEntry = { + id: "qiniu", + alias: "qiniu", + format: "openai", + executor: "default", + baseUrl: "https://api.qnaigc.com/v1/chat/completions", + authType: "apikey", + authHeader: "bearer", + modelsUrl: "https://api.qnaigc.com/v1/models", + defaultContextLength: 128000, + models: [], + passthroughModels: true, +}; diff --git a/src/app/api/providers/[id]/models/discovery/providerSets.ts b/src/app/api/providers/[id]/models/discovery/providerSets.ts index d98e4325f7..338a036386 100644 --- a/src/app/api/providers/[id]/models/discovery/providerSets.ts +++ b/src/app/api/providers/[id]/models/discovery/providerSets.ts @@ -56,6 +56,10 @@ export const NAMED_OPENAI_STYLE_PROVIDERS = new Set([ // DGrid is an OpenAI-compatible gateway whose default seed is the free auto-router; // the full model catalog is discovered live from https://api.dgrid.ai/v1/models. "dgrid", + // Qiniu (七牛云 AI inference) is an OpenAI-compatible gateway with no static seed β€” + // it proxies many upstream models (DeepSeek, Claude, Kimi...) behind one key, so the + // full catalog is discovered live from https://api.qnaigc.com/v1/models. + "qiniu", ]); export function isNamedOpenAIStyleProvider(provider: string): boolean { diff --git a/src/shared/constants/config.ts b/src/shared/constants/config.ts index 0b8262fe64..96d13b9482 100644 --- a/src/shared/constants/config.ts +++ b/src/shared/constants/config.ts @@ -5,6 +5,7 @@ export const PROVIDER_ENDPOINTS = { agentrouter: "https://agentrouter.org/v1/chat/completions", openrouter: "https://openrouter.ai/api/v1/chat/completions", dgrid: "https://api.dgrid.ai/v1/chat/completions", + qiniu: "https://api.qnaigc.com/v1/chat/completions", glm: "https://api.z.ai/api/anthropic/v1/messages", glmt: "https://api.z.ai/api/anthropic/v1/messages", "bailian-coding-plan": "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1/messages", diff --git a/src/shared/constants/providers/apikey/gateways.ts b/src/shared/constants/providers/apikey/gateways.ts index 540805bf54..27e1d38fb7 100644 --- a/src/shared/constants/providers/apikey/gateways.ts +++ b/src/shared/constants/providers/apikey/gateways.ts @@ -71,6 +71,20 @@ export const APIKEY_PROVIDERS_GATEWAYS = { "Create a DGrid API key at https://dgrid.ai, then use https://api.dgrid.ai/v1 " + "as the OpenAI-compatible base URL.", }, + qiniu: { + id: "qiniu", + alias: "qiniu", + name: "Qiniu", + icon: "cloud", + color: "#1E88E5", + textIcon: "QN", + passthroughModels: true, + website: "https://www.qiniu.com", + apiHint: + "Create a Qiniu AI inference API key at https://portal.qiniu.com/ai-inference/api-key, " + + "then paste it here as a Bearer token. OpenAI-compatible endpoint " + + "at https://api.qnaigc.com/v1, proxying DeepSeek, Claude, Kimi and more behind one key.", + }, orcarouter: { id: "orcarouter", alias: "orcarouter", diff --git a/tests/snapshots/provider/translate-path.json b/tests/snapshots/provider/translate-path.json index 312c66b7b9..f22206dc0c 100644 --- a/tests/snapshots/provider/translate-path.json +++ b/tests/snapshots/provider/translate-path.json @@ -3388,6 +3388,29 @@ "stream": "https://qianfan.baidubce.com/v2/chat/completions" } }, + "qiniu": { + "format": "openai", + "headers": { + "apiKey": { + "Accept": "text/event-stream", + "Authorization": "Bearer ", + "Content-Type": "application/json" + }, + "nonStream": { + "Authorization": "Bearer ", + "Content-Type": "application/json" + }, + "oauth": { + "Accept": "text/event-stream", + "Authorization": "Bearer ", + "Content-Type": "application/json" + } + }, + "url": { + "nonStream": "https://api.qnaigc.com/v1/chat/completions", + "stream": "https://api.qnaigc.com/v1/chat/completions" + } + }, "qoder": { "format": "openai", "headers": { diff --git a/tests/unit/providers-constants-split.test.ts b/tests/unit/providers-constants-split.test.ts index 25ad085af1..355d323879 100644 --- a/tests/unit/providers-constants-split.test.ts +++ b/tests/unit/providers-constants-split.test.ts @@ -1,7 +1,7 @@ // Characterization of the providers.ts catalog split (god-file decomposition): the host became a // barrel that re-exports 10 data catalogs now living under constants/providers/*, and APIKEY is // merged from 6 semantic family files (apikey/.ts). Locks: the public surface (every catalog -// + helpers still exported), the spread-merge integrity (160 APIKEY entries, no loss/dup), and that +// + helpers still exported), the spread-merge integrity (161 APIKEY entries, no loss/dup), and that // load-time Zod validation still runs. Pure-data move β†’ behavior must be identical. import { test } from "node:test"; import assert from "node:assert/strict"; @@ -31,12 +31,12 @@ test("barrel still exports every catalog + key helpers", () => { } }); -test("APIKEY_PROVIDERS merges the 6 family files into 160 entries (no loss / no dup)", async () => { +test("APIKEY_PROVIDERS merges the 6 family files into 161 entries (no loss / no dup)", async () => { const keys = Object.keys((P as Record).APIKEY_PROVIDERS); - assert.equal(keys.length, 160); - assert.equal(new Set(keys).size, 160, "duplicate keys after spread-merge"); + assert.equal(keys.length, 161); + assert.equal(new Set(keys).size, 161, "duplicate keys after spread-merge"); // the merged object's entry-count equals the sum of the 6 semantic family files; families are a - // strict partition (every provider in exactly one), so the sum must be exactly 160. + // strict partition (every provider in exactly one), so the sum must be exactly 161. const families: [string, string][] = [ ["gateways", "APIKEY_PROVIDERS_GATEWAYS"], ["frontier-labs", "APIKEY_PROVIDERS_FRONTIER"], @@ -56,7 +56,7 @@ test("APIKEY_PROVIDERS merges the 6 family files into 160 entries (no loss / no seen.add(k); } } - assert.equal(famTotal, 160, "families must partition all 160 providers"); + assert.equal(famTotal, 161, "families must partition all 161 providers"); }); test("AI_PROVIDERS Proxy aggregates all sections; lookups resolve", () => { diff --git a/tests/unit/qiniu-provider.test.ts b/tests/unit/qiniu-provider.test.ts new file mode 100644 index 0000000000..f98f38623e --- /dev/null +++ b/tests/unit/qiniu-provider.test.ts @@ -0,0 +1,148 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const { APIKEY_PROVIDERS } = await import("../../src/shared/constants/providers.ts"); +const { PROVIDER_ENDPOINTS } = await import("../../src/shared/constants/config.ts"); +const { REGISTRY: providerRegistry } = await import("../../open-sse/config/providerRegistry.ts"); +const { isValidModel } = await import("../../src/shared/constants/models.ts"); + +const QINIU_CHAT_URL = "https://api.qnaigc.com/v1/chat/completions"; +const QINIU_MODELS_URL = "https://api.qnaigc.com/v1/models"; + +test("Qiniu is registered as an API-key provider", () => { + const entry = APIKEY_PROVIDERS.qiniu; + assert.ok(entry, "APIKEY_PROVIDERS.qiniu must be defined"); + assert.equal(entry.id, "qiniu"); + assert.equal(entry.alias, "qiniu"); + assert.equal(entry.name, "Qiniu"); + assert.equal(entry.website, "https://www.qiniu.com"); + assert.equal(entry.passthroughModels, true); +}); + +test("Qiniu exposes the OpenAI-compatible chat completions endpoint", () => { + assert.equal(PROVIDER_ENDPOINTS.qiniu, QINIU_CHAT_URL); +}); + +test("Qiniu registry entry uses OpenAI format with bearer API-key auth", () => { + const entry = providerRegistry.qiniu; + assert.ok(entry, "providerRegistry.qiniu must be defined"); + assert.equal(entry.id, "qiniu"); + assert.equal(entry.alias, "qiniu"); + assert.equal(entry.format, "openai"); + assert.equal(entry.executor, "default"); + assert.equal(entry.authType, "apikey"); + assert.equal(entry.authHeader, "bearer"); + assert.equal(entry.baseUrl, QINIU_CHAT_URL); + assert.equal(entry.modelsUrl, QINIU_MODELS_URL); + assert.equal(entry.passthroughModels, true); +}); + +test("Qiniu ships no static model seed β€” relies fully on passthrough + live catalog", () => { + const models = providerRegistry.qiniu.models; + assert.deepEqual(models, []); +}); + +test("Qiniu accepts any model id via passthrough models (DeepSeek/Claude/Kimi behind one key)", () => { + assert.equal(isValidModel("qiniu", "deepseek-v3"), true); + assert.equal(isValidModel("qiniu", "deepseek-v3.2"), true); + assert.equal(isValidModel("qiniu", "claude-sonnet-4-5"), true); + assert.equal(isValidModel("qiniu", "kimi-k2"), true); +}); + +const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-qiniu-")); +process.env.DATA_DIR = TEST_DATA_DIR; + +const core = await import("../../src/lib/db/core.ts"); +const providersDb = await import("../../src/lib/db/providers.ts"); +const modelsRoute = await import("../../src/app/api/providers/[id]/models/route.ts"); + +async function resetStorage() { + core.resetDbInstance(); + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); + fs.mkdirSync(TEST_DATA_DIR, { recursive: true }); +} + +test.after(() => { + core.resetDbInstance(); + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); +}); + +interface ModelsBody { + provider: string; + connectionId: string; + models: Array<{ id: string }>; + source?: string; +} + +test("Qiniu import fetches the live /v1/models catalog", async () => { + await resetStorage(); + const connection = await providersDb.createProviderConnection({ + provider: "qiniu", + authType: "apikey", + name: "qiniu-live", + apiKey: "qiniu-key", + }); + + let fetched = false; + const originalFetch = globalThis.fetch; + globalThis.fetch = async (url) => { + if (String(url) === QINIU_MODELS_URL) { + fetched = true; + return Response.json({ + object: "list", + data: [{ id: "deepseek-v3" }, { id: "deepseek-v4" }, { id: "kimi-k2" }], + }); + } + return new Response("not found", { status: 404 }); + }; + + try { + const response = await modelsRoute.GET( + new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`), + { params: { id: connection.id } } + ); + assert.equal(response.status, 200); + const body = (await response.json()) as ModelsBody; + assert.equal(body.provider, "qiniu"); + assert.equal(body.source, "api", "should serve the live upstream catalog"); + assert.ok(fetched, `should have probed ${QINIU_MODELS_URL}`); + const ids = body.models.map((model) => model.id); + assert.ok(ids.includes("deepseek-v3"), `live catalog model missing: ${ids.join(",")}`); + assert.ok(ids.includes("kimi-k2"), `live catalog model missing: ${ids.join(",")}`); + } finally { + globalThis.fetch = originalFetch; + } +}); + +test("Qiniu import falls back to an empty local catalog when live fetch fails", async () => { + await resetStorage(); + const connection = await providersDb.createProviderConnection({ + provider: "qiniu", + authType: "apikey", + name: "qiniu-fallback", + apiKey: "qiniu-key-2", + }); + + const originalFetch = globalThis.fetch; + globalThis.fetch = async () => new Response("bad gateway", { status: 502 }); + + try { + const response = await modelsRoute.GET( + new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`), + { params: { id: connection.id } } + ); + assert.equal(response.status, 200); + const body = (await response.json()) as ModelsBody; + assert.equal(body.provider, "qiniu"); + assert.equal(body.source, "local_catalog", "import must not break when upstream is down"); + assert.deepEqual( + body.models.map((model) => model.id), + [] + ); + } finally { + globalThis.fetch = originalFetch; + } +});