feat: implement OpenAI-compatible Realtime API with authentication and management features

- Added support for public Realtime API, including new routes for managing API keys and handling WebRTC connections.
- Introduced RealtimeApiKey model and associated CRUD operations for admin management of API keys.
- Implemented authentication mechanisms for API keys and client secrets.
- Enhanced environment configuration with new secrets for Realtime API.
- Created OpenAIRealtime session management and event processing for real-time interactions.
- Updated schemas and settings to accommodate new features and ensure compatibility with existing systems.
This commit is contained in:
Xin Wang
2026-08-11 10:05:55 +08:00
parent cf32ea605d
commit 86639692ba
28 changed files with 3286 additions and 128 deletions
+37 -1
View File
@@ -7,7 +7,7 @@ JSON 用 camelCase(modelId/interfaceType/apiUrl/apiKey),Python 内部用 snake_c
from __future__ import annotations
from datetime import datetime
from datetime import UTC, datetime
import re
from typing import Annotated, Any, Literal, Union
@@ -601,3 +601,39 @@ class AnalysisWebhookTestOut(CamelModel):
latency_ms: int | None = None
message: str
payload: dict[str, Any]
# ---------- Realtime API keys ----------
class RealtimeApiKeyCreate(CamelModel):
name: str = Field(min_length=1, max_length=128)
expires_at: datetime | None = None
@field_validator("name", mode="before")
@classmethod
def normalize_name(cls, value: object) -> object:
return value.strip() if isinstance(value, str) else value
@field_validator("expires_at")
@classmethod
def validate_expiry(cls, value: datetime | None) -> datetime | None:
if value is None:
return None
normalized = value if value.tzinfo else value.replace(tzinfo=UTC)
if normalized <= datetime.now(UTC):
raise ValueError("expires_at 必须晚于当前时间")
return normalized
class RealtimeApiKeyOut(CamelModel):
id: str
name: str
key_prefix: str
status: Literal["active", "expired", "revoked"]
expires_at: datetime | None = None
last_used_at: datetime | None = None
revoked_at: datetime | None = None
created_at: datetime
class RealtimeApiKeyCreated(RealtimeApiKeyOut):
key: str