Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

llms-txt.ts

152 lines7.9 KB

1/**
2 * The /llms.txt agent guide (PLAN.md task 4.1). Shared module so the /docs
3 * page (7.3) and the distributable skill (7.6) render from the same source.
4 */
5export const llmsTxt = `# modelschemas
6​
7Live AI model schema service. Per-endpoint request/response JSON Schemas and
8model metadata for 30+ monitored providers (OpenAI, Anthropic, Gemini, xAI
9Grok, Mistral, Groq, DeepSeek, and more — GET /v1/providers for the full
10roster), refreshed automatically: model lists every 15 minutes, full OpenAPI
11spec syncs daily. Responses are JSON unless noted (\`text/typescript\`,
12\`application/openapi+json\`).
13​
14## Why use this
15​
16- Discover which models exist *right now*, across providers, by activity
17 (chat, image, video, audio, embeddings, moderation). Grain=provider
18 catalogs (Grok, OpenAI, …) set \`activity\` on each row and
19 \`schemaEndpointId\` pointing at the shared generation route
20 (\`v1/images/generations\`, \`images/generations\`, …). \`pricing\` is a
21 RateCard (or null when no price is stored). List rows carry a summary:
22 \`{currency, per: 'token', inputPerMillion, outputPerMillion, tiered?}\`
23 at the base rate, or \`{currency, per: 'second' | 'character' | 'image' | …}\`
24 for a card billed by unit. \`currency\` is ISO 4217 (mostly USD; nothing
25 is converted, so compare only like with like); \`?pricing=1\` returns
26 the full card. \`/v1/status\` counts live \`priced\` models per provider
27 and scores \`completeness\` (the share of chat facts filled; \`score\` is
28 null with no chat models). A provider there carries \`docsFailing\`,
29 \`priceClearsRefused\`, or \`updateStorm\` while its stored docs facts or
30 prices may be stale, or one poll rewrote most of its live rows.
31- Fetch a self-contained JSON Schema (refs bundled under $defs) for any
32 provider generation endpoint — request (input) and response (output).
33 A listed model rawId also works as \`{endpointId}\`: it aliases onto that
34 route and pins the request \`model\` field to the one id.
35- Validate a payload server-side before spending tokens on a provider call.
36- Estimate the cost of a call from the stored rate card, in the card's
37 currency (\`POST /v1/estimate\`).
38- Poll /v1/changes (or subscribe via webhooks) to hear about new models and
39 API revisions. A catalog.shape_changed change means the model row itself
40 changed shape (payload.version, payload.notes): re-read openapi.json.
41 /v1 changes are otherwise additive; ignore keys you do not know.
42​
43## Quickstart (no auth needed for reads)
44​
451. GET /v1 — endpoint index.
462. GET /v1/models?activity=chat — cross-provider catalog of chat models.
473. GET /v1/schemas — system-wide index: every provider's activities and
48 endpoint ids in one response (all schemas on the system).
494. GET /v1/schemas/anthropic — activities + endpoint ids for one provider.
505. GET /v1/schemas/anthropic/chat/{endpointId}?kind=input — the JSON Schema
51 for a request body (endpoint ids contain slashes; URL-encode them).
52 Grain=provider models also accept the raw id:
53 \`/v1/schemas/grok/image/grok-imagine-image-2.0?kind=input\`.
546. GET /v1/openapi/{provider} — generation-only OpenAPI (servers, auth,
55 paths). FAL requires ?model=. Over 40 endpoints, or a filter that
56 matches none: 400 spec_requires_selector. HTTP only (no MCP tool).
577. POST /v1/validate {"provider","endpointId","payload"} — check a payload.
588. POST /v1/estimate {"provider","model","request"?,"usage"?} — {amount,
59 currency} for a call from the stored rate card. Missing levers → 422;
60 no card → 404 unknown_pricing. See "Estimate usage" below.
619. GET /v1/changes?since=<unix epoch> — what changed.
62​
63## TypeScript types
64​
65Add \`?format=types\` to a schema read
66(GET /v1/schemas/{provider}/{activity}/{endpointId}) to get a self-contained
67TypeScript module instead of JSON: the schema as a pure const plus generated
68interfaces (\`text/typescript\`, zero imports, tree-shakeable, same ETag
69discipline). \`?optional=undefined\` widens optional properties to
70\`T | undefined\` for exactOptionalPropertyTypes consumers; default is
71\`foo?: T\`. A request \`model\` field is the live catalog union plus
72\`ListedModelId<'provider'>\` (still branded when the catalog is empty).
73Minted by \`listModels\` / \`listProviderModels\` / \`getModel\` (or
74\`asListedModelId\`). Arbitrary \`string\` values do not assign.
75​
76## Hypermedia (HAL, extended)
77​
78Every JSON read response carries \`_links\`: HAL link objects extended with
79\`method\`, \`contentType\`, and an inline \`example\` (a resolvable URL for
80GETs, a request body for POSTs) so you can follow the API without consulting
81docs. Templated hrefs (RFC 6570) set \`"templated": true\` and always include
82an example. Start at GET /v1 and follow \`_links\`.
83​
84## Long-polling
85​
86No sleep tool? Add \`?wait=30\` (seconds, cap 60, \`30s\` form accepted) to
87GET /v1/changes or GET /v1/status: the request holds until new data lands or
88the window expires, then returns whatever is current. One request, one
89rate-limit token.
90​
91## Caching
92​
93Read responses carry ETag (content hash), Last-Modified, Cache-Control with
94stale-while-revalidate, X-Fetched-At and X-Stale-At (unix epoch seconds).
95Send If-None-Match to get 304s.
96​
97## Auth (optional — unlocks higher rate limits + webhooks)
98​
99- Agent-auth protocol: discovery at /.well-known/agent-configuration,
100 register at POST /api/auth/agent/register, then execute capabilities with
101 short-lived JWTs.
102- Simple alternative: POST /v1/agents/register-key { "name" } returns an API
103 key once; send it as Authorization: Bearer <key>.
104​
105## Machine-readable spec
106​
107GET /openapi.json — OpenAPI 3.1 for this service; every operation has an
108operationId. GET /skill — installable agent skill (SKILL.md) teaching this
109full workflow.
110​
111## Estimate usage
112​
113\`usage\` on POST /v1/estimate takes one of two shapes. A payload that
114mixes them gets 422 mixed_usage.
115​
116- The provider's own usage object, as the API returned it: OpenAI
117 Responses or Chat Completions \`usage\`, Anthropic \`usage\`, or Gemini
118 \`usageMetadata\`. The service maps it to card levers.
119- Card levers. Their counts do not overlap: \`input_tokens\` excludes the
120 tokens in \`cache_read_tokens\`, \`cache_write_tokens\` (5-minute writes)
121 and \`cache_write_1h_tokens\`. A card can also read \`reasoning_tokens\`,
122 \`audio_tokens\`, \`image_tokens\` or \`web_searches\`; a count in one of
123 these is not also in \`input_tokens\` or \`output_tokens\`. The model's
124 \`pricing.inputs\` (GET /v1/models/{provider}/{id}) lists the levers its
125 card reads.
126​
127| Native field | Card lever |
128| --- | --- |
129| OpenAI \`input_tokens\` or \`prompt_tokens\` | \`input_tokens\`, less cached tokens and cache writes |
130| OpenAI \`*_details.cached_tokens\` | \`cache_read_tokens\` |
131| OpenAI \`*_details.cache_write_tokens\` | \`cache_write_tokens\` |
132| OpenAI \`prompt_tokens_details.image_tokens\` | \`image_tokens\` when the card reads it; otherwise it stays in \`input_tokens\` |
133| OpenAI \`prompt_tokens_details.text_tokens\` | not subtracted; it is already inside \`prompt_tokens\` |
134| OpenAI \`output_tokens\` or \`completion_tokens\` | \`output_tokens\` |
135| Anthropic \`input_tokens\` | \`input_tokens\` (already excludes cache) |
136| Anthropic \`cache_read_input_tokens\` | \`cache_read_tokens\` |
137| Anthropic \`cache_creation_input_tokens\` | \`cache_write_tokens\`; 1-hour writes go to \`cache_write_1h_tokens\` |
138| Gemini \`promptTokenCount\` | \`input_tokens\`, less \`cachedContentTokenCount\` |
139| Gemini \`cachedContentTokenCount\` | \`cache_read_tokens\` |
140| Gemini \`candidatesTokenCount\` + \`thoughtsTokenCount\` | \`output_tokens\` |
141​
142Reasoning, audio, image and video counts move to their own lever only
143when the card reads that lever. Otherwise they stay in the total, because
144the source bills them at that rate. Example: gpt-5 usage
145\`{"input_tokens":12000,"input_tokens_details":{"cached_tokens":4000},"output_tokens":800}\`
146prices 8000 input, 4000 cached and 800 output tokens.
147​
148## Errors
149​
150All errors are JSON: { "error": { "code", "message" } }. Messages include
151remedies (e.g. valid provider ids on a 404).