npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

llm-schemas

v1.0.2

Published

Shared Zod schemas for LLM API request validation (OpenAI Chat Completions, OpenAI Responses, Anthropic Messages)

Downloads

662

Readme

llm-schemas npm version npm downloads

Shared Zod schemas for validating LLM API request bodies. Covers OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages. Used by both llm-mock-server and copilot-sdk-proxy.

Table of contents

Install

npm install llm-schemas

Requires Node.js 22+ and Zod 4.

Usage

Import from a sub-path to get schemas for a specific API, or import from the top level to get everything namespaced.

OpenAI Chat Completions

import {
  OpenAIRequestSchema,
  MessageSchema,
  ToolSchema,
} from "llm-schemas/openai/chat-completions";

const body = OpenAIRequestSchema.parse(req.body);
console.log(body.model, body.messages);

OpenAI Responses

import {
  ResponsesRequestSchema,
  FunctionToolSchema,
  InputMessageSchema,
} from "llm-schemas/openai/responses";

const body = ResponsesRequestSchema.parse(req.body);
console.log(body.model, body.input);

Anthropic Messages

import {
  AnthropicRequestSchema,
  MessageSchema,
  ToolDefinitionSchema,
} from "llm-schemas/anthropic";

const body = AnthropicRequestSchema.parse(req.body);
console.log(body.model, body.max_tokens, body.messages);

Top-level import

If you need all three in one place, the root export namespaces them so there are no naming collisions.

import { openai, anthropic } from "llm-schemas";

openai.chatCompletions.OpenAIRequestSchema.parse(body);
openai.responses.ResponsesRequestSchema.parse(body);
anthropic.AnthropicRequestSchema.parse(body);

What's in each schema

Request schemas

All three request schemas use z.looseObject() at the top level, so unknown fields pass through without failing validation. Every field from the official API specs is included. Fields that don't need parsing are typed as z.unknown().optional().

Specs the schemas were built from:

| Schema | Required fields | Total fields | | ------ | --------------- | ------------ | | OpenAIRequestSchema | model, messages | 35 | | AnthropicRequestSchema | model, max_tokens, messages | 18 | | ResponsesRequestSchema | (none) | 29 |

The Responses API spec makes both model and input optional. If your app needs them to be required, add a .refine() after parsing.

Building blocks

OpenAI Chat Completions

  • ContentPartSchema - a content part like { type: "text", text: "..." } (looseObject)
  • MessageSchema - a chat message with role, content, tool_calls, etc.
  • ToolSchema - a tool definition with function.name, function.parameters, function.strict

Anthropic Messages

  • TextBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema - typed content blocks
  • LooseContentBlockSchema - union of known blocks + a fallback for unknown types
  • MessageSchema - a message with role and string or block array content
  • ToolDefinitionSchema - a tool with name, description, input_schema

OpenAI Responses

  • InputMessageSchema - a conversation message in the input array
  • FunctionCallInputSchema, FunctionCallOutputSchema - function call round-trip items
  • FunctionToolSchema - a function tool (with strict field)
  • RawToolSchema - accepts any tool shape as Record<string, unknown>

Every schema also exports its inferred TypeScript type (e.g. OpenAIRequest, AnthropicRequest, Message, FunctionTool).

Import paths

| Path | What you get | | ---- | ------------ | | llm-schemas | Everything, namespaced as openai.chatCompletions, openai.responses, anthropic | | llm-schemas/openai | Both OpenAI APIs, namespaced as chatCompletions and responses | | llm-schemas/openai/chat-completions | Chat completions schemas only | | llm-schemas/openai/responses | Responses schemas only | | llm-schemas/anthropic | Anthropic schemas only |

Development

npm run build # Compile TypeScript
npm test # Run tests
npm run lint # Lint with oxlint
npm run check # All three: typecheck + lint + test

Licence

MIT