prometheus-openapi
v3.12.1
Published
OpenAPI specification for the Prometheus API.
Readme
Prometheus OpenAPI
OpenAPI 3.1 specification for the Prometheus HTTP API.
Installation
npm install prometheus-openapiUsage
Import the OpenAPI Schema
// ESM
import schema from 'prometheus-openapi';
// CommonJS
const schema = require('prometheus-openapi');Or import directly:
import schema from 'prometheus-openapi/openapi.json';The YAML version is also available at openapi.yaml.
TypeScript Types
This package includes auto-generated TypeScript types for the Prometheus HTTP API:
import type { paths, operations, components } from 'prometheus-openapi';
// Example: Type for the /query response
type QueryResponse = paths['/query']['get']['responses']['200']['content']['application/json'];
// Example: Type for the /labels response
type LabelsResponse = paths['/labels']['get']['responses']['200']['content']['application/json'];Works great with API clients like openapi-fetch:
import createClient from 'openapi-fetch';
import type { paths } from 'prometheus-openapi';
const client = createClient<paths>({ baseUrl: 'http://localhost:9090/api/v1' });
const { data, error } = await client.GET('/query', {
params: { query: { query: 'up' } },
});Files
| File | Description |
|------|-------------|
| openapi.json | OpenAPI 3.1 specification (JSON) |
| openapi.yaml | OpenAPI 3.1 specification (YAML) |
| types.d.ts | TypeScript type definitions |
Development
Generate the JSON schema and TypeScript types from the YAML source:
npm run gen # Generate both JSON and types
npm run gen:json # Generate JSON only
npm run gen:types # Generate TypeScript types onlyRelated
- Prometheus JS — Ready-to-use typed client built on this spec (supports Vanilla Fetch, React Query, and SWR)
- Prometheus HTTP API Documentation
License
MIT
