feat: support api key ip restriction rules

This commit is contained in:
fawney19
2026-05-20 16:11:49 +08:00
parent b6bdc08267
commit f76bbaab52
55 changed files with 698 additions and 551 deletions

View File

@@ -148,6 +148,7 @@ export interface UserApiKeyExport {
allowed_providers?: string[] | null
allowed_api_formats?: string[] | null
allowed_models?: string[] | null
ip_rules?: string[] | null
rate_limit?: number | null // legacy/null 兼容1.3+ standalone null = 跟随系统默认
concurrent_limit?: number | null
force_capabilities?: Record<string, boolean>
@@ -497,6 +498,7 @@ export interface AdminApiKey {
allowed_providers?: string[] | null // 允许的提供商列表
allowed_api_formats?: string[] | null // 允许的 API 格式列表
allowed_models?: string[] | null // 允许的模型列表
ip_rules?: string[] | null // IP 限制规则
feature_settings?: Record<string, unknown> | null
auto_delete_on_expiry?: boolean // 过期后是否自动删除
last_used_at?: string
@@ -511,6 +513,7 @@ export interface CreateStandaloneApiKeyRequest {
allowed_providers?: string[] | null
allowed_api_formats?: string[] | null
allowed_models?: string[] | null
ip_rules?: string[] | null
rate_limit?: number | null // null = 跟随系统默认0 = 不限制
concurrent_limit?: number | null // null = 跟随系统默认0 = 不限制
expires_at?: string | null // RFC3339 时间null = 永不过期

View File

@@ -175,7 +175,7 @@ export interface ApiKey {
total_cost_usd?: number
rate_limit?: number | null
concurrent_limit?: number | null
allowed_ips?: string[] | null
ip_rules?: string[] | null
allowed_providers?: ProviderConfig[]
force_capabilities?: Record<string, boolean> | null // 强制能力配置
feature_settings?: FeatureSettingsMap | null
@@ -255,7 +255,7 @@ export const meApi = {
return response.data
},
async createApiKey(data: { name: string; rate_limit?: number | null; concurrent_limit?: number | null; allowed_ips?: string[] | null; feature_settings?: FeatureSettingsMap | null }): Promise<ApiKey> {
async createApiKey(data: { name: string; rate_limit?: number | null; concurrent_limit?: number | null; ip_rules?: string[] | null; feature_settings?: FeatureSettingsMap | null }): Promise<ApiKey> {
const response = await apiClient.post<ApiKey>('/api/users/me/api-keys', data)
return response.data
},
@@ -288,7 +288,7 @@ export const meApi = {
async updateApiKey(
keyId: string,
data: { name?: string; rate_limit?: number | null; concurrent_limit?: number | null; allowed_ips?: string[] | null; feature_settings?: FeatureSettingsMap | null | undefined }
data: { name?: string; rate_limit?: number | null; concurrent_limit?: number | null; ip_rules?: string[] | null; feature_settings?: FeatureSettingsMap | null | undefined }
): Promise<ApiKey & { message: string }> {
const response = await apiClient.put<ApiKey & { message: string }>(
`/api/users/me/api-keys/${keyId}`,

View File

@@ -221,7 +221,7 @@ export interface ApiKey {
feature_settings?: FeatureSettings | null
rate_limit?: number | null // 普通Key: 0 = 不限制,历史 null 视为跟随系统默认
concurrent_limit?: number | null // 普通Key: 0 = 不限制并发,历史 null 兼容
allowed_ips?: string[] | null
ip_rules?: string[] | null
total_requests?: number // 总请求数
total_cost_usd?: number // 总费用
}
@@ -230,7 +230,7 @@ export interface UpsertUserApiKeyRequest {
name?: string
rate_limit?: number | null
concurrent_limit?: number | null
allowed_ips?: string[] | null
ip_rules?: string[] | null
feature_settings?: FeatureSettings | null
}