Skip to main content

Documentation Index

Fetch the complete documentation index at: https://runinfra.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

The Vercel AI SDK ships a first-class OpenAI adapter. Override the base URL and key to route through RunInfra.

Install

npm i ai @ai-sdk/openai

Configure the provider

// lib/runinfra.ts
import { createOpenAI } from "@ai-sdk/openai";

export const runinfra = createOpenAI({
  baseURL: "https://api.runinfra.ai/v1",
  apiKey: process.env.RUNINFRA_API_KEY,
});

Stream text in a Next.js route

// app/api/chat/route.ts
import { streamText } from "ai";
import { runinfra } from "@/lib/runinfra";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({
    model: runinfra("default"),
    messages,
  });
  return result.toDataStreamResponse();
}

Generate structured data

import { generateObject } from "ai";
import { runinfra } from "@/lib/runinfra";
import { z } from "zod";

const { object } = await generateObject({
  model: runinfra("default"),
  schema: z.object({
    merchant: z.string(),
    total_usd: z.number(),
    items: z.array(z.string()),
  }),
  prompt: "Extract receipt fields: $12.50 at Blue Bottle for coffee and a muffin",
});

Tool calling

import { streamText, tool } from "ai";
import { z } from "zod";

const result = streamText({
  model: runinfra("default"),
  messages,
  tools: {
    getWeather: tool({
      description: "Get weather for a city",
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, temp: 21 }),
    }),
  },
});

Client hook

The SDK’s useChat hook needs no change. It hits your /api/chat route; your route calls RunInfra:
"use client";
import { useChat } from "ai/react";

export function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();
  return (
    <form onSubmit={handleSubmit}>
      {messages.map(m => <div key={m.id}>{m.role}: {m.content}</div>)}
      <input value={input} onChange={handleInputChange} />
    </form>
  );
}

Next steps

Streaming cookbook

Streaming patterns from scratch.

Tool calling cookbook

Tool-loop patterns at the API level.

Structured output cookbook

JSON Schema responses.

OpenAI compatibility

The contract this integration rides on.