Open History to see the last commit
1/**
2 * The service's own OpenAPI 3.1 document (PLAN.md task 4.1), hand-maintained.
3 * Single source of truth for three consumer surfaces: the generated TS client
4 * (task 7.4), the CLI (7.5), and the agent-auth capability list (5.1) — every
5 * operation MUST carry a unique operationId.
6 */
7
8const activityEnum = [
9 'chat',
10 'image',
11 'video',
12 'audio',
13 'embeddings',
14 'moderation',
15]
16
17const changeTypeEnum = [
18 'model.added',
19 'model.removed',
20 'model.updated',
21 'schema.added',
22 'schema.updated',
23 'endpoint.added',
24 'endpoint.removed',
25]
26
27const errorResponse = {
28 description: 'Error',
29 content: {
30 'application/json': {
31 schema: { $ref: '#/components/schemas/Error' },
32 },
33 },
34}
35
36const providerParam = {
37 name: 'provider',
38 in: 'path',
39 required: true,
40 description: 'Provider slug (see GET /v1/providers).',
41 schema: { type: 'string' },
42}
43
44const activityParam = {
45 name: 'activity',
46 in: 'path',
47 required: true,
48 description: 'Activity group.',
49 schema: { type: 'string', enum: activityEnum },
50}
51
52export const openApiDocument = {
53 openapi: '3.1.0',
54 info: {
55 title: 'modelschemas',
56 version: '0.1.0',
57 description:
58 'Live AI model schema service: per-endpoint request/response JSON ' +
59 'Schemas and model metadata for monitored providers, with ' +
60 'stale-while-revalidate caching and a change feed. Anonymous reads ' +
61 'are allowed at a low rate limit; register (agent-auth or API key) ' +
62 'for higher limits and webhook subscriptions.',
63 },
64 servers: [{ url: '/' }],
65 paths: {
66 '/v1': {
67 get: {
68 operationId: 'getServiceIndex',
69 summary: 'Service description and endpoint index',
70 responses: {
71 '200': {
72 description: 'Service index with _links to every surface.',
73 content: { 'application/json': { schema: { type: 'object' } } },
74 },
75 },
76 },
77 },
78 '/v1/status': {
79 get: {
80 operationId: 'getStatus',
81 summary: 'Per-provider sync status and row counts',
82 parameters: [
83 {
84 name: 'wait',
85 in: 'query',
86 description:
87 'Long-poll: hold up to N seconds (cap 60; "30s" form accepted) until new data exists, then return current data.',
88 schema: { type: 'string' },
89 },
90 ],
91 responses: {
92 '200': {
93 description: 'Service status.',
94 content: {
95 'application/json': {
96 schema: { $ref: '#/components/schemas/ServiceStatus' },
97 },
98 },
99 },
100 },
101 },
102 },
103 '/v1/providers': {
104 get: {
105 operationId: 'listProviders',
106 summary: 'List monitored providers with sync status',
107 responses: {
108 '200': {
109 description: 'Providers.',
110 content: { 'application/json': { schema: { type: 'object' } } },
111 },
112 },
113 },
114 },
115 '/v1/providers/{provider}/models': {
116 get: {
117 operationId: 'listProviderModels',
118 summary: 'List models for one provider',
119 parameters: [providerParam],
120 responses: {
121 '200': {
122 description: 'Models for the provider.',
123 content: { 'application/json': { schema: { type: 'object' } } },
124 },
125 '404': errorResponse,
126 },
127 },
128 },
129 '/v1/models': {
130 get: {
131 operationId: 'listModels',
132 summary: 'Cross-provider model catalog',
133 description:
134 'The headline "what can I use right now" endpoint. Filterable.',
135 parameters: [
136 {
137 name: 'activity',
138 in: 'query',
139 schema: { type: 'string', enum: activityEnum },
140 },
141 { name: 'provider', in: 'query', schema: { type: 'string' } },
142 {
143 name: 'capability',
144 in: 'query',
145 description: 'Substring match against model capabilities.',
146 schema: { type: 'string' },
147 },
148 {
149 name: 'q',
150 in: 'query',
151 description: 'Free-text match against id and display name.',
152 schema: { type: 'string' },
153 },
154 ],
155 responses: {
156 '200': {
157 description: 'Matching models.',
158 content: { 'application/json': { schema: { type: 'object' } } },
159 },
160 },
161 },
162 },
163 '/v1/models/{provider}/{modelId}': {
164 get: {
165 operationId: 'getModel',
166 summary: 'Full metadata for one model',
167 parameters: [
168 providerParam,
169 {
170 name: 'modelId',
171 in: 'path',
172 required: true,
173 description: 'Model slug or raw provider id.',
174 schema: { type: 'string' },
175 },
176 ],
177 responses: {
178 '200': {
179 description:
180 'Model metadata with activity, schemaEndpointId (canonical generation route on grain=provider catalogs), and _links.schema when bound.',
181 content: { 'application/json': { schema: { type: 'object' } } },
182 },
183 '404': errorResponse,
184 },
185 },
186 },
187 '/v1/schemas': {
188 get: {
189 operationId: 'listAllSchemas',
190 summary: 'System-wide schema index',
191 description:
192 'Every provider with extracted schemas, each with its activities and endpoint ids — the discovery entry point for all schemas on the system.',
193 responses: {
194 '200': {
195 description: 'Provider → activity → endpoint-id index.',
196 content: { 'application/json': { schema: { type: 'object' } } },
197 },
198 },
199 },
200 },
201 '/v1/schemas/{provider}': {
202 get: {
203 operationId: 'listProviderSchemas',
204 summary: 'Activities and endpoint ids for a provider',
205 parameters: [providerParam],
206 responses: {
207 '200': {
208 description: 'Activity → endpoint-id index.',
209 content: { 'application/json': { schema: { type: 'object' } } },
210 },
211 '404': errorResponse,
212 },
213 },
214 },
215 '/v1/schemas/{provider}/{activity}': {
216 get: {
217 operationId: 'getActivitySchemas',
218 summary: 'Endpoint-id-keyed schema map for one activity',
219 parameters: [providerParam, activityParam],
220 responses: {
221 '200': {
222 description:
223 'Map of endpoint id → { input, output } self-contained JSON Schemas (current versions).',
224 content: { 'application/json': { schema: { type: 'object' } } },
225 },
226 '404': errorResponse,
227 },
228 },
229 },
230 '/v1/schemas/{provider}/{activity}/{endpointId}': {
231 get: {
232 operationId: 'getSchema',
233 summary: 'One self-contained JSON Schema',
234 parameters: [
235 providerParam,
236 activityParam,
237 {
238 name: 'endpointId',
239 in: 'path',
240 required: true,
241 description:
242 "Path-derived endpoint id (URL-encode slashes), or a listed model rawId/slug which aliases onto that activity's generation route and pins the request `model` field.",
243 schema: { type: 'string' },
244 },
245 {
246 name: 'kind',
247 in: 'query',
248 description: 'Defaults to input.',
249 schema: { type: 'string', enum: ['input', 'output'] },
250 },
251 {
252 name: 'version',
253 in: 'query',
254 description: 'Content hash of a historical version.',
255 schema: { type: 'string' },
256 },
257 {
258 name: 'format',
259 in: 'query',
260 description:
261 'json (default) or types — a self-contained TypeScript module (schema const + generated types, tree-shakeable, zero imports). format=types on an input schema with a model property overlays the live catalog union plus ListedModelId; the schema const and content hash stay the bundled schema.',
262 schema: { type: 'string', enum: ['json', 'types'] },
263 },
264 {
265 name: 'optional',
266 in: 'query',
267 description:
268 'format=types only: optional-property style. exact (default) emits `foo?: T`; undefined emits `foo?: T | undefined`.',
269 schema: { type: 'string', enum: ['exact', 'undefined'] },
270 },
271 ],
272 responses: {
273 '200': {
274 description:
275 'Self-contained JSON Schema ($defs-bundled) — or, with format=types, a TypeScript module — served with ETag. ' +
276 'JSON responses carry `provenance` (upstream sourceUrl, sourceHash, fetchedAt, extractorVersion) so derivations are independently verifiable. ' +
277 '`provenance.derivation` grades how the content was arrived at — `upstream-spec` and `generated` are re-derived every sync and self-heal, while `probe-verified` (confirmed against live API calls on `provenance.verifiedAt`) and `docs-derived` (never confirmed) are point-in-time claims that can go stale.',
278 content: {
279 'application/json': { schema: { type: 'object' } },
280 'text/typescript': { schema: { type: 'string' } },
281 },
282 },
283 '404': errorResponse,
284 },
285 },
286 },
287 '/v1/openapi/{provider}': {
288 get: {
289 operationId: 'getProviderOpenApi',
290 summary: 'Generation-only OpenAPI document for one provider',
291 description:
292 'Assembled from classified endpoints plus the provider connect profile (servers, auth, required headers). ' +
293 'Not a raw upstream-spec mirror. Model-grained providers (today: FAL) require ?model=. ' +
294 'Selections over 40 classified endpoints, or a filter that matches none, return 400 spec_requires_selector. ' +
295 'An unsynced provider returns 404 no_endpoints. ?model= pins the live model enum on provider-grained specs; it does not drop endpoints.',
296 parameters: [
297 providerParam,
298 {
299 name: 'model',
300 in: 'query',
301 description:
302 'Pin to one model (raw id or slug). Required for model-grained providers.',
303 schema: { type: 'string' },
304 },
305 {
306 name: 'activity',
307 in: 'query',
308 description: 'Restrict to one activity group.',
309 schema: { type: 'string', enum: activityEnum },
310 },
311 ],
312 responses: {
313 '200': {
314 description: 'OpenAPI 3.1 document.',
315 content: {
316 'application/openapi+json': { schema: { type: 'object' } },
317 'application/json': { schema: { type: 'object' } },
318 },
319 },
320 '400': errorResponse,
321 '404': errorResponse,
322 '500': errorResponse,
323 },
324 },
325 },
326 '/v1/validate': {
327 post: {
328 operationId: 'validatePayload',
329 summary: 'Validate a payload against a provider endpoint schema',
330 requestBody: {
331 required: true,
332 content: {
333 'application/json': {
334 schema: { $ref: '#/components/schemas/ValidateRequest' },
335 },
336 },
337 },
338 responses: {
339 '200': {
340 description: 'Validation result.',
341 content: {
342 'application/json': {
343 schema: { $ref: '#/components/schemas/ValidateResult' },
344 },
345 },
346 },
347 '400': errorResponse,
348 '404': errorResponse,
349 },
350 },
351 },
352 '/v1/changes': {
353 get: {
354 operationId: 'listChanges',
355 summary: 'Changelog feed (cursor-paginated)',
356 description: 'The polling-friendly alternative to webhooks.',
357 parameters: [
358 {
359 name: 'since',
360 in: 'query',
361 description: 'Unix epoch seconds lower bound.',
362 schema: { type: 'integer' },
363 },
364 { name: 'provider', in: 'query', schema: { type: 'string' } },
365 {
366 name: 'type',
367 in: 'query',
368 schema: { type: 'string', enum: changeTypeEnum },
369 },
370 { name: 'cursor', in: 'query', schema: { type: 'string' } },
371 {
372 name: 'wait',
373 in: 'query',
374 description:
375 'Long-poll: hold up to N seconds (cap 60; "30s" form accepted) until new data exists, then return current data.',
376 schema: { type: 'string' },
377 },
378 {
379 name: 'limit',
380 in: 'query',
381 schema: { type: 'integer', minimum: 1, maximum: 200 },
382 },
383 ],
384 responses: {
385 '200': {
386 description: 'Changes page with next cursor.',
387 content: { 'application/json': { schema: { type: 'object' } } },
388 },
389 },
390 },
391 },
392 '/v1/admin/sync/{provider}': {
393 post: {
394 operationId: 'syncProvider',
395 summary: 'Manually trigger a provider spec sync (admin only)',
396 parameters: [providerParam],
397 security: [{ adminKey: [] }],
398 responses: {
399 '200': {
400 description: 'Sync outcome.',
401 content: { 'application/json': { schema: { type: 'object' } } },
402 },
403 '401': errorResponse,
404 '404': errorResponse,
405 '502': errorResponse,
406 },
407 },
408 },
409 },
410 components: {
411 securitySchemes: {
412 adminKey: {
413 type: 'apiKey',
414 in: 'header',
415 name: 'X-Admin-Key',
416 },
417 bearerAuth: {
418 type: 'http',
419 scheme: 'bearer',
420 description: 'Agent JWT (agent-auth) or API key.',
421 },
422 },
423 schemas: {
424 Error: {
425 type: 'object',
426 required: ['error'],
427 properties: {
428 error: {
429 type: 'object',
430 required: ['code', 'message'],
431 properties: {
432 code: { type: 'string' },
433 message: { type: 'string' },
434 },
435 },
436 },
437 },
438 ServiceStatus: {
439 type: 'object',
440 required: ['service', 'time', 'providers'],
441 properties: {
442 service: { type: 'string', const: 'modelschemas' },
443 time: { type: 'integer' },
444 providers: {
445 type: 'array',
446 items: {
447 type: 'object',
448 properties: {
449 id: { type: 'string' },
450 displayName: { type: 'string' },
451 status: {
452 type: 'string',
453 enum: ['active', 'degraded', 'disabled', 'pending'],
454 },
455 lastPolledAt: { type: ['integer', 'null'] },
456 lastSyncedAt: { type: ['integer', 'null'] },
457 counts: {
458 type: 'object',
459 properties: {
460 models: { type: 'integer' },
461 endpoints: { type: 'integer' },
462 schemas: { type: 'integer' },
463 },
464 },
465 },
466 },
467 },
468 },
469 },
470 ValidateRequest: {
471 type: 'object',
472 required: ['provider', 'endpointId', 'payload'],
473 properties: {
474 provider: { type: 'string' },
475 endpointId: { type: 'string' },
476 kind: { type: 'string', enum: ['input', 'output'] },
477 payload: {},
478 },
479 },
480 ValidateResult: {
481 type: 'object',
482 required: ['valid', 'errors'],
483 properties: {
484 valid: { type: 'boolean' },
485 errors: {
486 type: 'array',
487 items: {
488 type: 'object',
489 properties: {
490 path: { type: 'string' },
491 message: { type: 'string' },
492 keyword: { type: 'string' },
493 },
494 },
495 },
496 },
497 },
498 },
499 },
500} as const