-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.rs
More file actions
1329 lines (1233 loc) · 54.7 KB
/
openapi.rs
File metadata and controls
1329 lines (1233 loc) · 54.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
use serde::{Deserialize, Serialize};
#[cfg(feature = "utoipa")]
use utoipa::OpenApi;
#[cfg(feature = "utoipa")]
use crate::{
api_types, models,
routes::{admin, api, health},
};
#[cfg(feature = "utoipa")]
/// OpenAPI documentation for Hadrian Gateway
#[derive(OpenApi)]
#[openapi(
info(
title = "Hadrian Gateway API",
version = "0.1.0",
description = r#"**Hadrian Gateway** is an AI Gateway providing a unified OpenAI-compatible API for routing requests to multiple LLM providers.
## Overview
The gateway provides two main API surfaces:
- **Public API** (`/api/v1/*`) - OpenAI-compatible endpoints for LLM inference. Use these endpoints to create chat completions, text completions, embeddings, and list available models. Authentication depends on the configured `auth.mode` (API key, IdP, IAP, or none).
- **Admin API** (`/admin/v1/*`) - RESTful management endpoints for multi-tenant configuration. Manage organizations, projects, users, API keys, dynamic providers, usage tracking, and model pricing.
## Authentication
The gateway supports multiple authentication methods for API access.
### API Key Authentication
API keys are the primary authentication method for programmatic access. Keys are created via the Admin API and scoped to organizations, projects, or users.
**Using the Authorization header (recommended):**
```
Authorization: Bearer gw_live_abc123def456...
```
**Using the X-API-Key header:**
```
X-API-Key: gw_live_abc123def456...
```
Both headers are supported. The `Authorization: Bearer` format is recommended for compatibility with OpenAI client libraries.
**Example request:**
```bash
curl https://gateway.example.com/api/v1/chat/completions \
-H \"Authorization: Bearer gw_live_abc123def456...\" \
-H \"Content-Type: application/json\" \
-d '{\"model\": \"openai/gpt-4\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}]}'
```
### JWT Authentication
When JWT authentication is enabled, requests can be authenticated using a JWT token from your identity provider.
```
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
```
The gateway validates the JWT against the configured JWKS endpoint and extracts the identity from the token claims.
**Example request:**
```bash
curl https://gateway.example.com/api/v1/chat/completions \
-H \"Authorization: Bearer eyJhbGciOiJSUzI1NiIs...\" \
-H \"Content-Type: application/json\" \
-d '{\"model\": \"openai/gpt-4\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}]}'
```
### Multi-Auth Mode
When configured for multi-auth, the gateway accepts both API keys and JWTs using **format-based detection**:
- **X-API-Key header**: Always validated as an API key
- **Authorization: Bearer header**: Uses format-based detection:
- Tokens starting with the configured API key prefix (default: `gw_`) are validated as API keys
- All other tokens are validated as JWTs
**Important:** Providing both `X-API-Key` and `Authorization` headers simultaneously results in a 400 error (ambiguous credentials). Choose one authentication method per request.
**Examples:**
```bash
# API key in X-API-Key header
curl -H \"X-API-Key: gw_live_abc123...\" https://gateway.example.com/v1/chat/completions
# API key in Authorization: Bearer header (format-based detection)
curl -H \"Authorization: Bearer gw_live_abc123...\" https://gateway.example.com/v1/chat/completions
# JWT in Authorization: Bearer header
curl -H \"Authorization: Bearer eyJhbGciOiJSUzI1NiIs...\" https://gateway.example.com/v1/chat/completions
```
### Authentication Errors
| Error Code | HTTP Status | Description | Example Response |
|------------|-------------|-------------|------------------|
| `unauthorized` | 401 | No authentication credentials provided | `{\"error\": {\"code\": \"unauthorized\", \"message\": \"Authentication required\"}}` |
| `ambiguous_credentials` | 400 | Both X-API-Key and Authorization headers provided | `{\"error\": {\"code\": \"ambiguous_credentials\", \"message\": \"Ambiguous credentials: provide either X-API-Key or Authorization header, not both\"}}` |
| `invalid_api_key` | 401 | API key is invalid, malformed, or revoked | `{\"error\": {\"code\": \"invalid_api_key\", \"message\": \"Invalid API key\"}}` |
| `not_authenticated` | 401 | JWT validation failed | `{\"error\": {\"code\": \"not_authenticated\", \"message\": \"Token validation failed\"}}` |
| `forbidden` | 403 | Valid credentials but insufficient permissions | `{\"error\": {\"code\": \"forbidden\", \"message\": \"Insufficient permissions\"}}` |
### Configuration Examples
**API Key Authentication:**
```toml
[auth.mode]
type = \"api_key\"
[auth.api_key]
header_name = \"X-API-Key\" # Header to read API key from
key_prefix = \"gw_\" # Valid key prefix
cache_ttl_secs = 60 # Cache key lookups for 60 seconds
```
**IdP Authentication (SSO + API keys + JWT):**
```toml
[auth.mode]
type = \"idp\"
[auth.api_key]
header_name = \"X-API-Key\"
key_prefix = \"gw_\"
[auth.session]
secure = true
```
**Identity-Aware Proxy (IAP):**
```toml
[auth.mode]
type = \"iap\"
identity_header = \"X-Forwarded-User\"
email_header = \"X-Forwarded-Email\"
```
## Pagination
All Admin API list endpoints use **cursor-based pagination** for stable, performant navigation.
**Query Parameters:**
- `limit` (optional): Maximum records per page (default: 100, max: 1000)
- `cursor` (optional): Opaque cursor from previous response's `next_cursor` or `prev_cursor`
- `direction` (optional): `forward` (default) or `backward`
**Response:**
```json
{
\"data\": [...],
\"pagination\": {
\"limit\": 100,
\"has_more\": true,
\"next_cursor\": \"MTczMzU4MDgwMDAwMDphYmMxMjM0...\",
\"prev_cursor\": null
}
}
```
## Model Routing
Models can be addressed in several ways:
- **Static routing**: `provider-name/model-name` routes to config-defined providers
- **Dynamic routing**: `:org/{ORG}/{PROVIDER}/{MODEL}` routes to database-backed providers
- **Default**: When no prefix is specified, routes to the default provider
## Error Codes
All errors follow a consistent JSON format:
```json
{
\"error\": {
\"code\": \"error_code\",
\"message\": \"Human-readable error message\",
\"details\": { ... } // Optional additional context
}
}
```
### Authentication & Authorization Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `unauthorized` | 401 | Missing or invalid API key/token |
| `invalid_api_key` | 401 | API key is invalid, expired, or revoked |
| `forbidden` | 403 | Valid credentials but insufficient permissions |
| `not_authenticated` | 401 | Authentication required for this operation |
### Rate Limiting & Budget Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `rate_limit_exceeded` | 429 | Request rate limit exceeded. Check `Retry-After` header. |
| `budget_exceeded` | 402 | Budget limit exceeded for the configured period. Details include `limit_cents`, `current_spend_cents`, and `period`. |
| `cache_required` | 503 | Budget enforcement requires cache to be configured |
### Request Validation Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `validation_error` | 400 | Request body validation failed |
| `bad_request` | 400 | Malformed request |
| `routing_error` | 400 | Model routing failed (invalid model string or provider not found) |
| `not_found` | 404 | Requested resource not found |
| `conflict` | 409 | Resource already exists or conflicts with existing state |
### Provider & Gateway Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `provider_error` | 502 | Upstream LLM provider returned an error |
| `request_failed` | 502 | Failed to communicate with upstream provider |
| `circuit_breaker_open` | 503 | Provider circuit breaker is open due to repeated failures |
| `response_read_error` | 500 | Failed to read provider response |
| `response_builder` | 500 | Failed to build response from provider data |
| `internal_error` | 500 | Internal server error |
### Guardrails Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `guardrails_blocked` | 400 | Content blocked by guardrails policy. Response includes `violations` array. |
| `guardrails_timeout` | 504 | Guardrails evaluation timed out |
| `guardrails_provider_error` | 502 | Error communicating with guardrails provider |
| `guardrails_auth_error` | 502 | Authentication failed with guardrails provider |
| `guardrails_rate_limited` | 429 | Guardrails provider rate limit exceeded |
| `guardrails_config_error` | 500 | Invalid guardrails configuration |
| `guardrails_parse_error` | 400 | Failed to parse content for guardrails evaluation |
### Admin API Errors
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `database_required` | 503 | Database not configured (required for admin operations) |
| `services_required` | 503 | Required services not initialized |
| `not_configured` | 503 | Required feature or service not configured |
| `database_error` | 500 | Database operation failed |
## Rate Limiting
The gateway implements multiple layers of rate limiting to protect against abuse and ensure fair usage.
### Rate Limit Types
| Type | Scope | Default | Description |
|------|-------|---------|-------------|
| **Requests per minute** | API Key | 60 | Maximum requests per minute per API key |
| **Requests per day** | API Key | Unlimited | Optional daily request limit per API key |
| **Tokens per minute** | API Key | 100,000 | Maximum tokens processed per minute |
| **Tokens per day** | API Key | Unlimited | Optional daily token limit |
| **Concurrent requests** | API Key | 10 | Maximum simultaneous in-flight requests |
| **IP requests per minute** | IP Address | 120 | Rate limit for unauthenticated requests |
### Rate Limit Headers
All API responses include rate limit information in HTTP headers.
#### Request Rate Limit Headers
| Header | Description | Example |
|--------|-------------|---------|
| `X-RateLimit-Limit` | Maximum requests allowed in the current window | `60` |
| `X-RateLimit-Remaining` | Requests remaining in the current window | `45` |
| `X-RateLimit-Reset` | Seconds until the rate limit window resets | `42` |
#### Token Rate Limit Headers
| Header | Description | Example |
|--------|-------------|---------|
| `X-TokenRateLimit-Limit` | Maximum tokens allowed per minute | `100000` |
| `X-TokenRateLimit-Remaining` | Tokens remaining in the current minute | `85000` |
| `X-TokenRateLimit-Used` | Tokens used in the current minute | `15000` |
| `X-TokenRateLimit-Day-Limit` | Maximum tokens allowed per day (if configured) | `1000000` |
| `X-TokenRateLimit-Day-Remaining` | Tokens remaining today (if configured) | `950000` |
#### Rate Limit Exceeded Response
When a rate limit is exceeded, the API returns HTTP 429 with:
```json
{
\"error\": {
\"code\": \"rate_limit_exceeded\",
\"message\": \"Rate limit exceeded: 60 requests per minute\",
\"details\": {
\"limit\": 60,
\"window\": \"minute\",
\"retry_after_secs\": 42
}
}
}
```
The `Retry-After` header indicates seconds to wait before retrying:
```
HTTP/1.1 429 Too Many Requests
Retry-After: 42
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 42
```
### IP-Based Rate Limiting
Unauthenticated requests (requests without a valid API key) are rate limited by IP address. This protects public endpoints like `/health` from abuse.
- **Default:** 120 requests per minute per IP
- **Client IP Detection:** Respects `X-Forwarded-For` and `X-Real-IP` headers when trusted proxies are configured
- **Configuration:** Can be disabled or adjusted via `limits.rate_limits.ip_rate_limits` in config
### Rate Limit Configuration
Rate limits are configured hierarchically:
1. **Global defaults** (in `hadrian.toml`):
```toml
[limits.rate_limits]
requests_per_minute = 60
tokens_per_minute = 100000
concurrent_requests = 10
[limits.rate_limits.ip_rate_limits]
enabled = true
requests_per_minute = 120
```
2. **Per-API key** limits can override global defaults (when creating API keys via Admin API)
### Best Practices
- **Implement exponential backoff**: When receiving 429 responses, wait the `Retry-After` duration before retrying
- **Monitor rate limit headers**: Track `X-RateLimit-Remaining` to proactively throttle requests
- **Use streaming for long responses**: Streaming responses don't hold connections during generation
- **Batch requests when possible**: Combine multiple small requests into larger batches
"#,
license(name = "Apache-2.0 OR MIT", url = "https://github.com/ScriptSmith/hadrian/blob/main/LICENSE-APACHE"),
),
servers(
(url = "/", description = "Default server")
),
tags(
// Public API tags
(name = "chat", description = "Create chat completions using conversational message format. Supports streaming, tool use, vision, and reasoning models. OpenAI-compatible."),
(name = "completions", description = "Create text completions from a prompt. Legacy API for non-chat models. OpenAI-compatible."),
(name = "embeddings", description = "Generate vector embeddings for text input. Use for semantic search, clustering, and similarity comparisons. OpenAI-compatible."),
(name = "models", description = "List all available models from configured providers. Model IDs are prefixed with provider name."),
(name = "me", description = "Self-service endpoints for authenticated users. Export personal data for GDPR compliance."),
(name = "Images", description = "Generate, edit, and create variations of images using DALL-E models. OpenAI-compatible."),
(name = "Audio", description = "Text-to-speech, speech-to-text transcription, and audio translation using TTS and Whisper models. OpenAI-compatible."),
// Admin API tags
(name = "organizations", description = "Organizations are the top-level entity for multi-tenancy. Each organization can have multiple projects, users, API keys, and provider configurations."),
(name = "projects", description = "Projects belong to organizations and provide a way to separate workloads, budgets, and API keys within an organization."),
(name = "users", description = "Users can be members of organizations and projects. Users can have their own API keys and provider configurations."),
(name = "api-keys", description = "API keys authenticate requests to the Public API. Keys can be scoped to organizations, projects, or users with optional budget limits and expiration."),
(name = "dynamic-providers", description = "Dynamic providers allow runtime configuration of LLM backends without restarting the gateway. Useful for BYOK (bring-your-own-key) scenarios."),
(name = "usage", description = "Query usage statistics for API keys including token counts, costs, and breakdowns by date, model, or referer."),
(name = "model-pricing", description = "Configure per-model pricing for cost tracking. Pricing can be set globally, per-provider, per-organization, per-project, or per-user."),
(name = "conversations", description = "Store and manage chat conversation history. Conversations can be owned by users or projects and support multiple models."),
(name = "templates", description = "Manage reusable prompt templates. Templates can be owned by organizations, teams, projects, or users and include metadata for configuration."),
(name = "audit-logs", description = "Query audit logs for admin operations. All sensitive operations like API key creation, user permission changes, and resource modifications are logged."),
(name = "teams", description = "Teams group users within an organization for easier permission management. Users can belong to multiple teams, and projects can be assigned to a team."),
(name = "service_accounts", description = "Service accounts are machine identities that can own API keys and carry roles for RBAC evaluation. They enable unified authorization across human users and automated systems."),
(name = "access-reviews", description = "Access review reports for compliance requirements (SOC 2, ISO 27001). View user access across organizations, projects, and API keys."),
(name = "sso", description = "SSO connection configuration (read-only from config). View OIDC and proxy auth settings for JIT user provisioning."),
(name = "files", description = "Upload and manage files for use with vector stores. Files are uploaded via multipart form data and can be added to vector stores for RAG."),
(name = "vector-stores", description = "Create and manage vector stores for RAG (Retrieval Augmented Generation). Vector stores contain files that are chunked and embedded for semantic search.\n\n## Hadrian Extensions\n\nThe Vector Stores API is based on OpenAI's Vector Stores API with the following extensions:\n\n### Multi-Tenancy\n- `owner_type`, `owner_id` fields for organization/project/user ownership\n- Required in create requests and included in responses\n\n### Additional Fields\n- `description`: Human-readable description for vector stores\n- `embedding_model`: Configurable embedding model (default: text-embedding-3-small)\n- `embedding_dimensions`: Configurable vector dimensions (default: 1536)\n- `updated_at`: Modification timestamp\n- `file_id`: Reference to Files API in vector store files\n\n### Extension Endpoints\n- `GET /v1/vector_stores/{id}/files/{file_id}/chunks`: List chunks for debugging\n\n### Search Extensions\n- Request: `threshold` (similarity threshold), `file_ids` (file filter)\n- Response: `chunk_id`, `vector_store_id`, `chunk_index` for debugging\n\n### Schema Differences\n- Timestamps use ISO 8601 format (OpenAI uses Unix timestamps)\n- List responses use `pagination` object (OpenAI uses root-level `first_id`, `last_id`, `has_more`)\n- Search `content` is a string (OpenAI uses `[{type, text}]` array)"),
// Health & Infrastructure
(name = "health", description = "Health check endpoints for monitoring and Kubernetes probes. Use `/health` for detailed status, `/health/live` for liveness probes, and `/health/ready` for readiness probes.")
),
paths(
// Health check routes
health::health_check,
health::liveness,
health::readiness,
// Public API routes
api::api_v1_chat_completions,
api::api_v1_responses,
api::api_v1_completions,
api::api_v1_embeddings,
api::api_v1_models,
// Self-service endpoints (current user)
admin::me::export,
admin::me::delete,
admin::me_providers::list,
admin::me_providers::create,
admin::me_providers::get,
admin::me_providers::update,
admin::me_providers::delete,
admin::me_providers::test_connectivity,
admin::me_providers::test_credentials,
admin::me_providers::built_in_providers,
// Self-service endpoints - API Keys
admin::me_api_keys::get,
admin::me_api_keys::list,
admin::me_api_keys::create,
admin::me_api_keys::revoke,
admin::me_api_keys::rotate,
// Self-service endpoints - Sessions
admin::me_sessions::list,
admin::me_sessions::delete_one,
// Admin routes - Organizations
admin::organizations::create,
admin::organizations::get,
admin::organizations::list,
admin::organizations::update,
admin::organizations::delete,
// Admin routes - Projects
admin::projects::create,
admin::projects::get,
admin::projects::list,
admin::projects::update,
admin::projects::delete,
// Admin routes - Users
admin::users::create,
admin::users::get,
admin::users::list,
admin::users::update,
admin::users::delete,
admin::users::export,
// Admin routes - User Sessions
admin::sessions::list,
admin::sessions::delete_all,
admin::sessions::delete_one,
admin::users::list_org_members,
admin::users::add_org_member,
admin::users::remove_org_member,
admin::users::list_project_members,
admin::users::add_project_member,
admin::users::remove_project_member,
// Admin routes - API Keys
admin::api_keys::create,
admin::api_keys::list_by_org,
admin::api_keys::list_by_project,
admin::api_keys::list_by_user,
admin::api_keys::list_by_service_account,
admin::api_keys::revoke,
admin::api_keys::rotate,
// Admin routes - Dynamic Providers
admin::dynamic_providers::create,
admin::dynamic_providers::get,
admin::dynamic_providers::update,
admin::dynamic_providers::delete,
admin::dynamic_providers::list_by_org,
admin::dynamic_providers::list_by_project,
admin::dynamic_providers::list_by_user,
admin::dynamic_providers::test_connectivity,
admin::dynamic_providers::test_credentials,
// Admin routes - Usage (API Key level)
admin::usage::get_summary,
admin::usage::get_by_date,
admin::usage::get_by_model,
admin::usage::get_by_referer,
admin::usage::get_forecast,
// Admin routes - Usage (Organization level)
admin::usage::get_org_summary,
admin::usage::get_org_by_date,
admin::usage::get_org_by_model,
admin::usage::get_org_by_provider,
admin::usage::get_org_forecast,
// Admin routes - Usage (API Key by-provider and time series)
admin::usage::get_by_provider,
admin::usage::get_by_date_model,
admin::usage::get_by_date_provider,
admin::usage::get_by_pricing_source,
admin::usage::get_by_date_pricing_source,
// Admin routes - Usage (Project level)
admin::usage::get_project_summary,
admin::usage::get_project_by_date,
admin::usage::get_project_by_model,
admin::usage::get_project_by_provider,
admin::usage::get_project_by_date_model,
admin::usage::get_project_by_date_provider,
admin::usage::get_project_by_pricing_source,
admin::usage::get_project_by_date_pricing_source,
admin::usage::get_project_forecast,
// Admin routes - Usage (User level)
admin::usage::get_user_summary,
admin::usage::get_user_by_date,
admin::usage::get_user_by_model,
admin::usage::get_user_by_provider,
admin::usage::get_user_by_date_model,
admin::usage::get_user_by_date_provider,
admin::usage::get_user_by_pricing_source,
admin::usage::get_user_by_date_pricing_source,
admin::usage::get_user_forecast,
// Admin routes - Usage (Team level)
admin::usage::get_team_summary,
admin::usage::get_team_by_date,
admin::usage::get_team_by_model,
admin::usage::get_team_by_provider,
admin::usage::get_team_by_date_model,
admin::usage::get_team_by_date_provider,
admin::usage::get_team_by_pricing_source,
admin::usage::get_team_by_date_pricing_source,
admin::usage::get_team_forecast,
// Admin routes - Usage (Provider level)
admin::usage::get_provider_summary,
admin::usage::get_provider_by_date,
admin::usage::get_provider_by_model,
admin::usage::get_provider_forecast,
// Admin routes - Usage (Org time series)
admin::usage::get_org_by_date_model,
admin::usage::get_org_by_date_provider,
admin::usage::get_org_by_pricing_source,
admin::usage::get_org_by_date_pricing_source,
// Admin routes - Usage (Org entity breakdowns)
admin::usage::get_org_by_user,
admin::usage::get_org_by_date_user,
admin::usage::get_org_by_project,
admin::usage::get_org_by_date_project,
admin::usage::get_org_by_team,
admin::usage::get_org_by_date_team,
// Admin routes - Usage (Project entity breakdowns)
admin::usage::get_project_by_user,
admin::usage::get_project_by_date_user,
// Admin routes - Usage (Team entity breakdowns)
admin::usage::get_team_by_user,
admin::usage::get_team_by_date_user,
admin::usage::get_team_by_project,
admin::usage::get_team_by_date_project,
// Admin routes - Usage (Global)
admin::usage::get_global_summary,
admin::usage::get_global_by_date,
admin::usage::get_global_by_model,
admin::usage::get_global_by_provider,
admin::usage::get_global_by_pricing_source,
admin::usage::get_global_by_date_model,
admin::usage::get_global_by_date_provider,
admin::usage::get_global_by_date_pricing_source,
admin::usage::get_global_by_user,
admin::usage::get_global_by_date_user,
admin::usage::get_global_by_project,
admin::usage::get_global_by_date_project,
admin::usage::get_global_by_team,
admin::usage::get_global_by_date_team,
admin::usage::get_global_by_org,
admin::usage::get_global_by_date_org,
// Admin routes - Usage (Self-service)
admin::usage::get_me_summary,
admin::usage::get_me_by_date,
admin::usage::get_me_by_model,
admin::usage::get_me_by_provider,
admin::usage::get_me_by_date_model,
admin::usage::get_me_by_date_provider,
admin::usage::get_me_by_pricing_source,
admin::usage::get_me_by_date_pricing_source,
// Admin routes - Usage Logs
admin::usage::list_logs,
admin::usage::list_me_logs,
admin::usage::export_logs,
admin::usage::export_me_logs,
// Admin routes - Model Pricing
admin::model_pricing::create,
admin::model_pricing::get,
admin::model_pricing::update,
admin::model_pricing::delete,
admin::model_pricing::list_global,
admin::model_pricing::list_by_provider,
admin::model_pricing::list_by_org,
admin::model_pricing::list_by_project,
admin::model_pricing::list_by_user,
admin::model_pricing::upsert,
admin::model_pricing::bulk_upsert,
// Admin routes - Conversations
admin::conversations::create,
admin::conversations::get,
admin::conversations::update,
admin::conversations::delete,
admin::conversations::append_messages,
admin::conversations::set_pin,
admin::conversations::list_by_project,
admin::conversations::list_by_user,
admin::conversations::list_accessible_for_user,
// Admin routes - Templates
admin::templates::create,
admin::templates::get,
admin::templates::update,
admin::templates::delete,
admin::templates::list_by_org,
admin::templates::list_by_team,
admin::templates::list_by_project,
admin::templates::list_by_user,
// Admin routes - Provider Management
admin::providers::list_circuit_breakers,
admin::providers::get_circuit_breaker,
admin::providers::list_provider_health,
admin::providers::get_provider_health,
admin::providers::list_provider_stats,
admin::providers::get_provider_stats,
admin::providers::get_provider_stats_history,
// Admin routes - Dead Letter Queue
admin::dlq::list,
admin::dlq::get,
admin::dlq::delete,
admin::dlq::retry,
admin::dlq::stats,
admin::dlq::purge,
admin::dlq::prune,
// Admin routes - Audit Logs
admin::audit_logs::list,
admin::audit_logs::get,
// Admin routes - Access Reviews
admin::access_reviews::get_inventory,
admin::access_reviews::get_stale_access,
admin::access_reviews::get_org_access_report,
admin::access_reviews::get_user_access_summary,
// Admin routes - Teams
admin::teams::create,
admin::teams::get,
admin::teams::list,
admin::teams::update,
admin::teams::delete,
admin::teams::list_members,
admin::teams::add_member,
admin::teams::update_member,
admin::teams::remove_member,
// Admin routes - Service Accounts
admin::service_accounts::create,
admin::service_accounts::get,
admin::service_accounts::list,
admin::service_accounts::update,
admin::service_accounts::delete,
// Admin routes - SSO Connections (read-only, from config)
admin::sso_connections::list,
admin::sso_connections::get,
// Admin routes - Session Info (debugging)
admin::session_info::get,
// Admin routes - SSO Group Mappings
admin::sso_group_mappings::list,
admin::sso_group_mappings::create,
admin::sso_group_mappings::get,
admin::sso_group_mappings::update,
admin::sso_group_mappings::delete,
admin::sso_group_mappings::test,
admin::sso_group_mappings::export,
admin::sso_group_mappings::import,
// Admin routes - Organization SSO Config
admin::org_sso_configs::get,
admin::org_sso_configs::create,
admin::org_sso_configs::update,
admin::org_sso_configs::delete,
// SAML metadata endpoints are conditionally added at runtime via merge_saml_openapi()
// when the saml feature is enabled (parse_saml_metadata, get_sp_metadata)
// Admin routes - Organization RBAC Policies
admin::org_rbac_policies::list,
admin::org_rbac_policies::create,
admin::org_rbac_policies::get,
admin::org_rbac_policies::update,
admin::org_rbac_policies::delete,
admin::org_rbac_policies::list_versions,
admin::org_rbac_policies::rollback,
admin::org_rbac_policies::simulate,
admin::org_rbac_policies::validate,
// Admin routes - Domain Verifications
admin::domain_verifications::list,
admin::domain_verifications::create,
admin::domain_verifications::get,
admin::domain_verifications::get_instructions,
admin::domain_verifications::delete,
admin::domain_verifications::verify,
// Admin routes - Organization SCIM Config
admin::scim_configs::get,
admin::scim_configs::create,
admin::scim_configs::update,
admin::scim_configs::delete,
admin::scim_configs::rotate_token,
// Images API (OpenAI-compatible)
api::api_v1_images_generations,
api::api_v1_images_edits,
api::api_v1_images_variations,
// Audio API (OpenAI-compatible)
api::api_v1_audio_speech,
api::api_v1_audio_transcriptions,
api::api_v1_audio_translations,
// Files API (OpenAI-compatible, under /api/v1)
api::api_v1_files_upload,
api::api_v1_files_list,
api::api_v1_files_get,
api::api_v1_files_get_content,
api::api_v1_files_delete,
// API routes - Vector Stores
api::api_v1_vector_stores_create,
api::api_v1_vector_stores_list,
api::api_v1_vector_stores_get,
api::api_v1_vector_stores_modify,
api::api_v1_vector_stores_delete,
// API routes - Vector Store Files
api::api_v1_vector_stores_create_file,
api::api_v1_vector_stores_list_files,
api::api_v1_vector_stores_get_file,
api::api_v1_vector_stores_delete_file,
// API routes - Vector Store File Batches
api::api_v1_vector_stores_create_file_batch,
api::api_v1_vector_stores_get_file_batch,
api::api_v1_vector_stores_cancel_file_batch,
api::api_v1_vector_stores_list_batch_files,
// API routes - Vector Store Chunks & Search (Hadrian extensions)
api::api_v1_vector_stores_list_file_chunks,
api::api_v1_vector_stores_search,
// API routes - Tools (Hadrian extensions)
api::web_search,
api::web_fetch,
),
components(schemas(
// API types - Chat Completion
api_types::CreateChatCompletionPayload,
api_types::Message,
api_types::MessageContent,
api_types::chat_completion::ContentPart,
api_types::chat_completion::ImageUrl,
api_types::chat_completion::ImageUrlDetail,
api_types::chat_completion::VideoUrl,
api_types::chat_completion::InputAudio,
api_types::chat_completion::InputAudioFormat,
api_types::chat_completion::ReasoningEffort,
api_types::chat_completion::ReasoningSummary,
api_types::chat_completion::CreateChatCompletionReasoning,
api_types::chat_completion::ResponseFormat,
api_types::chat_completion::JsonSchemaConfig,
api_types::chat_completion::Stop,
api_types::chat_completion::StreamOptions,
api_types::chat_completion::ToolChoice,
api_types::chat_completion::ToolChoiceDefaults,
api_types::chat_completion::NamedToolChoice,
api_types::chat_completion::NamedToolChoiceFunction,
api_types::chat_completion::ToolType,
api_types::chat_completion::ToolDefinition,
api_types::chat_completion::ToolDefinitionFunction,
api_types::chat_completion::ToolCall,
api_types::chat_completion::ToolCallFunction,
// API types - Completions
api_types::CreateCompletionPayload,
// API types - Embeddings
api_types::CreateEmbeddingPayload,
api_types::embeddings::EmbeddingInput,
api_types::embeddings::EncodingFormat,
// API types - Images
api_types::CreateImageRequest,
api_types::CreateImageEditRequest,
api_types::CreateImageVariationRequest,
api_types::ImagesResponse,
api_types::images::Image,
api_types::images::ImageUsage,
api_types::images::ImageModel,
api_types::images::ImageQuality,
api_types::images::ImageResponseFormat,
api_types::images::ImageOutputFormat,
api_types::images::ImageSize,
api_types::images::ImageStyle,
api_types::images::ImageBackground,
api_types::images::ImageModeration,
// API types - Audio
api_types::CreateSpeechRequest,
api_types::CreateTranscriptionRequest,
api_types::CreateTranslationRequest,
api_types::audio::Voice,
api_types::audio::SpeechResponseFormat,
api_types::audio::SpeechStreamFormat,
api_types::audio::AudioResponseFormat,
api_types::audio::TimestampGranularity,
api_types::audio::TranscriptionInclude,
api_types::audio::TranscriptionChunkingStrategy,
api_types::audio::TranscriptionResponse,
api_types::audio::TranscriptionVerboseResponse,
api_types::audio::TranscriptionDiarizedResponse,
api_types::audio::TranscriptionWord,
api_types::audio::TranscriptionSegment,
api_types::audio::TranscriptionDiarizedSegment,
api_types::audio::TranscriptionLogprob,
api_types::audio::TranscriptionInputTokenDetails,
api_types::audio::TranscriptionUsageTokens,
api_types::audio::TranscriptionUsageDuration,
api_types::audio::TranscriptionUsage,
api_types::audio::TranslationResponse,
api_types::audio::TranslationVerboseResponse,
// API types - Responses
api_types::CreateResponsesPayload,
// Models response
api::CombinedModelsResponse,
// Admin models - Organization
models::Organization,
models::CreateOrganization,
models::UpdateOrganization,
// Admin models - Project
models::Project,
models::CreateProject,
models::UpdateProject,
// Admin models - User
models::User,
models::CreateUser,
models::UpdateUser,
models::UserDeletionResponse,
// GDPR Export types
models::UserDataExport,
models::UserMemberships,
models::UserOrgMembership,
models::UserProjectMembership,
models::ExportedApiKey,
models::ExportedUsageSummary,
// Admin models - API Key
models::ApiKey,
models::ApiKeyScope,
models::CreateApiKey,
models::CreatedApiKey,
models::ApiKeyOwner,
models::BudgetPeriod,
admin::api_keys::RotateApiKeyRequest,
// Admin models - Dynamic Provider
models::DynamicProvider,
models::DynamicProviderResponse,
models::CreateDynamicProvider,
models::CreateSelfServiceProvider,
models::CreateSelfServiceApiKey,
models::UpdateDynamicProvider,
models::ConnectivityTestResponse,
models::ProviderOwner,
admin::me_providers::SelfServiceProviderListResponse,
admin::me_providers::BuiltInProvider,
admin::me_providers::BuiltInProvidersResponse,
// Admin models - Model Pricing
models::DbModelPricing,
models::CreateModelPricing,
models::UpdateModelPricing,
models::PricingOwner,
models::PricingSource,
// Admin routes - Usage response types
admin::usage::UsageQuery,
admin::usage::UsageSummaryResponse,
admin::usage::DailySpendResponse,
admin::usage::ModelSpendResponse,
admin::usage::RefererSpendResponse,
admin::usage::ProviderSpendResponse,
admin::usage::ForecastQuery,
admin::usage::CostForecastResponse,
admin::usage::TimeSeriesForecastResponse,
admin::usage::DailyModelSpendResponse,
admin::usage::DailyProviderSpendResponse,
admin::usage::PricingSourceSpendResponse,
admin::usage::DailyPricingSourceSpendResponse,
admin::usage::UserSpendResponse,
admin::usage::DailyUserSpendResponse,
admin::usage::ProjectSpendResponse,
admin::usage::DailyProjectSpendResponse,
admin::usage::TeamSpendResponse,
admin::usage::DailyTeamSpendResponse,
admin::usage::OrgSpendResponse,
admin::usage::DailyOrgSpendResponse,
admin::usage::UsageLogResponse,
admin::usage::UsageLogListResponse,
admin::usage::UsageLogExportFormat,
// Admin routes - Users
admin::users::AddMemberRequest,
admin::users::UserListResponse,
// Admin routes - User Sessions
admin::sessions::SessionInfo,
admin::sessions::SessionListResponse,
admin::sessions::SessionsRevokedResponse,
crate::auth::session_store::DeviceInfo,
// Admin routes - Organizations
admin::organizations::ListQuery,
admin::organizations::OrganizationListResponse,
// Admin routes - Projects
admin::projects::ProjectListResponse,
// Admin routes - Model Pricing
admin::model_pricing::BulkUpsertResponse,
// Admin models - Conversation
models::Conversation,
models::ConversationWithProject,
models::CreateConversation,
models::UpdateConversation,
models::SetPinOrder,
models::AppendMessages,
models::ConversationOwner,
models::ConversationOwnerType,
models::Message,
admin::conversations::ConversationListResponse,
admin::conversations::ConversationWithProjectListResponse,
admin::conversations::ListAccessibleQuery,
// Admin models - Template
models::Template,
models::CreateTemplate,
models::UpdateTemplate,
models::TemplateOwner,
models::TemplateOwnerType,
admin::templates::TemplateListResponse,
// Admin routes - DLQ
admin::dlq::DlqListQuery,
admin::dlq::DlqEntryResponse,
admin::dlq::DlqStatsResponse,
admin::dlq::DlqRetryResponse,
admin::dlq::PruneQuery,
// Admin routes - Providers
admin::providers::CircuitBreakersResponse,
admin::providers::ProviderCircuitBreakerResponse,
admin::providers::ProviderHealthResponse,
admin::providers::ProviderStatsResponse,
admin::providers::ProviderStatsHistoryQuery,
crate::providers::CircuitBreakerStatus,
crate::jobs::ProviderHealthState,
crate::providers::health_check::HealthStatus,
crate::services::ProviderStats,
crate::services::ProviderStatsHistorical,
crate::services::TimeBucketStats,
crate::services::StatsGranularity,
// Admin routes - Audit Logs
admin::audit_logs::AuditLogListResponse,
models::AuditLog,
models::AuditLogQuery,
models::AuditActorType,
// Access Review types
models::ExportFormat,
models::AccessInventoryResponse,
models::AccessInventorySummary,
models::AccessInventoryQuery,
models::UserAccessInventoryEntry,
models::OrgAccessEntry,
models::ProjectAccessEntry,
models::ApiKeySummary,
// Organization Access Report types
models::OrgAccessReportResponse,
models::OrgAccessReportSummary,
models::OrgAccessReportQuery,
models::OrgMemberAccessEntry,
models::OrgMemberProjectAccess,
models::OrgApiKeyEntry,
models::AccessGrantHistoryEntry,
// User Access Summary types
models::UserAccessSummaryResponse,
models::UserAccessSummaryQuery,
models::UserAccessOrgEntry,
models::UserAccessProjectEntry,
models::UserAccessApiKeyEntry,
models::UserAccessSummary,
// Team types
models::Team,
models::CreateTeam,
models::UpdateTeam,
models::TeamMembership,
models::TeamMember,
models::AddTeamMember,
models::UpdateTeamMember,
admin::teams::TeamListResponse,
admin::teams::TeamMemberListResponse,
// Service Account types
models::ServiceAccount,
models::CreateServiceAccount,
models::UpdateServiceAccount,
admin::service_accounts::ServiceAccountListResponse,
// SSO Connection types
admin::sso_connections::SsoConnection,
admin::sso_connections::SsoConnectionsResponse,
// Session Info types
admin::session_info::SessionInfoResponse,
admin::session_info::IdentityInfo,
admin::session_info::UserInfo,
admin::session_info::OrgMembershipInfo,
admin::session_info::TeamMembershipInfo,
admin::session_info::ProjectMembershipInfo,
admin::session_info::SsoConnectionInfo,
// SSO Group Mapping types
models::SsoGroupMapping,
models::CreateSsoGroupMapping,
models::UpdateSsoGroupMapping,
admin::sso_group_mappings::SsoGroupMappingListResponse,
admin::sso_group_mappings::TestMappingRequest,
admin::sso_group_mappings::TestMappingResult,
admin::sso_group_mappings::TestMappingResponse,
admin::sso_group_mappings::ExportFormat,
admin::sso_group_mappings::ExportMappingEntry,
admin::sso_group_mappings::ExportResponse,
admin::sso_group_mappings::ImportConflictStrategy,
admin::sso_group_mappings::ImportMappingEntry,
admin::sso_group_mappings::ImportRequest,
admin::sso_group_mappings::ImportError,
admin::sso_group_mappings::ImportResponse,
// Organization SSO Config types
models::OrgSsoConfig,
models::CreateOrgSsoConfig,
models::UpdateOrgSsoConfig,
models::SsoProviderType,
models::SsoEnforcementMode,
// Organization RBAC Policy types
models::OrgRbacPolicy,
models::OrgRbacPolicyVersion,
models::CreateOrgRbacPolicy,
models::UpdateOrgRbacPolicy,
models::RollbackOrgRbacPolicy,
models::RbacPolicyEffect,
admin::org_rbac_policies::OrgRbacPolicyListResponse,
admin::org_rbac_policies::OrgRbacPolicyVersionListResponse,
admin::org_rbac_policies::SimulatePolicyRequest,
admin::org_rbac_policies::SimulatePolicyResponse,
admin::org_rbac_policies::SimulateSubject,
admin::org_rbac_policies::SimulateContext,