From 0a0ba67b6814cc833d29dee5488a12be8056ae49 Mon Sep 17 00:00:00 2001 From: jelveh Date: Tue, 4 Nov 2025 23:17:13 -0800 Subject: [PATCH] Update txt2img.md --- src/AI/txt2img.md | 84 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/src/AI/txt2img.md b/src/AI/txt2img.md index d0fc2b3..1d7bbf9 100755 --- a/src/AI/txt2img.md +++ b/src/AI/txt2img.md @@ -1,6 +1,6 @@ --- title: puter.ai.txt2img() -description: Generate images from text prompts using AI models like GPT Image, Nano Banana, and DALL-E 3. +description: Generate images from text prompts using GPT Image, DALL-E 2/3, Gemini Nano Banana, or Together AI models. --- Given a prompt, generate an image using AI. @@ -8,28 +8,57 @@ Given a prompt, generate an image using AI. ## Syntax ```js -puter.ai.txt2img(prompt, (testMode = false)) -puter.ai.txt2img(prompt, (options = {})) +puter.ai.txt2img(prompt, testModeOrOptions?) +puter.ai.txt2img({ prompt, ...options }) ``` ## Parameters #### `prompt` (String) (required) -A string containing the prompt you want to generate an image from. +A string containing the prompt you want to generate an image from. When passing a single options object, include a `prompt` property inside that object. #### `testMode` (Boolean) (Optional) -A boolean indicating whether you want to use the test API. Defaults to `false`. This is useful for testing your code without using up API credits. +A boolean indicating whether you want to use the test API. Defaults to `false`. You can also set `test_mode: true` inside the options object to get the same behaviour without using the positional flag. In test mode the service returns a sample image so you can test without spending credits. #### `options` (Object) (Optional) -An options object with the following properties: - -- `model` (String) (Optional) - The AI model to use for image generation, it can be `gpt-image-1`, `gpt-image-1-mini`, `gemini-2.5-flash-image-preview` (also known as Nano Banana), or `dall-e-3`. Defaults to `gpt-image-1-mini`. -- `quality` (String) (Optional) - The quality of the generated image. For `gpt-image-1` and `gpt-image-1-mini`, it can be `high`, `medium` or `low`. Defaults to `low`. There is no quality setting for `gemini-2.5-flash-image-preview`. For `dall-e-3`, it can be `hd` or `standard`. Defaults to `standard`. -- `input_image` (String) (Optional) (Only works with `gemini-2.5-flash-image-preview`) - Base64 encoded input image for image-to-image generation. -- `input_image_mime_type` (String) (Optional) (Only if `input_image` is set) - The MIME type of the input image. Could be `image/png`, `image/jpeg`, `image/jpg`, or `image/webp`. +An options object can include: + +##### General +- `model` (String) - Select the model. Defaults to `gpt-image-1-mini`. The alias `nano-banana` is automatically mapped to `gemini-2.5-flash-image-preview`. Models starting with Together AI prefixes (such as `black-forest-labs/`, `stabilityai/`, `togethercomputer/`, `playgroundai/`, `runwayml/`, `lightricks/`, `sg161222/`, `wavymulder/`, or `prompthero/`) or containing keywords like `flux`, `kling`, `sd3`, `stable-diffusion`, or `kolors` are routed to the Together AI driver. +- `provider` / `service` (String) - Force a provider without guessing from the model name. Accepted values include `openai`, `gemini`, and `together` (case-insensitive). +- `driver` (String) - Call a specific driver directly, bypassing provider detection. Valid values are `openai-image-generation`, `gemini-image-generation`, and `together-image-generation`. +- `test_mode` (Boolean) - Same as the positional `testMode` flag, but available inside the options object. + +##### OpenAI models (`gpt-image-1-mini`, `gpt-image-1`, `dall-e-2`, `dall-e-3`) +- `quality` (String) - For GPT Image models use `low`, `medium`, or `high` (default is `low`). For DALL·E 3 use `standard` (default) or `hd`. DALL·E 2 ignores quality. +- `ratio` (Object) - Request a preset aspect ratio such as `{ w: 1024, h: 1024 }` (square), `{ w: 1024, h: 1536 }` (portrait, GPT Image only), `{ w: 1536, h: 1024 }` (landscape, GPT Image only), `{ w: 1024, h: 1792 }` (portrait, DALL·E only), or `{ w: 1792, h: 1024 }` (landscape, DALL·E only). Invalid ratios are rejected with a `field_invalid` error. + +##### Gemini model (`gemini-2.5-flash-image-preview`, aka Nano Banana) +- `ratio` (Object) - Currently only `{ w: 1024, h: 1024 }` is supported. +- `input_image` (String) - Base64-encoded input image used for image-to-image generation. +- `input_image_mime_type` (String) - MIME type for `input_image`. Supported values: `image/png`, `image/jpeg`, `image/jpg`, `image/webp`. + +##### Together AI models +- `model` (String) - Together AI model identifier. Defaults to `black-forest-labs/FLUX.1-schnell` if you do not provide one. +- `width` / `height` (Number) - Explicit dimensions (rounded to the nearest multiple of 8, minimum 64). If omitted the ratio or Together defaults are used. +- `aspect_ratio` (String) - Alternative to width/height (e.g. `"16:9"`). +- `steps` (Number) - Diffusion steps (clamped to 1–50). +- `seed` (Number) - Random seed used for reproducibility. +- `negative_prompt` (String) - Text that should be avoided in the output. +- `n` (Number) - Number of images requested (1–4). Currently the client returns the first image produced. +- `image_url` / `image_base64` (String) - Reference image for image-to-image workflows. +- `mask_image_url` / `mask_image_base64` (String) - Mask to use for inpainting. +- `prompt_strength` (Number) - Float between 0 and 1 controlling how strongly the prompt influences image-to-image results. +- `disable_safety_checker` (Boolean) - Pass `true` to disable Together AI’s safety checker. +- `response_format` (String) - Forwarded to Together AI (e.g. `url`, `b64_json`). + +##### Available models +- **OpenAI** – `gpt-image-1-mini` (default), `gpt-image-1`, `dall-e-3`, `dall-e-2` +- **Gemini** – `gemini-2.5-flash-image-preview` (Nano Banana) +- **Together AI** – Any Together-hosted diffusion model whose name starts with prefixes like `black-forest-labs/`, `stabilityai/`, `togethercomputer/`, `playgroundai/`, `runwayml/`, `lightricks/`, `sg161222/`, `wavymulder/`, or `prompthero/`, or contains keywords such as `flux`, `kling`, `sd3`, `stable-diffusion`, or `kolors`. Common choices include `black-forest-labs/FLUX.1-schnell` (default), `stabilityai/stable-diffusion-3-medium`, and `playgroundai/playground-v2.5`. ## Return value @@ -53,17 +82,40 @@ A `Promise` that resolves to an `HTMLImageElement`. The element’s `src` points ``` -Generate an image with specific model and quality +Call Together AI's FLUX model with custom settings + +```html;ai-txt2img-together + + + + + + +``` + +Generate an image with specific model and aspect ratio ```html;ai-txt2img-options