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

@magic-ai-tools/ai-api-gateway-client

v1.0.8

Published

TypeScript client SDK for AI API Gateway

Downloads

548

Readme

AI API Gateway Client

A type-safe TypeScript/JavaScript client SDK for the AI API Gateway.

Installation

npm install ai-api-gateway-client

Quick Start

import { createClient } from 'ai-api-gateway-client';

// Create a client instance
const client = createClient({
  baseUrl: 'https://your-gateway.com',
  apiKey: 'your-api-key',
  system: 'your-system-code',
  defaultWatermark: 'your-watermark' // Optional default watermark
});

// Generate an image with Flux 1 Schnell
const result = await client.fluxSchnell({
  prompt: 'A beautiful sunset over the ocean',
  aspectRatio: '16:9'
});

console.log('Task ID:', result.data.taskId);

Configuration

| Option | Type | Required | Description | |--------|------|----------|-------------| | baseUrl | string | Yes | Base URL of the AI API Gateway | | apiKey | string | Yes | API key for authentication | | system | string | Yes | System identifier for your application | | defaultWatermark | string | No | Default watermark text for all requests |

Available APIs

Image Generation

Flux 1 Schnell

Fast image generation with good quality.

const result = await client.fluxSchnell({
  prompt: 'A cyberpunk cityscape at night',
  aspectRatio: '16:9', // '1:1' | '16:9' | '9:16' | '3:2' | '2:3'
  seed: 12345, // Optional: for reproducible results
  watermarkText: 'custom-watermark', // Optional: override default
  webHookUrl: 'https://your-webhook.com/callback' // Optional
});

GPT Image 1

Advanced image generation and editing.

const result = await client.gptImage1({
  prompt: 'A portrait in impressionist style',
  size: '1024x1024', // Optional
  variants: 2, // Optional: number of variants
  urls: ['https://example.com/reference.jpg'], // Optional: reference images
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Seedream 4

High-quality image generation with multiple variants.

const result = await client.seedream4({
  prompt: 'A serene mountain landscape',
  aspectRatio: '16:9', // '1:1' | '16:9' | '9:16' | '3:2' | '2:3' | '3:4' | '4:3' | '21:9'
  resolution: '2K', // '1K' | '2K' | '4K'
  variants: 3, // 1-6
  urls: ['https://example.com/reference.jpg'], // Optional
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Imagen 4 Ultra

Google's advanced image generation.

const result = await client.imagen4Ultra({
  prompt: 'A photorealistic portrait',
  aspectRatio: '1:1', // '1:1' | '16:9' | '9:16' | '4:3' | '3:4'
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Image Transformation

Nano Banana

const result = await client.nanoBanana({
  prompt: 'Transform to anime style',
  aspectRatio: '1:1',
  urls: ['https://example.com/source.jpg'],
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Nano Banana Pro

Advanced transformation with resolution and format options.

const result = await client.nanoBananaPro({
  prompt: 'Transform to watercolor painting',
  aspectRatio: '1:1',
  urls: ['https://example.com/source.jpg'],
  resolution: '2K', // '1K' | '2K' | '4K'
  outputFormat: 'png', // 'jpg' | 'png'
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Image Processing

Remove Background

const result = await client.rmBg({
  imageUrl: 'https://example.com/photo.jpg',
  watermarkText: 'custom-watermark',
  webHookUrl: 'https://your-webhook.com/callback'
});

Task Management

Get Task

const task = await client.getTask('task-id-here');
console.log('Status:', task.data.status);
console.log('Outputs:', task.data.outputs);

List Tasks

const tasks = await client.listTasks({
  page: 1,
  pageSize: 20
});

console.log('Total:', tasks.data.pagination.total);
tasks.data.tasks.forEach(task => {
  console.log(`${task.id}: ${task.status}`);
});

Retry Webhook

const result = await client.retryWebhook('task-id-here');
console.log('Webhook status:', result.data.webHookStatus);

Error Handling

The client throws AiApiGatewayError for API errors:

import { createClient, AiApiGatewayError } from 'ai-api-gateway-client';

try {
  const result = await client.fluxSchnell({
    prompt: 'A beautiful sunset',
    aspectRatio: '16:9'
  });
} catch (error) {
  if (AiApiGatewayError.isAiApiGatewayError(error)) {
    console.error('API Error:', error.message);
    console.error('Error Code:', error.code);
    console.error('Status Code:', error.statusCode);
    console.error('Response:', error.response);
  } else {
    throw error;
  }
}

TypeScript Support

The client is written in TypeScript and provides full type definitions:

import type {
  ClientConfig,
  ApiResponse,
  TaskResponse,
  Task,
  FluxSchnellParams,
  GptImage1Params,
  // ... other types
} from 'ai-api-gateway-client';

Release

npm run build
#npm login # or set accessToken
npm config set //registry.npmjs.org/:_authToken npm_xxxxxxxxxxxxxxxxxxxxxxxx
npm publish --access public

Credit

Thanks zzo.ai for the donation.

License

MIT