Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1027 lines (993 loc) · 29.7 KB
/
Copy pathopenapi.yaml
File metadata and controls
1027 lines (993 loc) · 29.7 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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: "3.0.3"
info:
title: Grob LLM Routing Proxy
description: |
Multi-provider LLM routing proxy. Routes requests to Anthropic, OpenAI,
Gemini, DeepSeek, Ollama, and other providers with automatic fallback,
format translation, streaming, tool calling, budget enforcement, and DLP.
version: "0.9.0"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
contact:
name: Grob
url: https://github.com/azerozero/grob
servers:
- url: http://[::1]:13456
description: Default local proxy (IPv6 localhost)
- url: http://127.0.0.1:13456
description: Local proxy (IPv4 localhost)
tags:
- name: LLM
description: LLM inference endpoints (Anthropic and OpenAI formats)
- name: Operations
description: Health, readiness, liveness, and metrics
- name: Config
description: Configuration management
- name: OAuth
description: OAuth token management for provider authentication
- name: HIT
description: Human Intent Token gateway — per-action human authorization for tool_use blocks
- name: Observability
description: Live event stream and provider scoring
paths:
/v1/messages:
post:
tags: [LLM]
summary: Create a message (Anthropic native format)
description: |
Send a conversation to the LLM and receive a response. Supports streaming
via SSE. The request is routed to the best available provider based on
the model, prompt rules, and task classification.
operationId: createMessage
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
parameters:
- $ref: "#/components/parameters/XRequestId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CanonicalRequest"
responses:
"200":
description: Successful response (buffered or SSE stream)
headers:
X-Request-Id:
schema:
type: string
X-Model-Deprecated:
description: Present if the requested model is marked deprecated
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicResponse"
text/event-stream:
schema:
type: string
description: SSE stream of message_start, content_block_delta, message_stop events
"401":
$ref: "#/components/responses/Unauthorized"
"429":
$ref: "#/components/responses/RateLimited"
"502":
description: All providers failed
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/v1/messages/count_tokens:
post:
tags: [LLM]
summary: Count tokens for a message
description: |
Estimate the token count for a request without sending it to a provider.
operationId: countTokens
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CanonicalRequest"
responses:
"200":
description: Token count estimate
content:
application/json:
schema:
type: object
properties:
input_tokens:
type: integer
/v1/chat/completions:
post:
tags: [LLM]
summary: Create chat completion (OpenAI compatible)
description: |
OpenAI-compatible endpoint. Accepts OpenAI chat completion requests,
translates them to Anthropic internal format, routes through the proxy,
and translates the response back to OpenAI format.
Supports streaming (stream: true returns SSE with OpenAI delta format).
operationId: createChatCompletion
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
parameters:
- $ref: "#/components/parameters/XRequestId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/OpenAIRequest"
responses:
"200":
description: Successful response
headers:
X-Request-Id:
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/OpenAIResponse"
text/event-stream:
schema:
type: string
description: SSE stream of chat.completion.chunk events
"401":
$ref: "#/components/responses/Unauthorized"
"429":
$ref: "#/components/responses/RateLimited"
"502":
description: All providers failed
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/v1/models:
get:
tags: [LLM]
summary: List available models
description: |
Returns a list of models configured in the proxy, in OpenAI-compatible
format. Each model includes its name and the provider mappings.
operationId: listModels
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: List of available models
content:
application/json:
schema:
type: object
properties:
object:
type: string
example: list
data:
type: array
items:
type: object
properties:
id:
type: string
example: claude-sonnet-4-20250514
object:
type: string
example: model
created:
type: integer
owned_by:
type: string
example: anthropic
/health:
get:
tags: [Operations]
summary: Health check
description: |
Returns service health including PID, active request count, and
current spend vs. budget. Always returns 200 if the process is up.
operationId: healthCheck
responses:
"200":
description: Service is healthy
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: ok
service:
type: string
example: grob
pid:
type: integer
active_requests:
type: integer
spend:
type: object
properties:
total_usd:
type: number
format: double
budget_usd:
type: number
format: double
/live:
get:
tags: [Operations]
summary: Liveness probe
description: |
Kubernetes liveness probe. Returns 200 if the process is alive.
Does not check provider connectivity.
operationId: livenessCheck
responses:
"200":
description: Process is alive
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: alive
/ready:
get:
tags: [Operations]
summary: Readiness probe
description: |
Kubernetes readiness probe. Returns 200 if providers are configured
and not all circuit breakers are open. Returns 503 otherwise.
operationId: readinessCheck
responses:
"200":
description: Service is ready to accept traffic
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: ready
providers:
type: integer
"503":
description: Service is not ready
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: not_ready
reason:
type: string
example: all circuit breakers open
/metrics:
get:
tags: [Operations]
summary: Prometheus metrics
description: |
Returns all metrics in Prometheus text exposition format.
Includes request counters, latency histograms, token counts,
spend gauges, circuit breaker states, and rate limit stats.
operationId: metrics
responses:
"200":
description: Prometheus metrics
content:
text/plain:
schema:
type: string
example: |
grob_requests_total{model="claude-sonnet-4-20250514",provider="anthropic",route_type="default",status="success"} 42
grob_request_duration_seconds_bucket{model="claude-sonnet-4-20250514",provider="anthropic",le="1"} 38
grob_active_requests 2
grob_spend_usd 12.34
grob_budget_limit_usd 50.0
/api/config:
get:
tags: [Config]
summary: Get current configuration
description: |
Returns the current running configuration as JSON. API keys are
redacted (first 4 + last 4 characters shown).
operationId: getConfig
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: Current configuration (keys redacted)
content:
application/json:
schema:
type: object
properties:
server:
type: object
router:
type: object
providers:
type: array
items:
type: object
models:
type: array
items:
type: object
post:
tags: [Config]
summary: Update configuration
description: |
Writes updated configuration to the config file. Only works when
config is loaded from a local file (not a remote URL). Does NOT
reload the running config -- call /api/config/reload after saving.
operationId: updateConfig
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
requestBody:
required: true
content:
application/json:
schema:
type: object
description: Partial config to merge (providers, models, router sections)
responses:
"200":
description: Configuration saved
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: success
message:
type: string
"400":
description: Parse error or remote config (read-only)
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/api/config/reload:
post:
tags: [Config]
summary: Reload configuration
description: |
Re-reads the configuration from its source (file or URL), rebuilds
the router and provider registry, and atomically swaps the running
config. In-flight requests continue using the previous config snapshot.
operationId: reloadConfig
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: Configuration reloaded
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: success
message:
type: string
active_requests:
type: integer
description: Number of requests still using the old config
/api/oauth/authorize:
post:
tags: [OAuth]
summary: Start OAuth authorization flow
description: |
Returns an authorization URL for the user to visit. Supports
Anthropic (Max/Console), OpenAI Codex, and Gemini OAuth flows.
Uses PKCE for security.
operationId: oauthAuthorize
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
oauth_type:
type: string
enum: [max, console, openai-codex, gemini]
default: max
description: Type of OAuth flow
responses:
"200":
description: Authorization URL and PKCE verifier
content:
application/json:
schema:
type: object
properties:
url:
type: string
format: uri
verifier:
type: string
instructions:
type: string
/api/oauth/exchange:
post:
tags: [OAuth]
summary: Exchange authorization code for tokens
description: |
Exchanges the authorization code received from the OAuth callback
for access and refresh tokens. Stores them persistently.
operationId: oauthExchange
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [code, verifier, provider_id]
properties:
code:
type: string
verifier:
type: string
provider_id:
type: string
oauth_type:
type: string
responses:
"200":
description: Token exchange successful
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
message:
type: string
provider_id:
type: string
expires_at:
type: string
format: date-time
/api/oauth/callback:
get:
tags: [OAuth]
summary: OAuth callback
description: |
Handles the OAuth redirect callback. Returns an HTML page that
displays the authorization code for the user to copy, or
auto-exchanges it if configured.
operationId: oauthCallback
parameters:
- name: code
in: query
required: true
schema:
type: string
- name: state
in: query
schema:
type: string
responses:
"200":
description: HTML page with authorization code
content:
text/html:
schema:
type: string
/auth/callback:
get:
tags: [OAuth]
summary: OAuth callback (alias)
description: |
Alias for /api/oauth/callback. Used by OpenAI Codex which expects
this exact path. Also served on a separate listener at 127.0.0.1:1455.
operationId: oauthCallbackAlias
parameters:
- name: code
in: query
required: true
schema:
type: string
responses:
"200":
description: HTML page with authorization code
content:
text/html:
schema:
type: string
/api/oauth/tokens:
get:
tags: [OAuth]
summary: List stored OAuth tokens
description: |
Returns a list of all stored OAuth tokens with their provider ID,
expiration time, and whether they need refresh.
operationId: oauthListTokens
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: List of tokens
content:
application/json:
schema:
type: array
items:
type: object
properties:
provider_id:
type: string
expires_at:
type: string
format: date-time
is_expired:
type: boolean
needs_refresh:
type: boolean
/api/oauth/tokens/delete:
post:
tags: [OAuth]
summary: Delete an OAuth token
description: Removes a stored OAuth token for the given provider.
operationId: oauthDeleteToken
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [provider_id]
properties:
provider_id:
type: string
responses:
"200":
description: Token deleted
/api/oauth/tokens/refresh:
post:
tags: [OAuth]
summary: Refresh an OAuth token
description: Forces an immediate refresh of the OAuth token for the given provider.
operationId: oauthRefreshToken
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [provider_id]
properties:
provider_id:
type: string
responses:
"200":
description: Token refreshed
/api/hit/approve:
post:
tags: [HIT]
summary: Approve or deny a pending HIT tool_use action
description: |
Resolves a pending HIT approval pause in a streaming response.
- **Simple** (`auth_method: prompt`): first caller decides. Returns `200 OK`.
- **MultiSig** (`auth_method: multisig`): one signature per call; returns `202 Accepted`
while collecting, `200 OK` when quorum is reached. `signer` is required.
- **Quorum** (`auth_method: quorum`): one vote per call; returns `202 Accepted` while
gathering, `200 OK` on decision.
- `404 Not Found` if no pending approval matches the `request_id`/`tool_name` pair.
operationId: hitApprove
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [request_id, tool_name, approved]
properties:
request_id:
type: string
description: Correlation ID from the HIT approval request event.
tool_name:
type: string
description: Name of the tool_use block to approve or deny.
approved:
type: boolean
description: "`true` to approve, `false` to deny."
signer:
type: string
description: Signer identity (e.g. `alice@company.com`). Required for multisig.
responses:
"200":
description: Decision applied — stream resumes or tool_use is dropped.
"202":
description: Vote/signature recorded — waiting for more approvals.
"404":
description: No pending approval found for this request_id/tool_name pair.
/api/events:
get:
tags: [Observability]
summary: Live event stream (SSE)
description: |
Server-Sent Events stream of dispatch pipeline events. Connect with
`Accept: text/event-stream`. Each event is a JSON-serialized `WatchEvent`.
Event types emitted:
- `request_start` — request entered dispatch
- `request_end` — request completed (with cost and latency)
- `request_error` — provider error
- `dlp_action` — DLP engine took action
- `fallback` — provider failover occurred
- `circuit_breaker` — circuit breaker state changed
- `provider_health` — periodic provider health snapshot
- `hit_approval_request` — HIT stream paused, human approval needed
- `hit_approval_response` — HIT approval decision received
- `hit_flagged_content` — dangerous pattern detected in response text
operationId: watchEvents
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: SSE stream
content:
text/event-stream:
schema:
type: string
/api/scores:
get:
tags: [Observability]
summary: Provider adaptive scores
description: |
Returns current adaptive scores for all providers when adaptive scoring
is enabled (`security.adaptive_scoring = true`). Scores reflect recent
latency and error rate and are used to re-order provider fallback chains.
operationId: getScores
security:
- bearerAuth: []
- apiKeyHeader: []
- {}
responses:
"200":
description: Provider scores map (provider name → score 0.0–1.0)
content:
application/json:
schema:
type: object
additionalProperties:
type: number
format: double
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: API key or JWT passed as Bearer token
apiKeyHeader:
type: apiKey
in: header
name: x-api-key
description: API key passed as x-api-key header
parameters:
XRequestId:
name: X-Request-Id
in: header
description: Optional request correlation ID. Generated as UUID v4 if not provided.
schema:
type: string
format: uuid
schemas:
CanonicalRequest:
type: object
required: [model, messages, max_tokens]
properties:
model:
type: string
description: Model name (routed by the proxy)
example: claude-sonnet-4-20250514
messages:
type: array
items:
$ref: "#/components/schemas/Message"
max_tokens:
type: integer
minimum: 1
example: 1024
thinking:
type: object
properties:
type:
type: string
enum: [enabled, disabled]
budget_tokens:
type: integer
description: Extended thinking configuration
temperature:
type: number
format: float
minimum: 0
maximum: 1
top_p:
type: number
format: float
top_k:
type: integer
stop_sequences:
type: array
items:
type: string
stream:
type: boolean
default: false
system:
description: System prompt (string or array of blocks)
oneOf:
- type: string
- type: array
items:
type: object
properties:
type:
type: string
text:
type: string
cache_control:
type: object
tools:
type: array
items:
type: object
description: Tool definition (Anthropic format)
tool_choice:
description: Tool choice constraint
metadata:
type: object
additionalProperties: true
Message:
type: object
required: [role, content]
properties:
role:
type: string
enum: [user, assistant]
content:
description: String or array of content blocks
oneOf:
- type: string
- type: array
items:
type: object
AnthropicResponse:
type: object
properties:
id:
type: string
type:
type: string
example: message
role:
type: string
example: assistant
content:
type: array
items:
type: object
properties:
type:
type: string
text:
type: string
model:
type: string
stop_reason:
type: string
enum: [end_turn, max_tokens, stop_sequence, tool_use]
usage:
type: object
properties:
input_tokens:
type: integer
output_tokens:
type: integer
OpenAIRequest:
type: object
required: [model, messages]
properties:
model:
type: string
example: claude-sonnet-4-20250514
messages:
type: array
items:
type: object
required: [role]
properties:
role:
type: string
enum: [system, user, assistant, tool]
content:
description: String or array of content parts
oneOf:
- type: string
- type: array
items:
type: object
tool_calls:
type: array
items:
type: object
tool_call_id:
type: string
max_tokens:
type: integer
temperature:
type: number
format: float
top_p:
type: number
format: float
stop:
type: array
items:
type: string
stream:
type: boolean
default: false
tools:
type: array
items:
type: object
tool_choice:
description: Tool choice constraint (OpenAI format)
OpenAIResponse:
type: object
properties:
id:
type: string
object:
type: string
example: chat.completion
created:
type: integer
model:
type: string
choices:
type: array
items:
type: object
properties:
index:
type: integer
message:
type: object
properties:
role:
type: string
content:
type: string
nullable: true
tool_calls:
type: array
items:
type: object
properties:
id:
type: string
type:
type: string
function:
type: object
properties:
name:
type: string
arguments:
type: string
finish_reason:
type: string
enum: [stop, length, tool_calls]
usage:
type: object
properties:
prompt_tokens:
type: integer
completion_tokens:
type: integer
total_tokens:
type: integer
Error:
type: object
properties:
error:
type: object
properties:
type:
type: string
example: api_error
message:
type: string
example: All providers failed for model claude-sonnet-4-20250514
responses:
Unauthorized:
description: Authentication failed
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
type:
type: string
example: authentication_error