AI & agents
Add AI to a make.omg.dev app with the built-in AI router. No API key, no secrets, no setup.
Every app you build on make.omg.dev can call AI models
through the built-in omg.dev AI router. You do not need an API key, a
baseURL, environment variables or secrets. The platform signs each call for
your app, and the router picks the model and bills it.
The AI code runs on the server side of your app. Your page calls it through
an /api/... route.
This works the same in the builder preview and in your published app. You write the code once.
Example: a chat page
Two files give you a streaming chat.
The server function goes in functions/chat.ts. Each file in functions/ is
mounted at /api/<name>, so this one answers POST /api/chat:
import { streamText, convertToModelMessages, anthropic, type UIMessage } from "@omg-dev/ai"
import { ctx } from "@omg-dev/server"
export async function POST(req: Request) {
// Optional: only signed-in visitors can spend your AI credit.
if (!ctx.userId) return new Response("Sign in to chat", { status: 401 })
const { messages }: { messages: UIMessage[] } = await req.json()
const result = streamText({
model: anthropic("omg/auto"),
system: "You are a friendly study helper. Keep answers short.",
messages: await convertToModelMessages(messages),
})
return result.toUIMessageStreamResponse()
}The page uses useChat from @omg-dev/ai/react. It sends to /api/chat by
default:
import { useState } from "react"
import { useChat } from "@omg-dev/ai/react"
export function Chat() {
const { messages, sendMessage, status } = useChat()
const [input, setInput] = useState("")
const busy = status === "submitted" || status === "streaming"
return (
<div className="flex flex-col gap-3 p-4">
{messages.map((m) => (
<p key={m.id}>
<b>{m.role === "user" ? "You" : "AI"}:</b>{" "}
{m.parts.map((p, i) => (p.type === "text" ? <span key={i}>{p.text}</span> : null))}
</p>
))}
<form
onSubmit={(e) => {
e.preventDefault()
if (!input.trim() || busy) return
sendMessage({ text: input })
setInput("")
}}
>
<input value={input} onChange={(e) => setInput(e.target.value)} placeholder="Ask something" />
<button disabled={busy}>Send</button>
</form>
</div>
)
}Things to keep:
- Wrap the browser messages with
await convertToModelMessages(messages).useChatsends UI messages, andstreamTextneeds model messages. - Return
result.toUIMessageStreamResponse().useChatreads that stream format. - Keep the name
functions/chat.ts.useChatsends to/api/chatunless you give it a different transport.
Where each import goes
| Code | Import from | Why |
|---|---|---|
Server: files in functions/ | @omg-dev/ai | Providers that go through the AI router. This entry is server-only. |
| Browser: pages and components | @omg-dev/ai/react | useChat, useCompletion, useObject. Safe to bundle for the browser. |
Do not import @omg-dev/ai in a page or component. It uses
node:async_hooks and does not bundle for the browser.
From @omg-dev/ai you get:
- The providers
anthropicandopenai, already pointed at the AI router. - The AI SDK helpers
streamText,generateText,streamObject,generateObject,tool,stepCountIsandconvertToModelMessages. - The types
ModelMessage,UIMessageandTool.
Do not use @ai-sdk/anthropic or @ai-sdk/openai directly, and do not set
apiKey or baseURL. Only the providers from @omg-dev/ai go through the
AI router.
Choosing a model
Use an omg.dev model tier as the model id. The tier picks the model behind it, so your app keeps working when omg.dev moves a tier to a newer model.
| Model id | Use it for |
|---|---|
omg/auto | The default. The cheapest tier, good for chat, summaries and short answers. |
omg/balanced | Harder questions and longer reasoning. It costs more per call. |
Both tiers work with both providers:
anthropic("omg/auto") // Anthropic message format
openai("omg/balanced") // OpenAI formatThe provider only selects the request format. The tier selects the model.
Use anthropic(...) unless you have a reason to prefer the OpenAI format.
Who pays
AI calls from your app use your AI credit as the app owner. This is the same balance that you use to build on make.omg.dev. Your visitors do not pay and do not need an account with omg.dev to make the call.
- AI in apps needs a paid plan. The free signup credit is for building only. On the free plan, an AI call from your app answers with an error.
- Calls from the builder preview also use your credit. The preview has a daily limit on AI calls.
- A public app lets any visitor spend your credit. If that matters, allow AI
only for signed-in visitors. Check
ctx.userIdfrom@omg-dev/server, as the example above does. - Each published app has a daily AI spending limit, and so do all apps of one owner together. The limit protects you from a runaway loop or a flood of visitors. It resets at 00:00 UTC.
- When your credit runs out, AI calls from your app stop with the message "This app's AI is paused: its owner is out of AI credit." Add credit to start them again.
Tag calls with the visitor (optional)
runWithEndUser(userId, fn) adds the visitor id to every AI call made inside
fn. The id is saved with the usage record for that call. It does not change
who pays. omg.dev does not show a per-visitor breakdown of AI usage yet.
import { streamText, convertToModelMessages, anthropic, runWithEndUser } from "@omg-dev/ai"
import { ctx } from "@omg-dev/server"
export async function POST(req: Request) {
const { messages } = await req.json()
return runWithEndUser(ctx.userId, async () => {
const result = streamText({ model: anthropic("omg/auto"), messages: await convertToModelMessages(messages) })
return result.toUIMessageStreamResponse()
})
}Tools and multi-step agents
The standard AI SDK shape works: tool({ description, inputSchema, execute })
and stopWhen: stepCountIs(n).
import { generateText, anthropic, tool, stepCountIs } from "@omg-dev/ai"
import { z } from "zod"
export async function POST(req: Request) {
const { question } = await req.json()
const result = await generateText({
model: anthropic("omg/auto"),
stopWhen: stepCountIs(5),
tools: {
getWeather: tool({
description: "Get the weather for a city",
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, temperatureC: 22 }),
}),
},
prompt: question,
})
return { answer: result.text }
}Each step is a separate AI call and uses credit.
Images, video and audio
To make images, video or speech from your app, use
@omg-dev/media. It goes through the same router and
bills the same way.