npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mynthio/tanstack-ai-adapter

v0.0.3

Published

Mynth image generation adapter for TanStack AI

Readme

@mynthio/tanstack-ai-adapter

npm version license: MIT

TanStack AI image generation adapter for Mynth.

It lets you use Mynth models with generateImage() while keeping TanStack AI's adapter pattern, normalized result shape, and full-stack streaming workflows.

Features

  • mynthImage(model, config?) for the common one-off case
  • createMynthImage(config?) for reusable provider configuration
  • Typed MYNTH_IMAGE_MODELS and MynthImageModel exports for model pickers and guards
  • Support for both TanStack image options and Mynth-specific provider options
  • Normalized image results, including revisedPrompt when Mynth enhances the prompt

Installation

# Bun
bun add @mynthio/tanstack-ai-adapter @tanstack/ai

# pnpm
pnpm add @mynthio/tanstack-ai-adapter @tanstack/ai

# npm
npm install @mynthio/tanstack-ai-adapter @tanstack/ai

# yarn
yarn add @mynthio/tanstack-ai-adapter @tanstack/ai

Authentication

Set your Mynth API key:

MYNTH_API_KEY=mak_...

You can also pass apiKey directly when creating the adapter. baseUrl is optional and useful for proxies, tests, or custom deployments.

Quick Start

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",
  numberOfImages: 1,
  size: "1024x1024",
});

console.log(result.id);
console.log(result.model);
console.log(result.images[0]?.url);

The adapter is model-bound, so you choose the Mynth model when you create it.

Reusable Provider

Use createMynthImage() when you want to share config across multiple 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",
});

console.log(result.images[0]?.url);

Per-call config overrides shared config:

const adapter = mynth("auto", {
  baseUrl: "https://proxy.example.com",
});

Mynth Provider Options

Use TanStack's top-level fields for common options like prompt, numberOfImages, and shorthand size. Use modelOptions for Mynth-specific request fields:

import { generateImage } from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";

const result = await generateImage({
  adapter: mynthImage("recraft/recraft-v4"),
  prompt: "Ignored when promptStructured is provided",
  numberOfImages: 2,
  size: "1024x1024",
  modelOptions: {
    promptStructured: {
      positive: "Modern poster design for a jazz festival",
      negative: "watermark, blurry text",
      enhance: "prefer_magic",
    },
    size: {
      type: "aspect_ratio",
      aspectRatio: "4:5",
      scale: "2k",
    },
    output: {
      format: "png",
      quality: 90,
    },
    inputs: ["https://example.com/reference-image.jpg"],
    webhook: {
      enabled: true,
    },
    contentRating: {
      enabled: true,
    },
    metadata: {
      requestId: "req_123",
    },
  },
});

Notes:

  • modelOptions.promptStructured overrides the plain prompt
  • modelOptions.size overrides the top-level size
  • Top-level size is for shorthand values such as "auto", preset strings, and "1024x1024"
  • Use modelOptions.size when you need structured Mynth size objects

Available Models

The package exports both a runtime array and a type union for Mynth 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);
}

This is especially useful for building selectors, validating incoming model IDs, or keeping server and client code in sync.

Full-Stack Streaming Example

This adapter works well with TanStack AI's streaming image flow. The example app in this repo uses a server route that streams generateImage() over SSE:

import { generateImage, toServerSentEventsResponse } from "@tanstack/ai";
import { mynthImage } from "@mynthio/tanstack-ai-adapter";

export async function POST(request: Request) {
  const { prompt, model } = await request.json();

  const stream = generateImage({
    adapter: mynthImage(model ?? "auto"),
    prompt,
    numberOfImages: 1,
    stream: true,
  });

  return toServerSentEventsResponse(stream);
}

For a working app with model selection and useGenerateImage(), see tanstack-start-ai-mynth-adapter.

Result Shape

The adapter returns TanStack AI's normalized image result:

  • id: the Mynth task id
  • model: the resolved model returned by Mynth, or the requested model as a fallback
  • images: only successful images are included
  • images[*].revisedPrompt: included when Mynth returns an enhanced prompt

API

mynthImage(model, config?)

Creates a Mynth image adapter directly.

  • model: a MynthImageModel
  • config.apiKey?: optional override for MYNTH_API_KEY
  • config.baseUrl?: optional base URL override

createMynthImage(config?)

Creates a reusable provider factory that returns model-bound adapters.

MYNTH_IMAGE_MODELS

Readonly array of supported Mynth image model IDs.

MynthImageModel

Type union of all supported model IDs.

Development

From public/oss:

bun install
bun run build
bun run test
bun run typecheck

Package-local commands also work from this directory:

bun run build
bun run test
bun run typecheck

Contributing

Contributions are welcome. See ../../CONTRIBUTING.md.

License

MIT