The Mynth community adapter calls Flux, Recraft, Gemini, Qwen, Seedream, Wan, and Grok Imagine from generateImage(). Mynth maintains it.
Note
Mynth is in public beta. The model list and some request options can still change. The adapter follows the Mynth SDK closely, and Mynth welcomes feedback on the API.
npm i @mynthio/tanstack-ai-adapter @tanstack/aipnpm add @mynthio/tanstack-ai-adapter @tanstack/aiyarn add @mynthio/tanstack-ai-adapter @tanstack/aibun add @mynthio/tanstack-ai-adapter @tanstack/aiThe adapter needs @tanstack/ai 0.34 or later.
Make a key in the Mynth API keys dashboard. Then put it in the environment of your server:
MYNTH_API_KEY=mak_...Warning
Keep MYNTH_API_KEY on the server. Do not put it in browser code or in public client environment variables. It can then end up in a client bundle.
import { generateImage } from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";
const result = await generateImage({
adapter: mynthImage("black-forest-labs/flux.2-dev"),
prompt: "Editorial product photo of a ceramic mug on a linen tablecloth",
threadId: "thread-1",
numberOfImages: 1,
size: "square",
});
console.log(result.id);
console.log(result.model);
console.log(result.images[0]?.url);You get a URL to the image in result.images[0]?.url. You pick the Mynth model when you create the adapter.
Return the generation from a route with stream: true:
import {
generateImage,
generationParamsFromRequest,
toServerSentEventsResponse,
} from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";
export async function POST(request: Request) {
const { input, threadId, runId } = await generationParamsFromRequest(
"image",
request,
);
const stream = generateImage({
adapter: mynthImage("auto"),
prompt: input.prompt,
threadId,
runId,
numberOfImages: 1,
stream: true,
});
return toServerSentEventsResponse(stream);
}On the client, use useGenerateImage(). For a full app, see the TanStack Start + Mynth adapter demo.
Models that take image input work with content-part prompts. Mix the instruction text with reference images, for restyles, edits, reference-guided images, and try-on:
import { generateImage } from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";
const result = await generateImage({
adapter: mynthImage("black-forest-labs/flux.2-dev"),
prompt: [
{ type: "text", content: "Restyle this scene as a watercolor painting" },
{
type: "image",
source: { type: "url", value: "https://example.com/photo.jpg" },
},
],
threadId: "thread-1",
});The adapter maps the image parts to Mynth inputs:
Use createMynthImage() to share settings across adapters:
import { generateImage } from "@tanstack/ai";
import { createMynthImage } from "@mynthio/tanstack-ai-adapter";
const mynth = createMynthImage({
apiKey: process.env.MYNTH_API_KEY!,
baseUrl: "https://api.mynth.io",
});
const result = await generateImage({
adapter: mynth("google/gemini-3.1-flash-image"),
prompt: "A playful paper-cut illustration of a city park in spring",
threadId: "thread-1",
});
console.log(result.images[0]?.url);You can still change the settings for one adapter:
import { createMynthImage } from "@mynthio/tanstack-ai-adapter";
const mynth = createMynthImage();
const adapter = mynth("auto", {
baseUrl: "https://proxy.example.com",
});The adapter exports a runtime list and a type of the image models:
import { MYNTH_IMAGE_MODELS, type MynthImageModel } from "@mynthio/tanstack-ai-adapter";
const defaultModel: MynthImageModel = "auto";
for (const model of MYNTH_IMAGE_MODELS) {
console.log(model);
}The exported list is a fixed snapshot, for type safety. For the live catalog with prices, use the models endpoint.
Top-level fields hold the common options: prompt, numberOfImages, and the short size. Put the Mynth options in modelOptions:
import { generateImage } from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";
const result = await generateImage({
adapter: mynthImage("recraft/recraft-v4"),
prompt: "Modern poster design for a jazz festival",
threadId: "thread-1",
numberOfImages: 2,
size: "portrait",
modelOptions: {
negativePrompt: "watermark, blurry text",
magicPrompt: true,
size: {
type: "aspect_ratio",
aspectRatio: "4:5",
scale: "4k",
},
output: {
format: "png",
quality: 90,
},
rating: true,
metadata: {
requestId: "req_123",
},
},
});The adapter returns the normalized image result of TanStack AI:
| Export | What it is |
|---|---|
| mynthImage(model, config?) | Creates an image adapter. config.apiKey overrides MYNTH_API_KEY. config.baseUrl overrides the base URL. config.destination sets a default destination. |
| createMynthImage(config?) | Creates a factory that returns adapters for a model. |
| MYNTH_IMAGE_MODELS | A readonly array of the image model ids. |
| MynthImageModel | The type of the image model ids. |
| MYNTH_IMAGE_INPUT_MODELS | A readonly array of the model ids that take image input (image to image, try-on). |
| MynthImageInputModel | The type of the model ids that take image input. |
This package has only an image adapter for generateImage(). It has no chat or text adapter.
Mynth has a public catalog at https://api.mynth.io/models. It needs no API key, and it has the prices. Use it for a model picker with live prices:
const response = await fetch("https://api.mynth.io/models");
const { data } = await response.json();
for (const model of data) {
console.log(model.id, model.displayName, model.pricing);
}Each entry looks about like this:
{
"id": "black-forest-labs/flux.2-dev",
"displayName": "FLUX.2 Dev",
"pricing": {
"perImage": { "base": "0.01", "4k": "0.04" },
"perInput": "0.002",
},
}With the Mynth SDK, new Mynth().models.list() gives the same data. See the Mynth SDK README and Mynth.