-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
844 lines (783 loc) · 27.8 KB
/
Copy pathopenapi.yaml
File metadata and controls
844 lines (783 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
openapi: 3.0.3
info:
title: LLM Gateway
version: "1.0.0"
description: |
An asynchronous front door for an LLM backend. Every call that costs the
backend compute — a chat completion, a Responses call, an embedding, a
moderation — is **queued** and answered later. Nothing here streams and
nothing proxies synchronously, because a backend that serves one request
at a time has to be asked one at a time.
Two endpoints are the exception, and only because they cost the upstream
nothing to answer: `GET /v1/models` and `GET /v1/models/{id}` are cheap
idempotent reads every SDK makes before it can do anything at all. See
the `Synchronous` tag below.
Each queued endpoint is collected where it was posted — a completion from
`GET /v1/responses/{id}`, an embedding from `GET /v1/embeddings/{id}`, a
moderation from `GET /v1/moderations/{id}` — so a client only ever needs
the one base URL it was configured with.
## Passthrough
The gateway holds no credentials and validates nothing. There is no master
key, no shared secret, no user table. Whatever `Authorization` you send is
stored with the entry and replayed upstream unchanged; the upstream decides
whether it is any good. A wrong key is queued like everything else and then
fails with the upstream's own error stored verbatim.
The body goes upstream untouched — unknown fields are not stripped, a
missing `model` is not an error, `stream: true` is not refused (and is
stored as the raw stream rather than parsed text). Headers are replayed
from a fixed allowlist: `Authorization`, `Content-Type`, `Accept`,
`Accept-Language`, `User-Agent`, `X-Request-Id`, and anything prefixed
`X-Litellm-`, `OpenAI-` or `Anthropic-`. Everything else is dropped.
## Ownership
An entry belongs to the key that queued it. Read, cancel or delete it with
the same `Authorization` you used to create it. No other key can see that
it exists — a mismatch is `404`, never `403`, so the API never confirms an
id it will not serve.
Only a SHA-256 hash of the bearer token is kept. Queueing without a key
works and produces an entry owned by "no key", readable by any request that
likewise sends none. Set `API_REQUIRE_CALLER_KEY=true` and every `/v1`
route answers `401` until a caller sends one.
## Statuses
`queued → in_progress → completed | failed`, plus `cancelled` for entries
stopped before a worker claimed them. Retries loop back to `queued`; they
live on the entry, not in the queue.
## Rate limiting
Queueing is limited per caller key (`BACKLOG_RATE_LIMIT`, default 60/min) —
per IP if you send none — because an entry costs a row and a worker slot
before the upstream has seen it. Going over returns `429` with
`Retry-After`. **Reading is never throttled**; polling is the documented way
to collect an answer.
`POST /v1/embeddings` and `POST /v1/moderations` share this same budget,
even though neither is queued: both still cost the upstream real compute,
unlike `GET /v1/models`, which is a plain read and stays unthrottled.
license:
name: MIT
servers:
- url: https://llm.example.com{gatewayPrefix}
description: |
Set the host to your own. `gatewayPrefix` addresses one registered
upstream instead of the default.
variables:
gatewayPrefix:
default: ""
description: |
Empty to use the gateway flagged as default. Set to `/{gateway-id}`
— a UUID copied from the dashboard's Gateways page — to pin every
call to one upstream. Every route below answers under the prefix as
well as without it, so an SDK configured with
`base_url = https://your-host/{id}/v1` queues *and* polls against
that one upstream.
security:
- bearerAuth: []
tags:
- name: Queue
description: Creating entries. Rate limited.
- name: Collect
description: Reading, cancelling and deleting entries. Never throttled.
- name: Synchronous
description: |
Answered straight from the upstream, not through the backlog — the model
listings, and only them. They cost the upstream nothing to answer and
every SDK reads them before it can do anything else, so they stay
unthrottled reads.
- name: Health
paths:
/v1/moderations/{id}:
get:
tags: [Queued]
summary: Collect a queued moderation
description: |
The moderation counterpart of `GET /v1/embeddings/{id}`, with the same
rules: `202` while it waits, the upstream's own body once answered.
parameters:
- $ref: "#/components/parameters/EntryId"
responses:
"200":
description: The moderation result.
"202":
description: Still queued or running.
"404":
description: No such moderation for this caller.
"409":
description: Cancelled before a worker ran it.
/v1/models:
get:
tags: [Synchronous]
summary: List a gateway's models
description: |
Answered synchronously, not queued: listing models never touches a
backend's limited concurrent generation slots, so there is nothing to
gain by making a caller poll for it. Proxies straight to the resolved
gateway's upstream and normalises the answer into an OpenAI models
list, whatever the gateway's own protocol — Anthropic's `/v1/models`
and Ollama's native `/api/tags` are both translated the same way a
chat completion is.
responses:
"200":
description: The gateway's models, OpenAI-list shaped.
content:
application/json:
schema:
type: object
properties:
object:
type: string
enum: [list]
data:
type: array
items:
$ref: "#/components/schemas/Model"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/GatewayNotFound"
"502":
$ref: "#/components/responses/UpstreamUnreachable"
"default":
$ref: "#/components/responses/UpstreamError"
/v1/models/{id}:
get:
tags: [Synchronous]
summary: Retrieve one model
description: |
Reads the same list `GET /v1/models` does and returns the entry whose
`id` matches — there is no per-protocol "get one model" call, since
Ollama has nothing that answers by name the way OpenAI and Anthropic
do. `id` may contain a slash, for OpenRouter-style names such as
`anthropic/claude-3.5-sonnet`.
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: The matching model.
content:
application/json:
schema:
$ref: "#/components/schemas/Model"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
description: |
The gateway itself is unknown (`gateway_not_found`), or it is
known but does not list this model (`model_not_found`).
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"502":
$ref: "#/components/responses/UpstreamUnreachable"
"default":
$ref: "#/components/responses/UpstreamError"
/v1/embeddings:
post:
tags: [Queued]
summary: Create embeddings
description: |
Queued, like every other call that costs the upstream real compute.
Answers `202` with an id, a `poll_url` and the `queue` block; collect
the vectors from `GET /v1/embeddings/{id}`.
This used to answer inline, on the reasoning that no OpenAI client
polls for an embedding. That holds for a client embedding one sentence
and fails for the traffic this gateway exists for: an indexing run
fires tens of thousands of batches, and answering them inline let all
of them reach the backend at once. Queued, they are run one at a time
by the workers and retry on their own budget instead of failing in the
caller's hand.
Anthropic has no embeddings API; a gateway pointed at one records the
entry as failed with Anthropic's own `404`.
requestBody:
required: true
content:
application/json:
schema:
type: object
description: Any OpenAI-compatible embeddings body.
properties:
model:
type: string
input:
description: A string, or an array of strings.
oneOf:
- type: string
- type: array
items:
type: string
additionalProperties: true
responses:
"202":
description: Queued. Collect it from `poll_url`.
content:
application/json:
schema:
$ref: "#/components/schemas/QueuedCall"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/GatewayNotFound"
"429":
$ref: "#/components/responses/RateLimited"
"502":
$ref: "#/components/responses/UpstreamUnreachable"
"default":
$ref: "#/components/responses/UpstreamError"
/v1/embeddings/{id}:
get:
tags: [Queued]
summary: Collect a queued embedding
description: |
`202` with the same receipt the `POST` returned while the entry is
still queued or running — carrying `Retry-After` — and the upstream's
own OpenAI embeddings body once a worker has answered it. A failed
entry answers with the upstream's status; one cancelled before a
worker reached it answers `409`.
Scoped to the caller's own entries, and to embeddings: an id queued by
another endpoint reads as `404` here rather than being handed back in
a shape it was never meant to have.
parameters:
- $ref: "#/components/parameters/EntryId"
responses:
"200":
description: The embeddings, OpenAI-list shaped.
content:
application/json:
schema:
$ref: "#/components/schemas/EmbeddingList"
"202":
description: Still queued or running.
"404":
description: No such embedding for this caller.
"409":
description: Cancelled before a worker ran it.
/v1/moderations:
post:
tags: [Queued]
summary: Run a moderation check
description: |
Queued and collected the same way `POST /v1/embeddings` is, rate
limited the same way too. Answers `202`; the verdict is read back from
`GET /v1/moderations/{id}`. Only OpenAI-compatible upstreams have ever implemented this
endpoint — a gateway on Anthropic or Ollama forwards the request
anyway and passes that upstream's own `404` straight back, rather
than this app guessing at support it cannot verify.
requestBody:
required: true
content:
application/json:
schema:
type: object
description: Any OpenAI-compatible moderations body.
properties:
input:
description: A string, or an array of strings.
oneOf:
- type: string
- type: array
items:
type: string
model:
type: string
additionalProperties: true
responses:
"200":
description: The upstream's moderation result, passed through unchanged.
content:
application/json:
schema:
type: object
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/GatewayNotFound"
"429":
$ref: "#/components/responses/RateLimited"
"502":
$ref: "#/components/responses/UpstreamUnreachable"
"default":
$ref: "#/components/responses/UpstreamError"
/up:
get:
tags: [Health]
summary: Liveness
description: Answers `200` once the app has booted. No authentication.
security: []
responses:
"200":
description: The app is up.
/v1/chat/completions:
post:
tags: [Queue]
summary: Queue a chat completion
description: |
Accepts an OpenAI chat-completion body and queues it. The body is
forwarded upstream exactly as it arrived.
Returns `202` immediately with a `poll_url`. The answer is collected
from `GET /v1/responses/{id}` — the id is the same either way, because
both doors open onto one queue.
requestBody:
required: true
content:
application/json:
schema:
type: object
description: Any OpenAI-compatible chat-completion body.
properties:
model:
type: string
messages:
type: array
items:
type: object
priority:
type: integer
description: Higher runs sooner. Optional.
additionalProperties: true
example:
model: qwen3-vl:30b-a3b
messages:
- role: user
content: Say PONG
responses:
"202":
description: Queued.
content:
application/json:
schema:
$ref: "#/components/schemas/QueuedChatCompletion"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/GatewayNotFound"
"429":
$ref: "#/components/responses/RateLimited"
/v1/responses:
post:
tags: [Queue]
summary: Queue a response
description: |
The Responses API shape. This is the one exception to passthrough on
the caller's side: the request is translated into a chat completion,
because LiteLLM cannot serve `/v1/responses` from an Ollama backend.
Vision input follows the Responses API format — `input` as an array of
message objects whose `content` mixes `input_text` and `input_image`
parts. The answer lands in `output[0].content[0].text`.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
model:
type: string
input:
description: A string, or an array of Responses API messages.
oneOf:
- type: string
- type: array
items:
type: object
priority:
type: integer
description: Higher runs sooner. Optional.
additionalProperties: true
examples:
text:
summary: Plain text
value:
model: qwen3-vl:30b-a3b
input: Say PONG
vision:
summary: Vision input
value:
model: qwen3-vl:30b-a3b
priority: 10
input:
- role: user
content:
- type: input_text
text: Extract invoice number and total as JSON.
- type: input_image
image_url: "data:image/png;base64,…"
responses:
"202":
description: Queued, in the Responses API shape.
content:
application/json:
schema:
$ref: "#/components/schemas/Response"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/GatewayNotFound"
"429":
$ref: "#/components/responses/RateLimited"
get:
tags: [Collect]
summary: List your entries
description: |
Your recent entries only, scoped to the key that queued them. Filters
are optional. An unknown `status` is refused with `422` rather than
silently reading as "no entries".
Listing reports no `queue` block: counting a position per row would be
a query per entry on the endpoint that returns the most of them.
parameters:
- name: status
in: query
required: false
schema:
$ref: "#/components/schemas/Status"
- name: model
in: query
required: false
schema:
type: string
- name: limit
in: query
required: false
schema:
type: integer
responses:
"200":
description: Your entries, newest first.
content:
application/json:
schema:
type: object
properties:
object:
type: string
enum: [list]
data:
type: array
items:
$ref: "#/components/schemas/Response"
"401":
$ref: "#/components/responses/Unauthorized"
"422":
description: Unknown `status` filter.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/v1/responses/{id}:
parameters:
- $ref: "#/components/parameters/EntryId"
get:
tags: [Collect]
summary: Show one entry
description: |
Status, result and `queue` for a single entry. This is the polling
endpoint — it is never rate limited, and a queued entry also answers
`Retry-After`, which is the only backoff hint given.
`queue` is `null` for anything no longer waiting, so `queue` turning
`null` is the same signal as `status` leaving `queued`.
responses:
"200":
description: The entry.
content:
application/json:
schema:
$ref: "#/components/schemas/Response"
headers:
Retry-After:
description: Present while the entry is `queued`.
schema:
type: integer
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotYours"
delete:
tags: [Collect]
summary: Delete an entry
description: |
Removes the entry from the API. The row is kept — this is a soft
delete, and the backlog remains the archive.
responses:
"200":
description: Deleted.
content:
application/json:
schema:
type: object
properties:
id:
type: string
object:
type: string
enum: [response.deleted]
deleted:
type: boolean
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotYours"
/v1/responses/{id}/cancel:
parameters:
- $ref: "#/components/parameters/EntryId"
post:
tags: [Collect]
summary: Cancel a queued entry
description: |
Only while the entry is `queued`. A request already handed to the
backend cannot be stopped cleanly, so cancelling `in_progress` would
promise something this app cannot keep — that returns `409`.
responses:
"200":
description: Cancelled.
content:
application/json:
schema:
$ref: "#/components/schemas/Response"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotYours"
"409":
description: Not cancellable — the entry has already left `queued`.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: |
Replayed upstream unchanged and never validated here. It also decides
ownership: only this key can read back what it queued.
parameters:
EntryId:
name: id
in: path
required: true
description: The id returned when the entry was queued.
schema:
type: string
schemas:
Status:
type: string
enum: [queued, in_progress, completed, failed, cancelled]
Queue:
type: object
nullable: true
description: |
Present on anything still waiting, `null` otherwise. The estimate is a
projection, not a promise: the median of how long recent answers for
the same model actually took, multiplied by how many rounds of work sit
in front of you at the configured worker count. It cannot see a model
swap coming, so a queue with several models interleaved runs longer
than it says.
properties:
position:
type: integer
description: Counts the entry itself — first in line is `1`.
depth:
type: integer
description: The whole backlog, not just your own entries.
workers:
type: integer
estimated_seconds:
type: integer
description: Through to *your* answer, not to a worker picking it up.
estimated_completion_at:
type: integer
description: Unix timestamp.
QueuedChatCompletion:
type: object
properties:
id:
type: string
object:
type: string
enum: [chat.completion.queued]
status:
$ref: "#/components/schemas/Status"
model:
type: string
nullable: true
created:
type: integer
poll_url:
type: string
description: |
Path to poll, answered under whichever prefix you called — a client
with `base_url = /{gateway}/v1` is never handed a path outside it.
queue:
$ref: "#/components/schemas/Queue"
Response:
type: object
description: |
The OpenAI Responses API shape. `queue` is the one addition, kept in a
key of its own so the spec's own fields stay exactly as an SDK expects.
properties:
id:
type: string
object:
type: string
enum: [response]
created_at:
type: integer
status:
$ref: "#/components/schemas/Status"
model:
type: string
nullable: true
output:
type: array
description: |
Empty until the entry completes. A completed chat entry lists the
assistant's `message` item and one `function_call` item per tool the
model asked for — a turn that only asked for tools lists no message.
Answer the calls by sending `function_call_output` items back on the
next turn, or by posting the equivalent `tool` messages to
`/v1/chat/completions`.
items:
type: object
usage:
type: object
nullable: true
error:
type: object
nullable: true
description: The upstream's own error, stored verbatim.
queue:
$ref: "#/components/schemas/Queue"
Model:
type: object
description: |
One upstream model, always normalised to this shape regardless of the
gateway's protocol.
properties:
id:
type: string
object:
type: string
enum: [model]
created:
type: integer
nullable: true
description: Unix timestamp. `null` when the upstream did not report one.
owned_by:
type: string
QueuedCall:
type: object
description: The receipt for an accepted request, and what a poll returns while it waits.
properties:
id:
type: string
example: resp_019fc2d6a59b727dad5a92e4d8670822
object:
type: string
enum: [response.queued, embedding.queued, moderation.queued]
status:
type: string
enum: [queued, in_progress]
model:
type: string
nullable: true
created:
type: integer
poll_url:
type: string
description: Where to collect the answer, under the same prefix the caller posted to.
queue:
$ref: "#/components/schemas/Queue"
EmbeddingList:
type: object
properties:
object:
type: string
enum: [list]
data:
type: array
items:
$ref: "#/components/schemas/Embedding"
model:
type: string
usage:
type: object
Embedding:
type: object
properties:
object:
type: string
enum: [embedding]
embedding:
type: array
items:
type: number
index:
type: integer
Error:
type: object
properties:
error:
type: object
properties:
message:
type: string
type:
type: string
description: |
`async_only`, `gateway_not_found`, `invalid_request`,
`invalid_state`, `model_not_found`, `upstream_error` (the
upstream answered with an error of its own — `error.body`
carries it verbatim) or `upstream_unreachable`.
responses:
Unauthorized:
description: |
Only when `API_REQUIRE_CALLER_KEY=true`. It checks that a key *was*
sent, never whether it is any good — that stays the upstream's call.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
NotYours:
description: |
No such entry **for this key**. A mismatch is deliberately `404` rather
than `403`, so the API never confirms an id it will not serve.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
GatewayNotFound:
description: |
The gateway id in the path is unknown or deactivated
(`gateway_not_found`). Anything else unmatched under `/v1` answers
`404` with `async_only`.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
RateLimited:
description: Too many entries queued. Reading is never throttled.
headers:
Retry-After:
schema:
type: integer
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
UpstreamUnreachable:
description: The upstream could not be reached at all (`upstream_unreachable`).
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
UpstreamError:
description: |
Any status the upstream itself answered with is passed straight
through, body and all (`upstream_error`). Only reachable on a
synchronous endpoint — a queued request stores the same information
on the entry instead, see `Response.error`.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"