OpenAI Chat Completion to TypeScript

Paste an OpenAI Chat Completions JSON response and get a TypeScript interface for choices, usage, message, tool_calls, and the rest. Works for any /v1/chat/completions response.

JSON input valid
TypeScript output

      
    

About this conversion

The official openai npm package ships its own TypeScript types, but you'll still want a generated interface when you're calling the OpenAI-compatible endpoint of a different provider (Groq, Together, OpenRouter, local Ollama), proxying responses through your own backend, or persisting the response to a database where the schema needs to match exactly what came back over the wire. Generating types from a real response captures the actual shape, including provider-specific extensions OpenAI's official types don't know about.

The shape includes id, object, created, model, choices[].message, choices[].finish_reason, and a usage block with prompt/completion/total tokens. Recent gpt-4o responses also include nested prompt_tokens_details and completion_tokens_details, plus an optional system_fingerprint. Paste your own response (with a tool_calls field, refusal, or logprobs filled in) and the converter merges everything into one accurate interface.

Same shape, other validators

Other JSON shapes