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

gate-ai

v0.1.0

Published

Dependency-free TypeScript client for Gate AI public APIs

Readme

Gate AI TypeScript SDK

A lightweight, type-safe client for calling Gate AI model and media APIs from TypeScript and JavaScript. The SDK stays close to the HTTP API: it handles authentication, typed request and response envelopes, streaming, multipart uploads, retries, and error decoding while your application owns orchestration and conversation state.

Documentation: https://gate.ai/docs

Languages: English | 简体中文

When to Use This SDK

Use the client when your application needs direct access to:

  • Chat Completions and Responses APIs
  • Anthropic Messages, Gemini, and Vertex-compatible APIs
  • Embeddings and image generation or editing
  • Speech-to-text and text-to-speech, including streaming
  • Asynchronous video generation and result download
  • Generation usage and credit balance queries

This is an API client, not an agent framework. Agent loops, tool dispatch, memory, and application state remain in your code.

Requirements

  • Node.js 18 or newer, or a modern browser with Fetch, FormData, Blob, and Web Streams
  • A Gate AI base URL
  • A Gate AI API key for authenticated operations

The package is ESM-only and has no runtime dependencies.

Installation

npm add gate-ai

The package can also be installed with pnpm add gate-ai, yarn add gate-ai, or bun add gate-ai.

Quickstart

Set the base URL to the Gate AI root URL. Do not append an API suffix such as /openai/v1. Custom reverse-proxy path prefixes are preserved, so a base URL such as https://proxy.example.com/gateai routes requests under /gateai.

import { DEFAULT_BASE_URL, GateAI } from "gate-ai";

const client = new GateAI(process.env.GATEAI_BASE_URL ?? DEFAULT_BASE_URL, {
  apiKey: process.env.GATEAI_API_KEY,
});

const response = await client.chat.send({
  model: "openai/gpt-5.2",
  messages: [
    { role: "user", content: "Explain embeddings in one sentence." },
  ],
});

console.log(response.data.choices?.[0]?.message?.content);

In Node.js, the client reads GATEAI_API_KEY automatically when neither apiKey nor securitySource is supplied.

Streaming

Streaming operations return an async iterable of parsed Server-Sent Events.

const stream = await client.chat.stream({
  model: "openai/gpt-5.2",
  messages: [{ role: "user", content: "Write a short haiku." }],
});

for await (const event of stream) {
  console.log(event.data.choices?.[0]?.delta);
}

Each event includes parsed data, the original raw JSON, and any SSE id, type, or retry metadata. Call await stream.close() when abandoning a stream before it is exhausted. A stream can be consumed only once.

API Reference

The client exposes resources grouped by API domain:

| Resource | Main operations | | --- | --- | | chat | Chat completions and streaming | | responses | Responses API calls and streaming | | embeddings | Vector embeddings | | anthropic.messages | Anthropic-compatible messages | | gemini, vertex | Gemini-compatible content generation | | images | Image generation and editing | | stt, tts | Speech transcription and synthesis | | videoGeneration | Submit, inspect, and download video jobs | | generations | Query persisted generation usage | | credits | Query the current credit balance |

See the TypeScript API Reference for method signatures, endpoints, response types, raw-call variants, and request options.

The model-list operation is intentionally not exposed by this SDK.

Client Configuration

const client = new GateAI(DEFAULT_BASE_URL, {
  apiKey: process.env.GATEAI_API_KEY,
  securitySource: async (signal) => loadRotatingAPIKey(signal),
  headers: { "X-Gate-Request-Source": "my-service" },
  userAgent: "my-service/1.0.0",
  retry: {
    maxRetries: 2,
    initialBackoffMs: 250,
    maxBackoffMs: 5_000,
  },
});

DEFAULT_BASE_URL is the production API root, https://api.gate.ai. Pass a different absolute HTTP or HTTPS URL to use a proxy, test environment, or other deployment.

securitySource is evaluated before every authenticated request and takes precedence over apiKey. A custom fetch implementation can also be supplied for testing or non-standard runtimes.

Responses and Errors

JSON operations return SDKResponse<T>, which contains:

  • data: the decoded response body
  • raw: the original response text
  • status and headers: HTTP response metadata
  • response: the native Fetch Response

Binary operations return BinaryResponse, exposing the response stream, content type, headers, and an arrayBuffer() convenience method. Text-to-speech responses also expose generationId when the server returns X-Gate-Generation-Id.

Non-success responses throw APIError. It exposes the HTTP status, provider error type, code and message, request ID, trace ID, raw body, and native Response. Missing credentials fail before a request is sent with MissingAPIKeyError.

GET requests retry transient network failures and HTTP 408, 429, 500, 502, 503, and 504 responses. POST requests do not retry by default because they may be billed. Set maxRetries or provide an idempotencyKey only when replay is safe. Multipart uploads are never retried. Retry-After and retry-after-ms are respected; when both are present, retry-after-ms takes precedence.

Examples

Development

npm ci
npm run typecheck
npm test
npm pack --dry-run

The canonical HTTP contract is maintained in the Gate AI documentation.