Skip to main content

TypeScript SDK

@nanogpt/sdk is NanoGPT’s official client. It has no runtime dependencies, is ESM-only and needs Node.js 22 or later, or another runtime with Fetch and Web Streams.

What it covers

For anything else, call the HTTP API directly. See the API reference.

Streaming and errors

Use the stream helpers. The create helpers return one JSON response and reject stream: true.
A failure after a stream has started arrives as an event on the HTTP 200 response. The SDK throws it as a NanoGPTError with the status from that event, or 500 if the event has none, so output you have already received may be partial. To cancel a request or set a timeout, pass an AbortSignal as signal. To read headers such as X-Request-ID before the body, pass onResponse.

API host

The client defaults to https://api.nano-gpt.com, the direct API host. Set baseURL to use another host.

Using the OpenAI SDK instead

NanoGPT is OpenAI-compatible, so the official OpenAI SDK also works:

Other packages

nanogptjs, nanogpt-client and the npm package named nanogpt aren’t published or reviewed by NanoGPT. They would receive your API key, so check them yourself before using them.