feat: separate api key and upstream concurrency

This commit is contained in:
wlx committed 2026-09-23 18:09:10 +08:00
1 parent 281849ceb8
commit f5f855c751
13 files changed
+74 -8

No files matched your search

@@ -80,7 +80,8 @@ public class GatewayController {
if(!mock && !provider.isConfigured(providerId)) throw new ApiException("PROVIDER_NOT_CONFIGURED","该供应商尚未配置密钥,不能执行真实调用",503); if(!mock && !provider.isConfigured(providerId)) throw new ApiException("PROVIDER_NOT_CONFIGURED","该供应商尚未配置密钥,不能执行真实调用",503);
ChatMeter.Request request=ChatMeter.request(input,json); ChatMeter.Request request=ChatMeter.request(input,json);
guard.checkRate(UUID.fromString(String.valueOf(key.get("id"))), false); guard.checkRate(UUID.fromString(String.valueOf(key.get("id"))), false);
try (GatewayGuard.Slot slot = guard.acquire(model)) { try (GatewayGuard.Slot keySlot = guard.acquireKey(UUID.fromString(String.valueOf(key.get("id"))));
GatewayGuard.Slot modelSlot = guard.acquire(model)) {
var ticket=billing.reserve(key,model,request,idempotencyKey); var ticket=billing.reserve(key,model,request,idempotencyKey);
servletResponse.setHeader("X-Request-Id",ticket.id().toString()); servletResponse.setHeader("X-Request-Id",ticket.id().toString());
try { try {
@@ -25,6 +25,7 @@ public class GatewayGuard {
private final int requestsPerMinute; private final int requestsPerMinute;
private final int readsPerMinute; private final int readsPerMinute;
private final int defaultModelConcurrency; private final int defaultModelConcurrency;
private final int defaultKeyConcurrency;
private final String redisPrefix; private final String redisPrefix;
private static DefaultRedisScript<Long> script(String location) { private static DefaultRedisScript<Long> script(String location) {
@@ -34,26 +35,35 @@ public class GatewayGuard {
return script; return script;
} }
@org.springframework.beans.factory.annotation.Autowired
public GatewayGuard( public GatewayGuard(
StringRedisTemplate redis, StringRedisTemplate redis,
@Value("${moyi.gateway.requests-per-minute:60}") int requestsPerMinute, @Value("${moyi.gateway.requests-per-minute:60}") int requestsPerMinute,
@Value("${moyi.gateway.reads-per-minute:300}") int readsPerMinute, @Value("${moyi.gateway.reads-per-minute:300}") int readsPerMinute,
@Value("${moyi.gateway.default-model-concurrency:4}") int defaultModelConcurrency, @Value("${moyi.gateway.default-model-concurrency:4}") int defaultModelConcurrency,
@Value("${moyi.gateway.default-key-concurrency:4}") int defaultKeyConcurrency,
@Value("${moyi.gateway.redis-prefix:moyi:}") String redisPrefix @Value("${moyi.gateway.redis-prefix:moyi:}") String redisPrefix
) { ) {
if (requestsPerMinute < 1 || readsPerMinute < 1 || defaultModelConcurrency < 1) { if (requestsPerMinute < 1 || readsPerMinute < 1 || defaultModelConcurrency < 1 || defaultKeyConcurrency < 1) {
throw new IllegalArgumentException("Gateway limits must be positive"); throw new IllegalArgumentException("Gateway limits must be positive");
} }
this.redis = redis; this.redis = redis;
this.requestsPerMinute = requestsPerMinute; this.requestsPerMinute = requestsPerMinute;
this.readsPerMinute = readsPerMinute; this.readsPerMinute = readsPerMinute;
this.defaultModelConcurrency = defaultModelConcurrency; this.defaultModelConcurrency = defaultModelConcurrency;
this.defaultKeyConcurrency = defaultKeyConcurrency;
if (redisPrefix == null || !redisPrefix.matches("[A-Za-z0-9:_-]{2,80}:")) { if (redisPrefix == null || !redisPrefix.matches("[A-Za-z0-9:_-]{2,80}:")) {
throw new IllegalArgumentException("Redis prefix must end in ':' and contain only letters, numbers, ':', '_' or '-'"); throw new IllegalArgumentException("Redis prefix must end in ':' and contain only letters, numbers, ':', '_' or '-'");
} }
this.redisPrefix = redisPrefix; this.redisPrefix = redisPrefix;
} }
/** Compatibility constructor for isolated unit tests and local callers. */
public GatewayGuard(StringRedisTemplate redis, int requestsPerMinute, int readsPerMinute,
int defaultModelConcurrency, String redisPrefix) {
this(redis, requestsPerMinute, readsPerMinute, defaultModelConcurrency, 4, redisPrefix);
}
public void checkRate(UUID keyId, boolean readOnly) { public void checkRate(UUID keyId, boolean readOnly) {
String bucket = redisPrefix + "gateway:rate:" + (readOnly ? "read:" : "invoke:") + keyId; String bucket = redisPrefix + "gateway:rate:" + (readOnly ? "read:" : "invoke:") + keyId;
long retryMs = execute(RATE, bucket, Integer.toString(readOnly ? readsPerMinute : requestsPerMinute), "60000"); long retryMs = execute(RATE, bucket, Integer.toString(readOnly ? readsPerMinute : requestsPerMinute), "60000");
@@ -68,13 +78,22 @@ public class GatewayGuard {
} }
public Slot acquire(Map<String, Object> model) { public Slot acquire(Map<String, Object> model) {
String bucket = redisPrefix + "gateway:slots:" + model.get("id"); String bucket = redisPrefix + "gateway:slots:model:" + model.get("id");
String token = UUID.randomUUID().toString(); String token = UUID.randomUUID().toString();
long acquired = execute(ACQUIRE, bucket, Integer.toString(modelConcurrency(model)), Long.toString(SLOT_TTL_MS), token); long acquired = execute(ACQUIRE, bucket, Integer.toString(modelConcurrency(model)), Long.toString(SLOT_TTL_MS), token);
if (acquired != 1) throw new GatewayLimitException("MODEL_BUSY", "当前模型并发已满,请稍后重试", 429, 1); if (acquired != 1) throw new GatewayLimitException("MODEL_BUSY", "当前模型并发已满,请稍后重试", 429, 1);
return new Slot(bucket, token); return new Slot(bucket, token);
} }
/** Limits simultaneous in-flight requests made through one MOYI platform API Key. */
public Slot acquireKey(UUID keyId) {
String bucket = redisPrefix + "gateway:slots:key:" + keyId;
String token = UUID.randomUUID().toString();
long acquired = execute(ACQUIRE, bucket, Integer.toString(defaultKeyConcurrency), Long.toString(SLOT_TTL_MS), token);
if (acquired != 1) throw new GatewayLimitException("KEY_BUSY", "当前 API Key 的并发已满,请稍后重试", 429, 1);
return new Slot(bucket, token);
}
private long execute(DefaultRedisScript<Long> script, String key, String... args) { private long execute(DefaultRedisScript<Long> script, String key, String... args) {
try { try {
Long value = redis.execute(script, List.of(key), (Object[]) args); Long value = redis.execute(script, List.of(key), (Object[]) args);
@@ -44,6 +44,7 @@ moyi:
requests-per-minute: ${GATEWAY_REQUESTS_PER_MINUTE:60} requests-per-minute: ${GATEWAY_REQUESTS_PER_MINUTE:60}
reads-per-minute: ${GATEWAY_READS_PER_MINUTE:300} reads-per-minute: ${GATEWAY_READS_PER_MINUTE:300}
default-model-concurrency: ${GATEWAY_DEFAULT_MODEL_CONCURRENCY:4} default-model-concurrency: ${GATEWAY_DEFAULT_MODEL_CONCURRENCY:4}
default-key-concurrency: ${GATEWAY_DEFAULT_KEY_CONCURRENCY:4}
tasks: tasks:
max-queued-per-model: ${TASK_MAX_QUEUED_PER_MODEL:100} max-queued-per-model: ${TASK_MAX_QUEUED_PER_MODEL:100}
worker-interval-ms: ${MOYI_TASK_WORKER_INTERVAL_MS:1000} worker-interval-ms: ${MOYI_TASK_WORKER_INTERVAL_MS:1000}
@@ -29,6 +29,17 @@ class GatewayDeploymentTest {
verify(redis).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:rate:invoke:" + keyId)), any(Object[].class)); verify(redis).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:rate:invoke:" + keyId)), any(Object[].class));
} }
@Test
void keyConcurrencyUsesDedicatedRedisBucket() {
StringRedisTemplate redis = mock(StringRedisTemplate.class);
doReturn(1L).when(redis).execute(any(RedisScript.class), anyList(), any(Object[].class));
UUID keyId = UUID.randomUUID();
try (GatewayGuard.Slot ignored = new GatewayGuard(redis, 60, 300, 4, 2, "moyi:test:").acquireKey(keyId)) {
// The lease is intentionally held for the duration of this assertion.
}
verify(redis, atLeastOnce()).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:slots:key:" + keyId)), any(Object[].class));
}
@Test @Test
void invalidRedisPrefixIsRejected() { void invalidRedisPrefixIsRejected() {
assertThrows(IllegalArgumentException.class, () -> new GatewayGuard(mock(StringRedisTemplate.class), 60, 300, 4, "")); assertThrows(IllegalArgumentException.class, () -> new GatewayGuard(mock(StringRedisTemplate.class), 60, 300, 4, ""));
+1 -1
View File
@@ -77,7 +77,7 @@ Invoke-WebRequest http://localhost:8080/health
本节点完成的是“控制面基础闭环 + 同步供应商转发 + Redis 网关保护 + 持久化任务队列”,不是生产网关完成版: 本节点完成的是“控制面基础闭环 + 同步供应商转发 + Redis 网关保护 + 持久化任务队列”,不是生产网关完成版:
- 数据已写入 PostgreSQL;Redis 已用于按 API Key 限流、按模型并发租约和 Redis Lua 原子操作。默认同步调用每 Key 每分钟 60 次、模型并发 4,均可通过环境变量调整;Redis 不可用时网关返回 503,不会绕过保护直接请求上游; - 数据已写入 PostgreSQL;Redis 已用于 API Key 频率限制、API Key 并发租约、上游分组并发租约和 Redis Lua 原子操作。默认同步调用每 Key 每分钟 60 次(`GATEWAY_REQUESTS_PER_MINUTE`)、每 Key 同时 4 个请求(`GATEWAY_DEFAULT_KEY_CONCURRENCY`);分组并发由管理端模型分组的 `maxConcurrency` 配置,未配置时使用 `GATEWAY_DEFAULT_MODEL_CONCURRENCY`。Redis 不可用时网关返回 503,不会绕过保护直接请求上游;
- `/v1/chat/completions` 支持 OpenAI 兼容同步/流式文本聊天;真实供应商未配置 Key 时返回 503,只有 `provider-mock` 可以返回 Mock。V13 起按人民币分组售价预留并结算,详见 [流式与计费](16-streaming-chat-billing.md); - `/v1/chat/completions` 支持 OpenAI 兼容同步/流式文本聊天;真实供应商未配置 Key 时返回 503,只有 `provider-mock` 可以返回 Mock。V13 起按人民币分组售价预留并结算,详见 [流式与计费](16-streaming-chat-billing.md);
- `/v1/3d/tasks` 和 `/v1/video/tasks` 已提供数据库持久化 Mock worker;真实供应商执行器尚未替换,返回 501 而非伪造任务成功; - `/v1/3d/tasks` 和 `/v1/video/tasks` 已提供数据库持久化 Mock worker;真实供应商执行器尚未替换,返回 501 而非伪造任务成功;
- Seedance、Tripo/VAST 的异步任务和 OSS 结果存储尚未迁移到 Java; - Seedance、Tripo/VAST 的异步任务和 OSS 结果存储尚未迁移到 Java;
+1 -1
View File
@@ -16,7 +16,7 @@
真实供应商没有配置密钥时返回 503,不再返回 Mock 成功。只有明确绑定 `provider-mock` 的模型可以走 Mock;真实异步供应商返回 501。已有种子目录和价格只是联调数据,实际模型 ID/能力须由供应商控制台核验后修改。 真实供应商没有配置密钥时返回 503,不再返回 Mock 成功。只有明确绑定 `provider-mock` 的模型可以走 Mock;真实异步供应商返回 501。已有种子目录和价格只是联调数据,实际模型 ID/能力须由供应商控制台核验后修改。
注意更正早期说明:当前登录会话和任务状态保存于 PostgreSQL;Tair 已实现的是按 Key 限流、按模型并发租约,不是已完成的 MQ、幂等或异步调度平台。不需要现在购买 MQ。 注意更正早期说明:当前登录会话和任务状态保存于 PostgreSQL;Tair 已实现的是按 Key 限流、按 API Key 并发租约、按上游分组并发租约,不是已完成的 MQ、幂等或异步调度平台。不需要现在购买 MQ。
## 2. 你需要在阿里云完成的配置 ## 2. 你需要在阿里云完成的配置
+17
View File
@@ -8,6 +8,23 @@ API Key 权限窗口支持同时勾选多个模型,再选择各自的分组;
模型广场、管理端模型/渠道和 API Key 列表默认每页 12 项,可选 24/48 项。权限列表默认每页 8 个模型,可选 16/32 项。筛选或每页数量改变时回到首页;删除导致页数减少时自动回到有效页。 模型广场、管理端模型/渠道和 API Key 列表默认每页 12 项,可选 24/48 项。权限列表默认每页 8 个模型,可选 16/32 项。筛选或每页数量改变时回到首页;删除导致页数减少时自动回到有效页。
## 两层并发限制
一次同步模型调用要同时通过两层并发保护:
1. **平台 API Key 并发**:限制同一个用户 Key 同时进行中的请求数量。默认值为 4,可在服务端环境变量 `GATEWAY_DEFAULT_KEY_CONCURRENCY` 调整;每个 Key 独立计数,不会因为其他用户占满而互相阻塞。
2. **上游分组并发**:限制同一个渠道分组向中转站发出的同时请求数量,供使用该分组的多个用户共享。管理员在模型与分组中填写“上游分组并发上限”;1 表示串行,4 表示最多同时处理 4 个请求。
两层限制会同时生效,任一层达到上限都会返回 429,并带有短暂重试提示。API Key 的每分钟请求频率和并发数是不同设置;异步任务另受任务队列上限控制。
## 用户操作指南
1. 在模型广场先按模型厂商筛选,再打开模型详情选择渠道分组;复制详情中的“调用模型 ID”。
2. 在 API Keys 创建密钥时,可以一次勾选多个模型和多个分组。完整密钥只显示一次,请立即保存;停用的密钥可以重新启用。
3. 在线调试选择已有的启用 API Key、模型和分组即可,不需要为每次测试重新创建密钥;请求和响应会保留到使用记录。
4. 外部应用使用用户端显示的统一 Base URL,路径为 `/v1`,聊天接口为 `/v1/chat/completions`,通过 `Authorization: Bearer <API_KEY>` 认证。
5. 使用记录查看模型、厂商、渠道分组、Token、费用、耗时和时间;任务中心查看异步任务进度与结果。余额、权限或并发不足时,按错误提示处理后再重试。
## 验证 ## 验证
- `cd prototype; npm test`:目录合并、无可用分组的模型、多模型授权集合和分页边界,以及既有流式响应测试。 - `cd prototype; npm test`:目录合并、无可用分组的模型、多模型授权集合和分页边界,以及既有流式响应测试。
+1
View File
@@ -43,6 +43,7 @@ JAVA_OPTS='-Xms256m -Xmx1536m -XX:+ExitOnOutOfMemoryError'
GATEWAY_REQUESTS_PER_MINUTE=60 GATEWAY_REQUESTS_PER_MINUTE=60
GATEWAY_READS_PER_MINUTE=300 GATEWAY_READS_PER_MINUTE=300
GATEWAY_DEFAULT_MODEL_CONCURRENCY=4 GATEWAY_DEFAULT_MODEL_CONCURRENCY=4
GATEWAY_DEFAULT_KEY_CONCURRENCY=4
TASK_MAX_QUEUED_PER_MODEL=100 TASK_MAX_QUEUED_PER_MODEL=100
MOYI_TASK_WORKER_INTERVAL_MS=1000 MOYI_TASK_WORKER_INTERVAL_MS=1000
+1
View File
@@ -11,6 +11,7 @@ REDIS_PASSWORD=replace-with-a-long-random-password
GATEWAY_REQUESTS_PER_MINUTE=60 GATEWAY_REQUESTS_PER_MINUTE=60
GATEWAY_READS_PER_MINUTE=300 GATEWAY_READS_PER_MINUTE=300
GATEWAY_DEFAULT_MODEL_CONCURRENCY=4 GATEWAY_DEFAULT_MODEL_CONCURRENCY=4
GATEWAY_DEFAULT_KEY_CONCURRENCY=4
TASK_MAX_QUEUED_PER_MODEL=100 TASK_MAX_QUEUED_PER_MODEL=100
MOYI_TASK_WORKER_INTERVAL_MS=1000 MOYI_TASK_WORKER_INTERVAL_MS=1000
+1
View File
@@ -46,6 +46,7 @@ services:
GATEWAY_REQUESTS_PER_MINUTE: ${GATEWAY_REQUESTS_PER_MINUTE:-60} GATEWAY_REQUESTS_PER_MINUTE: ${GATEWAY_REQUESTS_PER_MINUTE:-60}
GATEWAY_READS_PER_MINUTE: ${GATEWAY_READS_PER_MINUTE:-300} GATEWAY_READS_PER_MINUTE: ${GATEWAY_READS_PER_MINUTE:-300}
GATEWAY_DEFAULT_MODEL_CONCURRENCY: ${GATEWAY_DEFAULT_MODEL_CONCURRENCY:-4} GATEWAY_DEFAULT_MODEL_CONCURRENCY: ${GATEWAY_DEFAULT_MODEL_CONCURRENCY:-4}
GATEWAY_DEFAULT_KEY_CONCURRENCY: ${GATEWAY_DEFAULT_KEY_CONCURRENCY:-4}
TASK_MAX_QUEUED_PER_MODEL: ${TASK_MAX_QUEUED_PER_MODEL:-100} TASK_MAX_QUEUED_PER_MODEL: ${TASK_MAX_QUEUED_PER_MODEL:-100}
MOYI_TASK_WORKER_INTERVAL_MS: ${MOYI_TASK_WORKER_INTERVAL_MS:-1000} MOYI_TASK_WORKER_INTERVAL_MS: ${MOYI_TASK_WORKER_INTERVAL_MS:-1000}
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-10} DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-10}
+2 -2
View File
@@ -108,7 +108,7 @@ async function toggle(kind: 'channel' | 'model' | 'group', item: CatalogProvider
<section class="page-heading"><h1>{{ props.section === 'channels' ? '渠道管理' : '模型与分组' }}</h1><div class="heading-actions"><button class="icon-button" title="刷新" :disabled="loading" @click="refresh"><RefreshCcw :size="18" /></button><button class="button primary" @click="props.section === 'channels' ? editChannel() : editModel()"><Plus :size="16" />{{ props.section === 'channels' ? '添加渠道' : '添加模型' }}</button></div></section> <section class="page-heading"><h1>{{ props.section === 'channels' ? '渠道管理' : '模型与分组' }}</h1><div class="heading-actions"><button class="icon-button" title="刷新" :disabled="loading" @click="refresh"><RefreshCcw :size="18" /></button><button class="button primary" @click="props.section === 'channels' ? editChannel() : editModel()"><Plus :size="16" />{{ props.section === 'channels' ? '添加渠道' : '添加模型' }}</button></div></section>
<label class="search-input catalog-search"><Search :size="16" /><input v-model="query" :placeholder="props.section === 'channels' ? '搜索渠道名称或 Code' : '搜索模型名称或标识'" /></label> <label class="search-input catalog-search"><Search :size="16" /><input v-model="query" :placeholder="props.section === 'channels' ? '搜索渠道名称或 Code' : '搜索模型名称或标识'" /></label>
<p v-if="error" role="alert">{{ error }}</p> <p v-if="error" role="alert">{{ error }}</p>
<p v-if="props.section === 'models'" class="catalog-secondary">启用模型后会显示在用户端模型广场。模型厂商表示模型的实际研发方,渠道表示请求经过的中转站或官方接口;分组与所属渠道也启用后,用户才能为 API Key 选择该分组。并发上限按分组生效,填 1 才是串行,填 4 表示同一分组最多同时处理 4 个请求。</p> <p v-if="props.section === 'models'" class="catalog-secondary">启用模型后会显示在用户端模型广场。模型厂商表示模型的实际研发方,渠道表示请求经过的中转站或官方接口;分组与所属渠道也启用后,用户才能为 API Key 选择该分组。平台 API Key 并发和上游渠道/模型并发是两层独立限制:前者限制同一个 Key 的同时请求数,后者在下方按分组填写,填 1 才是串行,填 4 表示同一渠道分组最多同时处理 4 个请求。</p>
<p v-if="loading">加载中…</p> <p v-if="loading">加载中…</p>
<div v-if="props.section === 'channels'" class="responsive-table"><table><thead><tr><th>渠道</th><th>来源 / 协议</th><th>Base URL</th><th>凭据</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="item in pagedChannels" :key="item.id"><td><strong>{{ item.name }}</strong><small class="catalog-secondary">{{ item.code }}</small></td><td>{{ item.sourceType }}<small class="catalog-secondary">{{ item.protocol }}</small></td><td class="catalog-url">{{ item.baseUrl || '未配置' }}</td><td>{{ item.credentialMasked || '未配置' }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="item.status === 'active'" :disabled="saving" :aria-label="`${item.name} 启用`" @change="toggle('channel', item)" />{{ item.status === 'active' ? '已启用' : '已停用' }}</label></td><td><button class="icon-button" :title="`编辑渠道 ${item.name}`" @click="editChannel(item)"><Pencil :size="16" /></button><button class="icon-button" :title="`删除渠道 ${item.name}`" :disabled="saving" @click="confirmDelete('channel', item.id, item.name)"><Trash2 :size="16" /></button></td></tr><tr v-if="!shownChannels.length && !loading"><td colspan="6">暂无渠道</td></tr></tbody></table></div> <div v-if="props.section === 'channels'" class="responsive-table"><table><thead><tr><th>渠道</th><th>来源 / 协议</th><th>Base URL</th><th>凭据</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="item in pagedChannels" :key="item.id"><td><strong>{{ item.name }}</strong><small class="catalog-secondary">{{ item.code }}</small></td><td>{{ item.sourceType }}<small class="catalog-secondary">{{ item.protocol }}</small></td><td class="catalog-url">{{ item.baseUrl || '未配置' }}</td><td>{{ item.credentialMasked || '未配置' }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="item.status === 'active'" :disabled="saving" :aria-label="`${item.name} 启用`" @change="toggle('channel', item)" />{{ item.status === 'active' ? '已启用' : '已停用' }}</label></td><td><button class="icon-button" :title="`编辑渠道 ${item.name}`" @click="editChannel(item)"><Pencil :size="16" /></button><button class="icon-button" :title="`删除渠道 ${item.name}`" :disabled="saving" @click="confirmDelete('channel', item.id, item.name)"><Trash2 :size="16" /></button></td></tr><tr v-if="!shownChannels.length && !loading"><td colspan="6">暂无渠道</td></tr></tbody></table></div>
<ListPagination v-if="props.section === 'channels'" v-model:page="channelPage" v-model:page-size="channelPageSize" :total="shownChannels.length" label="渠道分页" /> <ListPagination v-if="props.section === 'channels'" v-model:page="channelPage" v-model:page-size="channelPageSize" :total="shownChannels.length" label="渠道分页" />
@@ -153,7 +153,7 @@ async function toggle(kind: 'channel' | 'model' | 'group', item: CatalogProvider
<label class="form-label">缓存命中输入价格(留空按普通输入价格)<input v-model="group.cachedInput" class="text-input" type="number" min="0" step="any" /></label> <label class="form-label">缓存命中输入价格(留空按普通输入价格)<input v-model="group.cachedInput" class="text-input" type="number" min="0" step="any" /></label>
<label class="form-label" for="group-unit">价格单位</label><input id="group-unit" v-model="group.unit" class="text-input" required /> <label class="form-label" for="group-unit">价格单位</label><input id="group-unit" v-model="group.unit" class="text-input" required />
<small>文本聊天自动扣费仅支持 CNY / 1M tokens(元/百万 Token)。输入、输出均需填写;填 0 表示免费,留空则禁止调用。请填写平台对用户的售价。</small> <small>文本聊天自动扣费仅支持 CNY / 1M tokens(元/百万 Token)。输入、输出均需填写;填 0 表示免费,留空则禁止调用。请填写平台对用户的售价。</small>
<div class="modal-form-grid"><label><span class="form-label">优先级</span><input v-model="group.priority" class="text-input" type="number" min="0" step="1" required /></label><label><span class="form-label">并发上限</span><input v-model="group.maxConcurrency" class="text-input" type="number" min="1" step="1" required /><small>1 为串行;建议按该渠道限额填写,4 表示最多同时处理 4 个请求。</small></label></div> <div class="modal-form-grid"><label><span class="form-label">优先级</span><input v-model="group.priority" class="text-input" type="number" min="0" step="1" required /></label><label><span class="form-label">上游分组并发上限</span><input v-model="group.maxConcurrency" class="text-input" type="number" min="1" step="1" required /><small>这是中转站允许多个用户共享该模型的并发数。1 为串行;按渠道实际额度填写。</small></label></div>
</template> </template>
</form> </form>
<template #footer><button class="button secondary" :disabled="saving" @click="editor = ''">取消</button><button class="button primary" form="catalog-editor" type="submit" :disabled="saving">{{ saving ? '保存中…' : '保存' }}</button></template> <template #footer><button class="button secondary" :disabled="saving" @click="editor = ''">取消</button><button class="button primary" form="catalog-editor" type="submit" :disabled="saving">{{ saving ? '保存中…' : '保存' }}</button></template>
+2
View File
@@ -213,3 +213,5 @@ td strong{font-size:12px}
@media(min-width:1151px){.model-filter-grid{grid-template-columns:minmax(220px,1.7fr) repeat(5,minmax(125px,1fr))}} @media(min-width:1151px){.model-filter-grid{grid-template-columns:minmax(220px,1.7fr) repeat(5,minmax(125px,1fr))}}
/* Usage audit console */ /* Usage audit console */
.usage-filter{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.usage-filter .search-input{min-width:260px;flex:1}.usage-filter select{min-width:120px}.button.danger{color:#fff;border-color:#d94b62;background:#d94b62}.button.danger:hover{background:#bd354d}.danger-icon{color:#c43d55}.usage-table th:first-child,.usage-table td:first-child{width:36px}.usage-table input[type=checkbox]{width:15px;height:15px;accent-color:#6351df}.usage-table code{font-size:10px}.usage-detail-list{margin-bottom:18px}.usage-payload{max-height:180px;overflow:auto;margin:6px 0 15px;padding:11px;border:1px solid var(--border);border-radius:8px;color:#344054;font:11px/1.55 "DM Mono",monospace;white-space:pre-wrap;word-break:break-word;background:#f7f8fb}.table-pagination{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-top:1px solid var(--border);color:var(--muted);font-size:11px}.table-pagination>div{display:flex;gap:6px}.rotate-90{transform:rotate(90deg)}.rotate--90{transform:rotate(-90deg)} .usage-filter{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.usage-filter .search-input{min-width:260px;flex:1}.usage-filter select{min-width:120px}.button.danger{color:#fff;border-color:#d94b62;background:#d94b62}.button.danger:hover{background:#bd354d}.danger-icon{color:#c43d55}.usage-table th:first-child,.usage-table td:first-child{width:36px}.usage-table input[type=checkbox]{width:15px;height:15px;accent-color:#6351df}.usage-table code{font-size:10px}.usage-detail-list{margin-bottom:18px}.usage-payload{max-height:180px;overflow:auto;margin:6px 0 15px;padding:11px;border:1px solid var(--border);border-radius:8px;color:#344054;font:11px/1.55 "DM Mono",monospace;white-space:pre-wrap;word-break:break-word;background:#f7f8fb}.table-pagination{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-top:1px solid var(--border);color:var(--muted);font-size:11px}.table-pagination>div{display:flex;gap:6px}.rotate-90{transform:rotate(90deg)}.rotate--90{transform:rotate(-90deg)}
.docs-guide-extra{padding:24px 28px}.docs-guide-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}.docs-guide-grid article{display:flex;gap:12px;min-height:112px;padding:15px;border:1px solid var(--border);border-radius:10px;background:var(--soft)}.docs-guide-grid article>b{display:grid;flex:0 0 30px;width:30px;height:30px;place-items:center;border:1px solid #d8d0fb;border-radius:8px;color:var(--primary);font-family:"DM Mono",monospace;font-size:10px;background:var(--primary-soft)}.docs-guide-grid h4{margin:1px 0 7px;font-size:13px}.docs-guide-grid p{margin:0;color:var(--text-soft);font-size:11px;line-height:1.65}.docs-guide-grid code{padding:2px 4px;border-radius:4px;color:var(--primary);font-family:"DM Mono",monospace;background:var(--primary-soft)}
@media(max-width:700px){.docs-guide-extra{padding:20px 16px}.docs-guide-grid{grid-template-columns:1fr}}
+13 -1
View File
@@ -640,7 +640,19 @@ MOYI_MODEL=&lt;model-id&gt;</code></pre></div></section><section><b>02</b><div><
-H "Authorization: Bearer $MOYI_API_KEY" \ -H "Authorization: Bearer $MOYI_API_KEY" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ "model": "&lt;model-id&gt;", "messages": [...] }'</code></pre></div></section><div class="docs-note"><Info :size="18" /><p><strong>保持开放与兼容。</strong>具体模型支持的协议和参数以模型详情与版本化 API 文档为准。</p></div></article></section> -d '{ "model": "&lt;model-id&gt;", "messages": [...] }'</code></pre></div></section><div class="docs-note"><Info :size="18" /><p><strong>保持开放与兼容。</strong>具体模型支持的协议和参数以模型详情与版本化 API 文档为准。</p></div></article></section>
</template> </template>
<section v-if="view === 'docs'" class="panel docs-guide-extra">
<header class="panel-header"><div><span>USER GUIDE</span><h3>从模型广场到第一次调用</h3></div><span class="select-button static">按步骤操作</span></header>
<div class="docs-guide-grid">
<article><b>01</b><div><h4>选择模型与来源</h4><p>模型广场先按模型厂商筛选,例如 OpenAI、智谱、月之暗面或字节跳动;进入详情后再选择可用的渠道分组。模型 ID 使用详情里的“调用模型 ID”。</p></div></article>
<article><b>02</b><div><h4>创建并授权 API Key</h4><p>在 API Keys 中创建 Key,授权窗口可以同时勾选多个模型和多个分组。密钥只在创建时完整显示,请立即保存;停用后的 Key 可重新启用。</p></div></article>
<article><b>03</b><div><h4>在线调试</h4><p>在线调试直接选择已有的启用状态 API Key,再选择模型和分组;无需为每次调试重新创建 Key。调试结果和请求会保留在历史记录中。</p></div></article>
<article><b>04</b><div><h4>接入应用</h4><p>将 Base URL、Key 和模型调用 ID 配置到 SDK 或程序中。统一地址为 <code>{{ platformApiBaseUrl }}</code>,聊天接口是 <code>/chat/completions</code>,请求头使用 Bearer Key。</p></div></article>
<article><b>05</b><div><h4>查看用量与任务</h4><p>使用记录展示模型、分组、Token、费用和耗时;任务中心展示异步任务状态和结果。额度不足、模型停用或分组并发已满时,请先查看错误提示和重试时间。</p></div></article>
<article><b>06</b><div><h4>理解两层并发</h4><p>同一个 API Key 有独立的并发上限;上游分组还有一个可供多个用户共享的并发上限。一次请求必须同时取得两类额度,任一达到上限都会稍后重试。</p></div></article>
</div>
</section>
<SlidePanel v-if="selectedModel" :title="selectedModel.name" eyebrow="MODEL DETAILS" @close="selectedModel = null"> <SlidePanel v-if="selectedModel" :title="selectedModel.name" eyebrow="MODEL DETAILS" @close="selectedModel = null">
<div class="drawer-model-head"><span class="model-icon" :class="selectedModel.accent"><component :is="selectedModel.icon" :size="22" /></span><div><small>{{ selectedModel.vendorName || '未标注厂商' }}</small><strong>{{ selectedModel.type }} · {{ selectedModel.mode }}调用</strong><small>渠道:{{ selectedModel.provider }}</small></div></div> <div class="drawer-model-head"><span class="model-icon" :class="selectedModel.accent"><component :is="selectedModel.icon" :size="22" /></span><div><small>{{ selectedModel.vendorName || '未标注厂商' }}</small><strong>{{ selectedModel.type }} · {{ selectedModel.mode }}调用</strong><small>渠道:{{ selectedModel.provider }}</small></div></div>