Inference Logoinference.sh

Remix

Set up the inference.sh proxy in Remix applications.


Installation

bash
1npm install @inferencesh/sdk

Basic Setup

Create app/routes/api.inference.proxy.ts:

typescript
1import { createRequestHandler } from "@inferencesh/sdk/proxy/remix";23const handler = createRequestHandler();45// Handle both GET and POST requests6export const loader = handler;7export const action = handler;

Environment Variable

Add to your .env:

bash
1INFERENCE_API_KEY="inf_your_key_here"

Client Configuration

typescript
1import { inference } from "@inferencesh/sdk";23const client = inference({4  proxyUrl: "/api/inference/proxy"5});67export async function generateImage(prompt: string) {8  const result = await client.run({9    app: "infsh/flux",10    input: { prompt }11  });12  13  return result.output;14}

With Authentication

Check user session before proxying:

typescript
1import { createRequestHandler } from "@inferencesh/sdk/proxy/remix";2import { getSession } from "~/lib/session.server";34const proxyHandler = createRequestHandler();56export const loader = async (args) => {7  const session = await getSession(args.request.headers.get("Cookie"));8  9  if (!session.userId) {10    return new Response(JSON.stringify({ error: "Unauthorized" }), {11      status: 401,12      headers: { "Content-Type": "application/json" },13    });14  }15  16  return proxyHandler(args);17};1819export const action = async (args) => {20  const session = await getSession(args.request.headers.get("Cookie"));21  22  if (!session.userId) {23    return new Response(JSON.stringify({ error: "Unauthorized" }), {24      status: 401,25      headers: { "Content-Type": "application/json" },26    });27  }28  29  return proxyHandler(args);30};

Custom API Key Resolution

typescript
1import { createRequestHandler } from "@inferencesh/sdk/proxy/remix";23const handler = createRequestHandler({4  resolveApiKey: async () => {5    // Load from secrets manager6    return await getSecret("INFERENCE_API_KEY");7  }8});910export const loader = handler;11export const action = handler;

Route Naming

Remix uses file-based routing with dots as path separators:

FileURL
api.inference.proxy.ts/api/inference/proxy
api_.inference.proxy.ts/api/inference/proxy (no layout)

Streaming

The Remix handler supports streaming responses for real-time task updates.

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.