This commit is contained in:
2026-07-19 18:57:43 +02:00
parent 48bb6c2ec2
commit c53e2a3319
179 changed files with 9307 additions and 897 deletions
+38 -6
View File
@@ -5,7 +5,6 @@ from .._shared import endpoint, field
GROUP = {
"slug": "gateway",
"title": "OpenAI Gateway",
"admin": True,
"intro": """
# OpenAI Gateway
@@ -37,6 +36,26 @@ generic model `molodetz-img-small`, which the gateway maps to the configured ima
Flux 1.1 Pro by default). Cost is tracked per call with a flat per-image price when the upstream
returns no native cost.
## Quick start
Copy the command below and paste it into a terminal. If you are signed in the `{{ api_key }}`
and `{{ app_reference }}` placeholders are already filled in with your own values; otherwise
replace them with the API key from your [profile](/profile) page and any application identifier.
```bash
curl -X POST "{{ base }}/openai/v1/chat/completions" \
-H "Authorization: Bearer {{ api_key }}" \
-H "X-App-Reference: {{ app_reference }}" \
-H "Content-Type: application/json" \
-d '{
"model": "molodetz",
"messages": [{"role": "user", "content": "Hello, how are you?"}]
}'
```
The response carries `X-Gateway-*` headers with token counts and dollar cost for the call.
For streaming, add `"stream": true` to the JSON body.
## Model routing and providers
On top of the single default upstream above, an administrator can register additional named
@@ -90,6 +109,17 @@ Dollar costs use the upstream's native `cost` field when it returns one
model route, falling back to the prices configured on the `openai` service when no route matches. The
denied paths that make no upstream call (embeddings or image generation disabled) return no usage headers.
## Request header `X-App-Reference`
Clients **SHOULD** send an `X-App-Reference` header to identify themselves for cost attribution.
The value is a free-form slug (max 30 characters, letters, digits, `_`, `.`, `-`). When missing or
invalid, the gateway defaults to `default`. The value is recorded in every usage ledger row and can
be queried alongside owner-kind and owner-id to attribute spending per application.
```
X-App-Reference: devplace-devii-v-1-0-0
```
Administrators enable and configure this gateway under [Background Services](/docs/services.html)
(the `openai` service).
@@ -104,7 +134,7 @@ for signing DevPlace's own requests.
path="/openai/v1/chat/completions",
title="Chat completions",
summary="OpenAI-compatible chat completion. Supports streaming.",
auth="user",
auth="public",
encoding="json",
params=[
field(
@@ -113,7 +143,7 @@ for signing DevPlace's own requests.
"string",
False,
"gpt-4o-mini",
"Model id. When it matches a configured model route the gateway forwards to that route's provider and upstream model; otherwise it uses the default upstream model.",
"Model id. When it matches a configured model route the gateway forwards to that route's provider and upstream model; otherwise it falls back to the configured default upstream model.",
),
field(
"messages",
@@ -144,7 +174,7 @@ for signing DevPlace's own requests.
path="/openai/v1/embeddings",
title="Embeddings",
summary="OpenAI-compatible text embeddings. Request model molodetz~embed.",
auth="user",
auth="public",
encoding="json",
params=[
field(
@@ -175,6 +205,7 @@ for signing DevPlace's own requests.
notes=[
"Returns `503` when the gateway service is not running or embeddings are disabled.",
"Every response carries the `X-Gateway-*` token and dollar-cost headers (see Per-call cost and usage headers above).",
"If `model` matches a configured embed model route it is forwarded to that route's provider and upstream model; otherwise it falls back to the configured default embedding model.",
],
),
endpoint(
@@ -183,7 +214,7 @@ for signing DevPlace's own requests.
path="/openai/v1/images/generations",
title="Image generation",
summary="OpenAI-compatible image generation. Request model molodetz-img-small.",
auth="user",
auth="public",
encoding="json",
params=[
field(
@@ -222,6 +253,7 @@ for signing DevPlace's own requests.
notes=[
"Returns `503` when the gateway service is not running or image generation is disabled.",
"Every response carries the `X-Gateway-*` token and dollar-cost headers (see Per-call cost and usage headers above).",
"If `model` matches a configured image model route it is forwarded to that route's provider and upstream model; otherwise it falls back to the configured default image model.",
],
),
endpoint(
@@ -230,7 +262,7 @@ for signing DevPlace's own requests.
path="/openai/v1/{path}",
title="Passthrough",
summary="Any other /v1 path is forwarded to the upstream as-is.",
auth="user",
auth="public",
interactive=False,
params=[
field(
+49 -2
View File
@@ -136,7 +136,7 @@ four ways to sign requests.
"textarea",
False,
"Leave literary as is, only do punctuation and casing",
"Correction instruction, up to 2000 characters.",
"Correction instruction, up to 20000 characters.",
),
],
sample_response={
@@ -150,6 +150,53 @@ four ways to sign requests.
},
},
),
endpoint(
id="profile-interactions",
method="POST",
path="/profile/{username}/interactions",
title="Configure Devii interactive widgets",
summary="Enable or disable CA-IWP interactive prompts (ui_prompt) for this account, or reset to the administrator default. Guests always use the site default. Admins may target any user.",
auth="user",
encoding="form",
destructive=True,
params=[
field(
"username",
"path",
"string",
True,
"bob_test",
"Profile owner. Must be yourself unless you are an admin.",
),
field(
"enabled",
"form",
"boolean",
False,
"true",
"true to enable interactive widgets, false to disable. Ignored when reset is true.",
),
field(
"reset",
"form",
"boolean",
False,
"false",
"true to clear the user override and inherit the administrator default.",
),
],
sample_response={
"ok": True,
"redirect": "/profile/bob_test",
"data": {
"url": "/profile/bob_test",
"enabled": True,
"source": "user",
"default": True,
"override": True,
},
},
),
endpoint(
id="profile-ai-modifier",
method="POST",
@@ -190,7 +237,7 @@ four ways to sign requests.
"textarea",
False,
"Execute what is behind `@ai` (the prompt) and replace that part including `@ai`",
"Modifier instruction, up to 2000 characters.",
"Modifier instruction, up to 20000 characters.",
),
],
sample_response={