Quick start
This example usesstabilityai/sdxl-turbo:
images[0] is a data: URI containing the encoded image, not an HTTP link — fetch() accepts it directly, as above.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Generate images with Stable Diffusion and SDXL on DeepInfra.
stabilityai/sdxl-turbo:
import { TextToImage } from "deepinfra";
import { createWriteStream } from "fs";
import { Readable } from "stream";
const DEEPINFRA_API_KEY = process.env.DEEPINFRA_API_KEY;
const model = new TextToImage("stabilityai/sdxl-turbo", DEEPINFRA_API_KEY);
const response = await model.generate({
prompt: "a burger with a funny hat on the beach",
});
const result = await fetch(response.images[0]);
if (result.ok && result.body) {
Readable.fromWeb(result.body).pipe(createWriteStream("image.jpg"));
}
curl "https://api.deepinfra.com/v1/inference/stabilityai/sdxl-turbo" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPINFRA_API_KEY" \
-d '{"prompt": "a burger with a funny hat on the beach"}'
images[0] is a data: URI containing the encoded image, not an HTTP link — fetch() accepts it directly, as above.