feat: add embeddings endpoint and config for OpenAI-compatible text embeddings via gateway

Add POST /openai/v1/embeddings route in openai_gateway router, new config fields for embedding upstream URL/model/key/enabled toggle with defaults pointing to OpenRouter Qwen3 8B, INTERNAL_EMBED_MODEL constant in config.py, documentation in docs_api.py and README.md describing the molodetz~embed model mapping, and embed-call tracking in gateway metrics alongside existing chat/vision counters.
This commit is contained in:
2026-06-14 01:06:18 +00:00
parent 1076696dec
commit c7770ee21a
17 changed files with 662 additions and 62 deletions
+7 -1
View File
@@ -336,7 +336,11 @@ endpoint at `/openai/v1/chat/completions` (plus a transparent `/openai/v1/*`
passthrough). It forwards to the configured upstream (DeepSeek by default) and, when a
request carries image content, first describes the image(s) via a vision model
(OpenRouter/Gemma by default) and inlines the description as text - so a vision-less
upstream can still answer. Enabled by default and configurable on `/admin/services`.
upstream can still answer. It also serves OpenAI-compatible **text embeddings** at
`/openai/v1/embeddings`: clients send the generic model `molodetz~embed`, which the gateway
maps to the configured embedding model (OpenRouter's Qwen3 8B embedding model by default,
$0.01 per 1M input tokens), with usage and cost tracked per call like chat and vision.
Enabled by default and configurable on `/admin/services`.
It is the **single point of truth for AI**: the news, bots, and guest Devii sessions call this
gateway by default instead of an external provider, send the generic model name `molodetz`,
@@ -370,12 +374,14 @@ Configuration on the Services tab:
| `gateway_instances` | `4` | Max concurrent upstream forwards per worker (pool + semaphore) |
| `gateway_timeout` | `300` | Upstream timeout (seconds); minimum five minutes; also bounds the vision describe-image call |
| `gateway_vision_enabled` / `_url` / `_model` / `_key` / `_cache_size` | on / OpenRouter / Gemma / env / 256 | Image-description augmentation |
| `gateway_embed_enabled` / `_url` / `_model` / `_key` | on / OpenRouter / Qwen3 8B / migrated | Embeddings at `/openai/v1/embeddings` (client model `molodetz~embed`) |
| `gateway_require_auth` | on | When off, the gateway is open |
| `gateway_allow_admins` / `gateway_allow_users` | on / off | Which DevPlace users may call it (any auth scheme) |
| `gateway_access_key` | empty | A standalone key (sent as `X-API-KEY`/Bearer) that always grants access |
| `gateway_internal_key` | auto (uuid4) | Auto-generated on boot; DevPlace's own services authenticate with this. Clear and restart to rotate |
| `gateway_price_cache_hit_per_m` / `_cache_miss_per_m` / `_output_per_m` | 0.0028 / 0.14 / 0.28 | Chat cost per 1M tokens, used when the upstream returns no native cost (DeepSeek) |
| `gateway_vision_price_input_per_m` / `_output_per_m` | 0 / 0 | Vision cost per 1M tokens, used only when the vision upstream returns no native cost |
| `gateway_embed_price_input_per_m` | 0.01 | Embeddings cost per 1M input tokens, used only when the embeddings upstream returns no native cost |
| `gateway_max_retries` / `gateway_retry_backoff_ms` | 2 / 250 | Retry attempts and linear backoff on timeout, connection error, or upstream 5xx |
| `gateway_circuit_threshold` / `gateway_circuit_cooldown_seconds` | 5 / 30 | Consecutive failures before the circuit breaker opens, and its cooldown |
| `gateway_usage_retention_hours` | 720 | How long per-call usage rows are kept before pruning (30 days) |