Server Proxy

Keep your Visgate API key on the server with @visgate_ai/server-proxy.

The server proxy keeps your API key secure by injecting it on the server before forwarding requests to Visgate. The client never sees the key.

Installation

npm install @visgate_ai/server-proxy

Environment Variables

Set these on your server:

VariableRequiredDescription
VISGATE_API_KEYYesYour Visgate API key (vg-...)
VISGATE_BASE_URLNoDefaults to https://visgateai.com/api/v1

BYOK Keys (optional)

To use provider keys on the server (so the client never sends them):

VariableProvider
VISGATE_FAL_KEY or FAL_KEYFal
VISGATE_REPLICATE_KEY or REPLICATE_API_TOKENReplicate
VISGATE_RUNWAY_KEY or RUNWAY_API_KEYRunway
VISGATE_RUNPOD_KEY or RUNPOD_API_KEYRunPod

The proxy injects these headers when the client does not send them.

Next.js App Router

Create the route file:

app/api/visgate/[...path]/route.ts
export const maxDuration = 300;
export { GET, POST, PUT, DELETE, OPTIONS } from "@visgate_ai/server-proxy/next";

Then in your client code:

import { Client } from "@visgate_ai/client";
 
const client = new Client({ proxyUrl: "/api/visgate" });
const result = await client.generate("a sunset");

For video generation, use a longer client timeout (e.g. 5 minutes) so the request doesn't abort before the API responds:

const client = new Client({ proxyUrl: "/api/visgate", timeout: 300_000 });

Core API (Any Framework)

For Express, Hono, Fastify, or any Node.js server:

import { proxyToVisgate } from "@visgate_ai/server-proxy";
 
// In your handler:
const response = await proxyToVisgate(request, {
  pathSegments: ["health"],
  // apiKey: process.env.VISGATE_API_KEY  (default)
  // baseUrl: process.env.VISGATE_BASE_URL (default)
  // timeoutMs: 300000 (default 5 min)
});

Express Example

import express from "express";
import { proxyToVisgate } from "@visgate_ai/server-proxy";
 
const app = express();
 
app.all("/api/visgate/*", async (req, res) => {
  const pathSegments = req.path.replace("/api/visgate/", "").split("/");
  const response = await proxyToVisgate(req, { pathSegments });
  res.status(response.status);
  response.headers.forEach((value, key) => res.setHeader(key, value));
  const body = await response.text();
  res.send(body);
});

On this page