Images
This section covers endpoints to create images, edit images with a mask, and generate variations, following the same patterns as OpenAI’s Images API.
Create image
Section titled “Create image”POST https://api.aifoundryhub.com/v1/images/generations
Generates one or more images from a text prompt.
Example request
Section titled “Example request”curl -X POST "https://api.aifoundryhub.com/v1/images/generations" \ -H "Authorization: Bearer $AI_FOUNDRY_HUB_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "flux.1-pro", "prompt": "A cozy reading nook with warm morning light, cinematic, high detail", "size": "1024x1024", "n": 1 }'import fs from "node:fs";import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.AI_FOUNDRY_HUB_API_KEY, baseURL: "https://api.aifoundryhub.com/v1",});
// Option A: URL responseconst urlResp = await client.images.generate({ model: "flux.1-pro", prompt: "A cozy reading nook with warm morning light, cinematic, high detail", size: "1024x1024", n: 1,});console.log(urlResp.data[0].url);
// Option B: Base64 response → save to fileconst b64Resp = await client.images.generate({ model: "flux.1-pro", prompt: "A cozy reading nook with warm morning light, cinematic, high detail", size: "1024x1024", n: 1});const b64 = b64Resp.data[0].b64_json;await fs.promises.writeFile("image.png", Buffer.from(b64, "base64"));package main
import ( "context" "fmt" "os"
openai "github.com/openai/openai-go" "github.com/openai/openai-go/option")
func main() { client := openai.NewClient( option.WithAPIKey(os.Getenv("AI_FOUNDRY_HUB_API_KEY")), option.WithBaseURL("https://api.aifoundryhub.com/v1"), )
params := openai.ImageGenerateParams{ Model: "flux.1-pro", Prompt: "A cozy reading nook with warm morning light, cinematic, high detail", Size: "1024x1024", N: openai.Int(1), }
ctx := context.Background() resp, err := client.Images.Generate(ctx, params) if err != nil { panic(err) }
fmt.Println(resp.Data[0].URL)}import os, base64from openai import OpenAI
client = OpenAI( api_key=os.getenv("AI_FOUNDRY_HUB_API_KEY"), base_url="https://api.aifoundryhub.com/v1",)
resp = client.images.generate( model="flux.1-pro", prompt="A cozy reading nook with warm morning light, cinematic, high detail", size="1024x1024", n=1, response_format="b64_json",)
with open("image.png", "wb") as f: f.write(base64.b64decode(resp.data[0].b64_json))Returns
Section titled “Returns”An images response object with one entry per generated image.
Example response (URL)
Section titled “Example response (URL)”{ "created": 1714569952, "data": [ { "url": "https://cdn.example.com/ai/abc123.png" } ]}Example response (Base64)
Section titled “Example response (Base64)”{ "created": 1714569952, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." } ]}Create image edit
Section titled “Create image edit”POST https://api.aifoundryhub.com/v1/images/edits
Edits an existing image based on a mask, infilling the masked regions according to the prompt.
Example request
Section titled “Example request”curl -X POST "https://api.aifoundryhub.com/v1/images/edits" \ -H "Authorization: Bearer $AI_FOUNDRY_HUB_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F model=flux.1-pro \ -F image=@/path/to/original.png \ -F mask=@/path/to/mask.png \ -F prompt='Add a steaming cup of coffee on the table' \ -F size=1024x1024import fs from "node:fs";import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.AI_FOUNDRY_HUB_API_KEY, baseURL: "https://api.aifoundryhub.com/v1",});
const edit = await client.images.edits.create({ model: "flux.1-pro", image: fs.createReadStream("original.png"), mask: fs.createReadStream("mask.png"), prompt: "Add a steaming cup of coffee on the table", size: "1024x1024"});console.log(edit.data[0].url);package main
import ( "context" "fmt" "os"
openai "github.com/openai/openai-go" "github.com/openai/openai-go/option")
func main() { client := openai.NewClient( option.WithAPIKey(os.Getenv("AI_FOUNDRY_HUB_API_KEY")), option.WithBaseURL("https://api.aifoundryhub.com/v1"), )
img, _ := os.Open("original.png") defer img.Close() m, _ := os.Open("mask.png") defer m.Close()
params := openai.ImageEditParams{ Model: "flux.1-pro", Image: openai.ImageEditParamsImageUnion{ OfFile: img, }, Mask: m, Prompt: "Add a steaming cup of coffee on the table", Size: "1024x1024", }
ctx := context.Background() resp, err := client.Images.Edit(ctx, params) if err != nil { panic(err) } fmt.Println(resp.Data[0].URL)}import osfrom openai import OpenAI
client = OpenAI( api_key=os.getenv("AI_FOUNDRY_HUB_API_KEY"), base_url="https://api.aifoundryhub.com/v1",)
resp = client.images.edits.create( model="flux.1-pro", image=open("original.png", "rb"), mask=open("mask.png", "rb"), prompt="Add a steaming cup of coffee on the table", size="1024x1024",)print(resp.data[0].url)Returns
Section titled “Returns”An images response object with one entry per edited image.
Create image variation
Section titled “Create image variation”POST https://api.aifoundryhub.com/v1/images/variations
Generates one or more new images based on the style and content of an input image.
Example request
Section titled “Example request”curl -X POST "https://api.aifoundryhub.com/v1/images/variations" \ -H "Authorization: Bearer $AI_FOUNDRY_HUB_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F model=flux.1-pro \ -F image=@/path/to/source.png \ -F n=2 \ -F size=512x512import fs from "node:fs";import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.AI_FOUNDRY_HUB_API_KEY, baseURL: "https://api.aifoundryhub.com/v1",});
const result = await client.images.variations.create({ model: "flux.1-pro", image: fs.createReadStream("source.png"), n: 2, size: "512x512"});console.log(result.data.map(x => x.url));package main
import ( "context" "fmt" "os"
openai "github.com/openai/openai-go" "github.com/openai/openai-go/option")
func main() { client := openai.NewClient( option.WithAPIKey(os.Getenv("AI_FOUNDRY_HUB_API_KEY")), option.WithBaseURL("https://api.aifoundryhub.com/v1"), )
img, _ := os.Open("source.png") defer img.Close()
params := openai.ImageNewVariationParams{ Model: "flux.1-pro", Image: img, N: openai.Int(2), Size: "512x512", }
ctx := context.Background() resp, err := client.Images.NewVariation(ctx, params) if err != nil { panic(err) } for _, d := range resp.Data { fmt.Println(d.URL) }}from openai import OpenAIimport os
client = OpenAI( api_key=os.getenv("AI_FOUNDRY_HUB_API_KEY"), base_url="https://api.aifoundryhub.com/v1",)
resp = client.images.variations.create( model="flux.1-pro", image=open("source.png", "rb"), n=2, size="512x512",)print([d.url for d in resp.data])Returns
Section titled “Returns”An images response object with one entry per variation.