-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopenapi.yaml
More file actions
726 lines (707 loc) · 20.5 KB
/
openapi.yaml
File metadata and controls
726 lines (707 loc) · 20.5 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
openapi: 3.0.3
info:
title: LLM Proxy API
description: |
API specification for the LLM Proxy service, which provides transparent proxying
for OpenAI LLM API calls with token-based authentication, rate limiting, and
usage tracking.
version: 1.0.0
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: 'http://localhost:8080'
description: Development server
paths:
/health:
get:
summary: Health check endpoint
description: Checks if the service is up and running
operationId: healthCheck
tags:
- Health
responses:
'200':
description: Service is healthy
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
/manage/projects:
get:
summary: List all projects
description: Returns a list of all projects in the system
operationId: listProjects
tags:
- Projects
security:
- ManagementToken: []
responses:
'200':
description: List of projects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Project'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
post:
summary: Create a new project
description: Creates a new project with the provided details
operationId: createProject
tags:
- Projects
security:
- ManagementToken: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ProjectRequest'
responses:
'201':
description: Project created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Project'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/manage/projects/{projectId}:
parameters:
- name: projectId
in: path
description: Project ID
required: true
schema:
type: string
format: uuid
get:
summary: Get project details
description: Returns details for a specific project
operationId: getProject
tags:
- Projects
security:
- ManagementToken: []
responses:
'200':
description: Project details
content:
application/json:
schema:
$ref: '#/components/schemas/Project'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
patch:
summary: Update project
description: Updates an existing project (partial update; name and/or api_key)
operationId: updateProject
tags:
- Projects
security:
- ManagementToken: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ProjectUpdateRequest'
responses:
'200':
description: Project updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Project'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
delete:
summary: Delete project
description: Deletes a project and all associated tokens
operationId: deleteProject
tags:
- Projects
security:
- ManagementToken: []
responses:
'204':
description: Project deleted successfully
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
/manage/projects/{projectId}/tokens/revoke:
parameters:
- name: projectId
in: path
description: Project ID
required: true
schema:
type: string
format: uuid
post:
summary: Bulk revoke all tokens for a project
description: Revokes (deactivates) all active tokens associated with a project
operationId: bulkRevokeProjectTokens
tags:
- Tokens
security:
- ManagementToken: []
responses:
'200':
description: Bulk token revocation completed
content:
application/json:
schema:
type: object
properties:
revoked_count:
type: integer
description: Number of tokens successfully revoked
example: 5
already_revoked_count:
type: integer
description: Number of tokens that were already inactive
example: 2
total_tokens:
type: integer
description: Total number of tokens for the project
example: 7
failed_count:
type: integer
description: Number of tokens that failed to revoke
example: 0
required:
- revoked_count
- already_revoked_count
- total_tokens
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
description: Project not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
$ref: '#/components/responses/InternalServerError'
/manage/tokens:
get:
summary: List all tokens
description: Returns a list of all tokens in the system
operationId: listTokens
tags:
- Tokens
security:
- ManagementToken: []
parameters:
- name: projectId
in: query
description: Filter tokens by project ID
required: false
schema:
type: string
format: uuid
- name: activeOnly
in: query
description: Filter to only return active tokens
required: false
schema:
type: boolean
responses:
'200':
description: List of tokens
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Token'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
post:
summary: Create a new token
description: Creates a new token for a specified project
operationId: createToken
tags:
- Tokens
security:
- ManagementToken: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TokenRequest'
responses:
'201':
description: Token created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Token'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
description: Project not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
$ref: '#/components/responses/InternalServerError'
/manage/tokens/{tokenId}:
parameters:
- name: tokenId
in: path
description: Token ID
required: true
schema:
type: string
format: uuid
get:
summary: Get token details
description: Returns details for a specific token
operationId: getToken
tags:
- Tokens
security:
- ManagementToken: []
responses:
'200':
description: Token details
content:
application/json:
schema:
$ref: '#/components/schemas/Token'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
patch:
summary: Update token
description: Updates token properties like active status or request limits
operationId: updateToken
tags:
- Tokens
security:
- ManagementToken: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TokenUpdateRequest'
responses:
'200':
description: Token updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Token'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
delete:
summary: Revoke token
description: Revokes (deactivates) a token
operationId: revokeToken
tags:
- Tokens
security:
- ManagementToken: []
responses:
'204':
description: Token revoked successfully
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
/v1/{path}:
parameters:
- name: path
in: path
description: OpenAI API path
required: true
schema:
type: string
get:
summary: Proxy GET requests to OpenAI API
description: Forwards GET requests to OpenAI API with token authentication
operationId: proxyOpenAIGet
tags:
- Proxy
security:
- TokenAuth: []
responses:
'200':
description: Successful response from OpenAI API
headers:
X-Request-ID:
description: Unique request identifier for tracing
schema:
type: string
X-LLM-Proxy-Remote-Duration-Ms:
description: Time spent on upstream API call in milliseconds
schema:
type: integer
content:
application/json:
schema:
type: object
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
description: Project is inactive or access denied
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error: "Project is inactive"
code: "project_inactive"
'404':
$ref: '#/components/responses/NotFound'
'429':
$ref: '#/components/responses/TooManyRequests'
'500':
$ref: '#/components/responses/InternalServerError'
'503':
description: Service temporarily unavailable
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error: "Service temporarily unavailable"
code: "service_unavailable"
post:
summary: Proxy POST requests to OpenAI API
description: Forwards POST requests to OpenAI API with token authentication
operationId: proxyOpenAIPost
tags:
- Proxy
security:
- TokenAuth: []
requestBody:
description: Body to forward to OpenAI API
required: true
content:
application/json:
schema:
type: object
responses:
'200':
description: Successful response from OpenAI API
headers:
X-Request-ID:
description: Unique request identifier for tracing
schema:
type: string
X-LLM-Proxy-Remote-Duration-Ms:
description: Time spent on upstream API call in milliseconds
schema:
type: integer
content:
application/json:
schema:
type: object
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
description: Project is inactive or access denied
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error: "Project is inactive"
code: "project_inactive"
'404':
$ref: '#/components/responses/NotFound'
'429':
$ref: '#/components/responses/TooManyRequests'
'500':
$ref: '#/components/responses/InternalServerError'
'503':
description: Service temporarily unavailable
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error: "Service temporarily unavailable"
code: "service_unavailable"
components:
schemas:
HealthResponse:
type: object
properties:
status:
type: string
description: Health status of the service
example: "ok"
version:
type: string
description: Version of the service
example: "1.0.0"
timestamp:
type: string
format: date-time
description: Timestamp of the health check
example: "2023-09-15T14:30:45Z"
Project:
type: object
properties:
id:
type: string
format: uuid
description: Unique identifier for the project
example: "123e4567-e89b-12d3-a456-426614174000"
name:
type: string
description: Name of the project
example: "My AI Project"
is_active:
type: boolean
description: Whether the project is active
example: true
created_at:
type: string
format: date-time
description: When the project was created
example: "2023-09-15T14:30:45Z"
updated_at:
type: string
format: date-time
description: When the project was last updated
example: "2023-09-15T14:30:45Z"
required:
- id
- name
- is_active
- created_at
- updated_at
ProjectRequest:
type: object
properties:
name:
type: string
description: Name of the project
example: "My AI Project"
api_key:
type: string
description: Upstream API key (will be encrypted at rest)
example: "sk-abcdefghijklmnopqrstuvwxyz1234567890ABCDEFG"
required:
- name
- api_key
ProjectUpdateRequest:
type: object
properties:
name:
type: string
description: New project name
api_key:
type: string
description: New upstream API key
is_active:
type: boolean
description: Whether the project is active
# No required fields; partial update
Token:
type: object
properties:
token:
type: string
format: uuid
description: The token value
example: "123e4567-e89b-12d3-a456-426614174000"
project_id:
type: string
format: uuid
description: ID of the project this token belongs to
example: "123e4567-e89b-12d3-a456-426614174000"
expires_at:
type: string
format: date-time
description: When the token expires
example: "2023-12-31T23:59:59Z"
is_active:
type: boolean
description: Whether the token is active
example: true
request_count:
type: integer
description: Number of requests made with this token
example: 42
max_requests:
type: integer
description: Maximum number of requests allowed for this token (0 = unlimited)
example: 1000
created_at:
type: string
format: date-time
description: When the token was created
example: "2023-09-15T14:30:45Z"
last_used_at:
type: string
format: date-time
nullable: true
description: When the token was last used
example: "2023-09-15T14:30:45Z"
required:
- token
- project_id
- expires_at
- is_active
- request_count
- max_requests
- created_at
TokenRequest:
type: object
properties:
project_id:
type: string
format: uuid
description: ID of the project for which to create a token
example: "123e4567-e89b-12d3-a456-426614174000"
expires_in_days:
type: integer
description: Number of days until the token expires (default 30, 0 = never expires)
example: 30
max_requests:
type: integer
description: Maximum number of requests allowed (default 0 = unlimited)
example: 1000
required:
- project_id
Error:
type: object
properties:
code:
type: string
description: Error code
example: "invalid_request"
message:
type: string
description: Error message
example: "Invalid request parameters"
required:
- code
- message
TokenUpdateRequest:
type: object
properties:
is_active:
type: boolean
description: Whether the token is active
max_requests:
type: integer
description: Maximum number of requests allowed (0 = unlimited)
# No required fields; partial update
ErrorResponse:
type: object
properties:
error:
type: string
description: Error message
example: "Project is inactive"
code:
type: string
description: Error code
example: "project_inactive"
description:
type: string
description: Additional error description
example: "The project associated with this token is currently inactive"
required:
- error
- code
responses:
BadRequest:
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Unauthorized:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Forbidden:
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
NotFound:
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
TooManyRequests:
description: Too many requests
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
InternalServerError:
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
securitySchemes:
ManagementToken:
type: http
scheme: bearer
description: Management token for admin operations
TokenAuth:
type: http
scheme: bearer
description: Token for authenticating proxy requests