Skip to main content
With Nuwa LLM Gateway, you can unify multiple LLM providers (OpenAI, OpenRouter, LiteLLM) behind a single endpoint with DID authentication and usage-based pricing. The gateway provides provider-first routing, automatic usage tracking, and seamless payment integration. NPM Package: @nuwa-ai/llm-gateway - Ready to use without building from source.
Before you start: obtain a Service Key for your service DID. See the Service Key guide and use the copied value as SERVICE_KEY.

Quick start

Provider routing

The gateway uses provider-first routing for clear endpoint organization:
  • OpenAI
  • OpenRouter
  • LiteLLM
# Chat completions
POST /openai/v1/chat/completions

# Responses
POST /openai/v1/responses

Using PaymentChannelHttpClient

For programmatic access with automatic payment handling, use the PaymentChannelHttpClient from the Payment Kit:
  • Installation & Setup
  • Making Requests
  • Error Handling
npm install @nuwa-ai/payment-kit @nuwa-ai/identity-kit
import { PaymentChannelHttpClient } from '@nuwa-ai/payment-kit';
import { IdentityKit } from '@nuwa-ai/identity-kit';

// Initialize identity environment
const env = await IdentityKit.bootstrap({
  method: 'rooch',
  vdrOptions: {
    network: 'test',
  },
});

// Import your Service Key
await env.keyManager.importKeyFromString('0x...');
const signer = env.keyManager.getSigner();

// Create HTTP client
const client = new PaymentChannelHttpClient({
  baseUrl: 'http://localhost:8080',
  signer,
  chainConfig: { network: 'test' },
});

Pricing configuration

The gateway supports flexible pricing configuration:
  • Built-in pricing: Default model pricing for OpenAI models
  • Pricing overrides: Custom pricing via PRICING_OVERRIDES environment variable
  • Global multiplier: Adjust all costs with PRICING_MULTIPLIER (range 0-2)

Usage tracking

  • Automatic tracking: All requests are logged with token counts and USD costs
  • Streaming support: Chat Completions automatically inject stream_options.include_usage=true
  • Response API: Usage appears in response.completed SSE events
  • Access logs: Structured JSON logs to stdout with request details

Common issues

  • “SERVICE_KEY is required”: Generate and set your service key from the Service Key guide
  • “At least one provider API key is required”: Configure at least one provider API key
  • Port conflicts: Use --port <number> to specify a different port

Relevant Docs