-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathopenapi.yaml
More file actions
769 lines (739 loc) · 21.5 KB
/
openapi.yaml
File metadata and controls
769 lines (739 loc) · 21.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
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
openapi: 3.0.3
info:
title: LLM Observatory Analytics API
description: |
Enterprise-grade REST API for querying and analyzing LLM traces, metrics, and performance data.
## Features
- Advanced filtering with 13 operators (eq, ne, gt, gte, lt, lte, in, not_in, contains, not_contains, starts_with, ends_with, regex, search)
- Full-text search with PostgreSQL GIN indexes
- Cursor-based pagination for stable, efficient paging
- Redis caching for repeated queries
- JWT authentication and RBAC
- Rate limiting based on user role
## Authentication
All endpoints require authentication via JWT token in the Authorization header:
```
Authorization: Bearer <jwt_token>
```
## Rate Limits
- Admin: 100,000 requests/minute
- Developer: 10,000 requests/minute
- Viewer: 1,000 requests/minute
- Billing: 1,000 requests/minute
Rate limit information is included in response headers:
- `X-RateLimit-Limit`: Total requests allowed
- `X-RateLimit-Remaining`: Remaining requests
- `X-RateLimit-Reset`: Unix timestamp when limit resets
version: 1.0.0
contact:
name: LLM Observatory Team
email: support@llm-observatory.example.com
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: http://localhost:8080
description: Local development server
- url: https://api.llm-observatory.example.com
description: Production server
tags:
- name: Traces
description: Query and retrieve LLM traces
- name: Health
description: Health check and monitoring
paths:
/health:
get:
summary: Health check
description: Check the health status of the API, database, and Redis
operationId: healthCheck
tags:
- Health
responses:
'200':
description: Service is healthy
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
'503':
description: Service is degraded or unhealthy
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
/api/v1/traces:
get:
summary: List traces
description: |
Retrieve a paginated list of traces with optional filtering.
This endpoint supports basic filtering using query parameters.
For advanced filtering with complex logical operators, use POST /api/v1/traces/search.
operationId: listTraces
tags:
- Traces
security:
- BearerAuth: []
parameters:
- name: from
in: query
description: Start time (ISO 8601 or relative like "now-1h")
schema:
type: string
format: date-time
example: "2025-11-01T00:00:00Z"
- name: to
in: query
description: End time (ISO 8601 or relative)
schema:
type: string
format: date-time
example: "2025-11-05T23:59:59Z"
- name: project_id
in: query
description: Filter by project ID (required for non-admin users)
schema:
type: string
example: "project-123"
- name: provider
in: query
description: Filter by provider (e.g., "openai", "anthropic")
schema:
type: string
example: "openai"
- name: model
in: query
description: Filter by model (e.g., "gpt-4", "claude-3-opus")
schema:
type: string
example: "gpt-4"
- name: status
in: query
description: Filter by status code
schema:
type: string
example: "SUCCESS"
- name: min_duration
in: query
description: Minimum duration in milliseconds
schema:
type: integer
example: 1000
- name: max_duration
in: query
description: Maximum duration in milliseconds
schema:
type: integer
example: 5000
- name: min_cost
in: query
description: Minimum cost in USD
schema:
type: number
format: float
example: 0.01
- name: max_cost
in: query
description: Maximum cost in USD
schema:
type: number
format: float
example: 1.0
- name: environment
in: query
description: Filter by environment
schema:
type: string
example: "production"
- name: user_id
in: query
description: Filter by user ID
schema:
type: string
- name: session_id
in: query
description: Filter by session ID
schema:
type: string
- name: search
in: query
description: Full-text search in input/output (basic ILIKE search)
schema:
type: string
- name: cursor
in: query
description: Pagination cursor from previous response
schema:
type: string
- name: limit
in: query
description: Number of results per page (1-1000)
schema:
type: integer
minimum: 1
maximum: 1000
default: 50
- name: sort_by
in: query
description: Field to sort by
schema:
type: string
default: "ts"
- name: sort_order
in: query
description: Sort order
schema:
type: string
enum: [asc, desc]
default: desc
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedTraceResponse'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'429':
$ref: '#/components/responses/RateLimitExceeded'
/api/v1/traces/search:
post:
summary: Advanced trace search
description: |
Search traces using advanced filters with complex logical operators.
## Features
- 13 filter operators: eq, ne, gt, gte, lt, lte, in, not_in, contains, not_contains, starts_with, ends_with, regex, search
- Logical operators: AND, OR, NOT with unlimited nesting
- Full-text search using PostgreSQL GIN indexes (40-500x faster than ILIKE)
- Field selection to return only needed fields
- Custom sorting with direction control
- Cursor-based pagination
- Redis caching
## Performance
- Simple filters: 10-30ms
- Complex nested filters: 30-100ms
- Full-text search: 20-80ms
operationId: searchTraces
tags:
- Traces
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AdvancedSearchRequest'
examples:
simpleFilter:
summary: Simple equality filter
value:
filter:
field: "provider"
operator: "eq"
value: "openai"
limit: 50
complexFilter:
summary: Complex nested filter with full-text search
value:
filter:
operator: "and"
filters:
- field: "provider"
operator: "eq"
value: "openai"
- field: "input_text"
operator: "search"
value: "authentication error"
- operator: "or"
filters:
- field: "duration_ms"
operator: "gte"
value: 1000
- field: "total_cost_usd"
operator: "gt"
value: 0.1
sort_by: "ts"
sort_desc: true
limit: 100
fields: ["trace_id", "provider", "model", "duration_ms", "total_cost_usd"]
fullTextSearch:
summary: Full-text search with ranking
value:
filter:
field: "input_text"
operator: "search"
value: "generate code for authentication"
sort_by: "ts"
sort_desc: true
limit: 50
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedTraceResponse'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'429':
$ref: '#/components/responses/RateLimitExceeded'
/api/v1/traces/{trace_id}:
get:
summary: Get trace by ID
description: Retrieve a single trace by its trace ID
operationId: getTraceById
tags:
- Traces
security:
- BearerAuth: []
parameters:
- name: trace_id
in: path
required: true
description: Trace ID to retrieve
schema:
type: string
example: "trace-abc123"
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/SingleTraceResponse'
'404':
$ref: '#/components/responses/NotFound'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: JWT token obtained from authentication endpoint
schemas:
HealthResponse:
type: object
required:
- status
- database
- redis
- timestamp
properties:
status:
type: string
enum: [healthy, degraded]
description: Overall service status
database:
type: string
enum: [healthy, unhealthy]
description: Database connection status
redis:
type: string
enum: [healthy, unhealthy]
description: Redis connection status
timestamp:
type: string
format: date-time
description: Timestamp of health check
Trace:
type: object
required:
- ts
- trace_id
- span_id
properties:
ts:
type: string
format: date-time
description: Timestamp of the trace
trace_id:
type: string
description: Unique trace identifier
span_id:
type: string
description: Unique span identifier
parent_span_id:
type: string
nullable: true
description: Parent span identifier for nested spans
service_name:
type: string
nullable: true
description: Name of the service that generated the trace
span_name:
type: string
nullable: true
description: Name of the span
provider:
type: string
description: LLM provider (e.g., "openai", "anthropic")
model:
type: string
description: Model name (e.g., "gpt-4", "claude-3-opus")
input_text:
type: string
nullable: true
description: Input prompt or text
output_text:
type: string
nullable: true
description: Generated output text
prompt_tokens:
type: integer
nullable: true
description: Number of prompt tokens
completion_tokens:
type: integer
nullable: true
description: Number of completion tokens
total_tokens:
type: integer
nullable: true
description: Total tokens (prompt + completion)
prompt_cost_usd:
type: number
format: float
nullable: true
description: Cost of prompt tokens in USD
completion_cost_usd:
type: number
format: float
nullable: true
description: Cost of completion tokens in USD
total_cost_usd:
type: number
format: float
nullable: true
description: Total cost in USD
duration_ms:
type: integer
nullable: true
description: Request duration in milliseconds
ttft_ms:
type: integer
nullable: true
description: Time to first token in milliseconds
status_code:
type: string
description: Status code (e.g., "SUCCESS", "ERROR")
error_message:
type: string
nullable: true
description: Error message if request failed
user_id:
type: string
nullable: true
description: User identifier
session_id:
type: string
nullable: true
description: Session identifier
environment:
type: string
nullable: true
description: Environment (e.g., "production", "staging")
tags:
type: array
items:
type: string
nullable: true
description: Tags associated with the trace
attributes:
type: object
nullable: true
additionalProperties: true
description: Additional attributes as JSON
PaginatedTraceResponse:
type: object
required:
- status
- data
- pagination
- meta
properties:
status:
type: string
enum: [success]
data:
type: array
items:
$ref: '#/components/schemas/Trace'
pagination:
$ref: '#/components/schemas/PaginationMetadata'
meta:
$ref: '#/components/schemas/ResponseMetadata'
SingleTraceResponse:
type: object
required:
- status
- data
- meta
properties:
status:
type: string
enum: [success]
data:
$ref: '#/components/schemas/Trace'
meta:
$ref: '#/components/schemas/ResponseMetadata'
PaginationMetadata:
type: object
required:
- has_more
- limit
properties:
cursor:
type: string
nullable: true
description: Cursor for next page (base64 encoded)
has_more:
type: boolean
description: Whether more results are available
limit:
type: integer
description: Number of results per page
total:
type: integer
nullable: true
description: Total count (null to avoid expensive COUNT queries)
ResponseMetadata:
type: object
required:
- timestamp
- execution_time_ms
- cached
- version
properties:
timestamp:
type: string
format: date-time
description: Response timestamp
execution_time_ms:
type: integer
description: Execution time in milliseconds
cached:
type: boolean
description: Whether response was served from cache
version:
type: string
description: API version
request_id:
type: string
nullable: true
description: Unique request identifier for tracing
AdvancedSearchRequest:
type: object
properties:
filter:
oneOf:
- $ref: '#/components/schemas/FieldFilter'
- $ref: '#/components/schemas/LogicalFilter'
nullable: true
description: Filter criteria (optional)
sort_by:
type: string
nullable: true
description: Field to sort by
example: "ts"
sort_desc:
type: boolean
default: false
description: Sort in descending order
cursor:
type: string
nullable: true
description: Pagination cursor
limit:
type: integer
minimum: 1
maximum: 1000
default: 50
description: Number of results per page
fields:
type: array
items:
type: string
nullable: true
description: Fields to include in response (omit for all fields)
example: ["trace_id", "provider", "model", "duration_ms"]
FieldFilter:
type: object
required:
- field
- operator
- value
properties:
field:
type: string
description: Field name to filter on
example: "provider"
operator:
type: string
enum:
- eq
- ne
- gt
- gte
- lt
- lte
- in
- not_in
- contains
- not_contains
- starts_with
- ends_with
- regex
- search
description: Filter operator
value:
oneOf:
- type: string
- type: number
- type: integer
- type: boolean
- type: array
items:
oneOf:
- type: string
- type: number
- type: integer
description: Filter value (type depends on operator)
LogicalFilter:
type: object
required:
- operator
- filters
properties:
operator:
type: string
enum: [AND, OR, NOT]
description: Logical operator
filters:
type: array
items:
oneOf:
- $ref: '#/components/schemas/FieldFilter'
- $ref: '#/components/schemas/LogicalFilter'
description: Filters to combine (recursive)
ErrorResponse:
type: object
required:
- error
- meta
properties:
error:
type: object
required:
- code
- message
properties:
code:
type: string
description: Error code
message:
type: string
description: Human-readable error message
details:
type: string
nullable: true
description: Additional error details
meta:
type: object
required:
- timestamp
properties:
timestamp:
type: string
format: date-time
responses:
BadRequest:
description: Bad request - Invalid parameters or filter
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error:
code: "BAD_REQUEST"
message: "Invalid filter: field 'invalid_field' is not allowed"
meta:
timestamp: "2025-11-05T10:00:00Z"
Unauthorized:
description: Unauthorized - Missing or invalid JWT token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error:
code: "UNAUTHORIZED"
message: "Invalid or missing JWT token"
meta:
timestamp: "2025-11-05T10:00:00Z"
Forbidden:
description: Forbidden - Insufficient permissions
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error:
code: "FORBIDDEN"
message: "Insufficient permissions to read traces"
meta:
timestamp: "2025-11-05T10:00:00Z"
NotFound:
description: Not found - Resource does not exist
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error:
code: "NOT_FOUND"
message: "Trace with ID 'trace-123' not found"
meta:
timestamp: "2025-11-05T10:00:00Z"
RateLimitExceeded:
description: Rate limit exceeded
headers:
X-RateLimit-Limit:
schema:
type: integer
description: Total requests allowed
X-RateLimit-Remaining:
schema:
type: integer
description: Remaining requests (will be 0)
X-RateLimit-Reset:
schema:
type: integer
description: Unix timestamp when limit resets
Retry-After:
schema:
type: integer
description: Seconds until rate limit resets
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
error:
code: "RATE_LIMIT_EXCEEDED"
message: "Too many requests. Please slow down."
meta:
timestamp: "2025-11-05T10:00:00Z"