Skip to content

feat: add per-provider, model index, and schema API endpoints#1743

Open
wojons wants to merge 2 commits into
anomalyco:devfrom
wojons:feature/api-endpoints
Open

feat: add per-provider, model index, and schema API endpoints#1743
wojons wants to merge 2 commits into
anomalyco:devfrom
wojons:feature/api-endpoints

Conversation

@wojons
Copy link
Copy Markdown
Contributor

@wojons wojons commented May 9, 2026

Summary

Add three new lightweight API endpoints to models.dev — a model index, per-provider data, and a JSON Schema — making the data more accessible for AI agents without requiring a full 1.8 MB download.

New Endpoints

Endpoint Size Description
/api/models.json ~509 KB Model ID → providers list + capabilities (tool_call, reasoning, modalities, open_weights)
/api/{provider}.json 0.6–209 KB each Full data for a single provider (120 files)
/api/schema.json ~14 KB JSON Schema describing the full data shape

Usage

# Find which providers offer a specific model
curl -s https://models.dev/api/models.json | jq '."claude-sonnet-4-5".providers'
# Get full pricing/details for one provider
curl -s https://models.dev/api/anthropic.json | jq '.anthropic.models["claude-sonnet-4-5"].cost'
# Validate data structure
curl -s https://models.dev/api/schema.json
Implementation
Build (packages/web/script/build.ts):
- After the existing _api.json is generated, also writes per-provider _api/{provider}.json files
- Builds a reverse model index (_api/models.json) by iterating all providers and grouping models by their model ID
- Generates a JSON Schema (_api/schema.json) from the Provider and Model shapes
Worker (packages/function/src/worker.ts):
- Routes /api/models.json → /_api/models.json
- Routes /api/schema.json → /_api/schema.json
- Routes /api/{provider}.json → /_api/{provider}.json (regex match on ^/api/[a-z0-9][a-z0-9._-]+\.json$)
Documentation:
- "How to use" modal on the site updated with sections and curl examples for all new endpoints
- README updated with endpoints table and usage examples
Notes
- The model index is ~1/3 the size of the full API (509 KB vs 1.8 MB)
- Name mismatch warnings are printed during build when different providers give the same model ID different display names (pre-existing data inconsistency, not introduced here)
- No new dependencies added
- Existing bun validate flow is unaffected since the new files derive from the same generate() output

wojons added 2 commits May 9, 2026 12:05
Generate per-provider JSON files, a lightweight model index (model ID →
providers + capabilities), and a JSON Schema at build time. Update the
Cloudflare Worker to route /api/models.json, /api/schema.json, and
/api/{provider}.json. Document all new endpoints in the site and README.
Lightweight provider index (20 KB, 118 providers) with id, name, doc,
model_count, npm, and api fields. Helps users find the correct Provider ID
when providers have similar names. Update site modal and README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant