本页还没有译文
本页 39 段还没译成Español,下面显示的是英文原文。Prodia
还没翻译译自英文(ai-sdk.dev)本页 39 段都还没译
Prodia is a fast inference platform for generative AI, offering high-speed image generation with FLUX and Stable Diffusion models.
You can use Prodia models through AI Gateway (recommended) or connect directly with @ai-sdk/prodia.
import { generateImage } from 'ai';
const { image } = await generateImage({
model: 'openai/gpt-image-2.5-sunburst',
prompt: 'A sunlit mountain village in watercolor.',
});
console.log(image.base64);Using AI Gateway
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install ai:
pnpmnpmyarnbun
pnpm add ainpm install aiyarn add aibun add aiSet an AI Gateway API key in your environment:
export AI_GATEWAY_API_KEY=your_api_key_hereVercel deployments can also use OIDC authentication. See the AI Gateway provider documentation for configuration and the model catalog for available models.
Gateway feature and provider-option support depends on the model and the provider serving the request. See Gateway provider options.
Using @ai-sdk/prodia
For direct access to Prodia, install ai and @ai-sdk/prodia:
pnpmnpmyarnbun
pnpm add ai @ai-sdk/prodianpm install ai @ai-sdk/prodiayarn add ai @ai-sdk/prodiabun add ai @ai-sdk/prodiaSet your Prodia API credential in the PRODIA_TOKEN environment variable:
export PRODIA_TOKEN=your_api_key_hereAI Gateway does not expose every API in @ai-sdk/prodia. Use the direct provider for provider-specific APIs or custom connection settings.
Note
The following sections document the direct @ai-sdk/prodia provider,
including its model factories and settings. Gateway model and feature
availability can differ.
Provider Instance
You can import the default provider instance prodia from @ai-sdk/prodia:
import { prodia } from '@ai-sdk/prodia';If you need a customized setup, you can import createProdia and create a provider instance with your settings:
import { createProdia } from '@ai-sdk/prodia';
const prodia = createProdia({
apiKey: 'your-api-key', // optional, defaults to PRODIA_TOKEN environment variable
baseURL: 'custom-url', // optional
headers: {
/* custom headers */
}, // optional
});You can use the following optional settings to customize the Prodia provider instance:
-
baseURL string
Use a different URL prefix for API calls. The default prefix is
https://inference.prodia.com/v2. -
apiKey string
API key that is being sent using the
Authorizationheader as a Bearer token. It defaults to thePRODIA_TOKENenvironment variable. -
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing.
Image Models
You can create Prodia image models using the .image() factory method.
For more on image generation with the AI SDK see generateImage().
Basic Usage
import { writeFileSync } from 'node:fs';
import { prodia } from '@ai-sdk/prodia';
import { generateImage } from 'ai';
const { image } = await generateImage({
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
prompt: 'A cat wearing an intricate robe',
});
const filename = `image-${Date.now()}.png`;
writeFileSync(filename, image.uint8Array);
console.log(`Image saved to ${filename}`);Model Capabilities
Prodia offers fast inference for various image generation models. Here are the supported model types:
| Model | Description |
|---|---|
inference.flux-fast.schnell.txt2img.v2 | Fast FLUX Schnell model for text-to-image generation |
inference.flux.schnell.txt2img.v2 | FLUX Schnell model for text-to-image generation |
Note
Prodia supports additional model IDs. Check the Prodia documentation for the full list of available models.
Image Size
You can specify the image size using the size parameter in WIDTHxHEIGHT format:
import { prodia } from '@ai-sdk/prodia';
import { generateImage } from 'ai';
const { image } = await generateImage({
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
prompt: 'A serene mountain landscape at sunset',
size: '1024x768',
});Provider Options
Prodia image models support additional options through the providerOptions.prodia object:
import { prodia, type ProdiaImageModelOptions } from '@ai-sdk/prodia';
import { generateImage } from 'ai';
const { image } = await generateImage({
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
prompt: 'A cat wearing an intricate robe',
providerOptions: {
prodia: {
width: 1024,
height: 768,
steps: 4,
stylePreset: 'cinematic',
} satisfies ProdiaImageModelOptions,
},
});The following provider options are supported:
- width number - Output width in pixels (256–1920). When set, this overrides any width derived from
size. - height number - Output height in pixels (256–1920). When set, this overrides any height derived from
size. - steps number - Number of computational iterations (1–4). More steps typically produce higher quality results.
- stylePreset string - Apply a visual theme to the output image. Supported presets:
3d-model,analog-film,anime,cinematic,comic-book,digital-art,enhance,fantasy-art,isometric,line-art,low-poly,neon-punk,origami,photographic,pixel-art,texture,craft-clay. - loras string[] - Augment the output with up to 3 LoRA models.
- progressive boolean - When using JPEG output, return a progressive JPEG.
Seed
You can use the seed parameter to get reproducible results:
import { prodia } from '@ai-sdk/prodia';
import { generateImage } from 'ai';
const { image } = await generateImage({
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
prompt: 'A serene mountain landscape at sunset',
seed: 12345,
});Provider Metadata
The generateImage response includes provider-specific metadata in providerMetadata.prodia.images[]. Each image object may contain the following properties:
- jobId string - The unique identifier for the generation job.
- seed number - The seed used for generation. Useful for reproducing results.
- elapsed number - Generation time in seconds.
- iterationsPerSecond number - Processing speed metric.
- createdAt string - Timestamp when the job was created.
- updatedAt string - Timestamp when the job was last updated.
import { prodia } from '@ai-sdk/prodia';
import { generateImage } from 'ai';
const { image, providerMetadata } = await generateImage({
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
prompt: 'A serene mountain landscape at sunset',
});
// Access provider metadata
const metadata = providerMetadata?.prodia?.images?.[0];
console.log('Job ID:', metadata?.jobId);
console.log('Seed:', metadata?.seed);
console.log('Elapsed:', metadata?.elapsed);