Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/openai-gpt-image-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@tanstack/ai-openai': minor
---

Add `gpt-image-2` to the OpenAI image model list. The new model is exposed
through the same tree-shakeable `openaiImage` adapter as `gpt-image-1` and
shares its provider options (`quality`, `background`, `output_format`,
`output_compression`, `moderation`, `partial_images`) and size set
(`1024x1024`, `1536x1024`, `1024x1536`, `auto`).

```ts
import { openaiImage } from '@tanstack/ai-openai/adapters'
import { generate } from '@tanstack/ai'

const adapter = openaiImage({ apiKey: process.env.OPENAI_API_KEY! })

const result = await generate({
adapter,
model: 'gpt-image-2',
prompt: 'A watercolor fox in a snowy forest',
})
```
5 changes: 5 additions & 0 deletions .changeset/openrouter-web-fetch-tool-capability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/ai-openrouter': patch
---

Restore `web_fetch` in `OpenRouterChatModelToolCapabilitiesByName` so `webFetchTool()` is assignable to OpenRouter text adapters again. The recent model-metadata sync (#623) regenerated this map with `web_search` only, breaking the per-model type-safety tests added in #611.
6 changes: 4 additions & 2 deletions docs/media/image-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ All image adapters support these common options:

| Model | Supported Sizes |
|-------|----------------|
| `gpt-image-2` | `1024x1024`, `1536x1024`, `1024x1536`, `auto` |
Comment thread
coderabbitai[bot] marked this conversation as resolved.
| `gpt-image-1` | `1024x1024`, `1536x1024`, `1024x1536`, `auto` |
| `gpt-image-1-mini` | `1024x1024`, `1536x1024`, `1024x1536`, `auto` |
| `dall-e-3` | `1024x1024`, `1792x1024`, `1024x1792` |
Expand Down Expand Up @@ -138,11 +139,11 @@ const result = await generateImage({

OpenAI models support model-specific Model Options:

#### GPT-Image-1 / GPT-Image-1-Mini
#### GPT-Image-2 / GPT-Image-1 / GPT-Image-1-Mini

```typescript
const result = await generateImage({
adapter: openaiImage('gpt-image-1'),
adapter: openaiImage('gpt-image-2'),
prompt: 'A cat wearing a hat',
modelOptions: {
quality: 'high', // 'high' | 'medium' | 'low' | 'auto'
Expand Down Expand Up @@ -223,6 +224,7 @@ interface GeneratedImage {

| Model | Images per Request |
|-------|-------------------|
| `gpt-image-2` | 1-10 |
| `gpt-image-1` | 1-10 |
| `gpt-image-1-mini` | 1-10 |
| `dall-e-3` | 1 |
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/ai-openai/src/adapters/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface OpenAIImageConfig extends OpenAIClientConfig {}
* OpenAI Image Generation Adapter
*
* Tree-shakeable adapter for OpenAI image generation functionality.
* Supports gpt-image-1, gpt-image-1-mini, dall-e-3, and dall-e-2 models.
* Supports gpt-image-2, gpt-image-1, gpt-image-1-mini, dall-e-3, and dall-e-2 models.
*
* Features:
* - Model-specific type-safe provider options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export type OpenAIImageProviderOptions =
* Used by the core AI types to narrow providerOptions based on the selected model.
*/
export type OpenAIImageModelProviderOptionsByName = {
'gpt-image-2': GptImage1ProviderOptions
'gpt-image-1': GptImage1ProviderOptions
'gpt-image-1-mini': GptImage1MiniProviderOptions
'dall-e-3': DallE3ProviderOptions
Expand All @@ -191,6 +192,7 @@ export type OpenAIImageModelProviderOptionsByName = {
* Type-only map from model name to its supported sizes.
*/
export type OpenAIImageModelSizeByName = {
'gpt-image-2': GptImageSize
'gpt-image-1': GptImageSize
'gpt-image-1-mini': GptImageSize
'dall-e-3': DallE3Size
Expand All @@ -217,6 +219,7 @@ export function validateImageSize(
if (!size || size === 'auto') return

const validSizes: Record<string, Array<string>> = {
'gpt-image-2': ['1024x1024', '1536x1024', '1024x1536', 'auto'],
'gpt-image-1': ['1024x1024', '1536x1024', '1024x1536', 'auto'],
'gpt-image-1-mini': ['1024x1024', '1536x1024', '1024x1536', 'auto'],
'dall-e-3': ['1024x1024', '1792x1024', '1024x1792'],
Expand Down Expand Up @@ -263,7 +266,7 @@ export function validateNumberOfImages(

export const validateBackground = (options: ImageValidationOptions) => {
if (options.background) {
const supportedModels = ['gpt-image-1', 'gpt-image-1-mini']
const supportedModels = ['gpt-image-2', 'gpt-image-1', 'gpt-image-1-mini']
if (!supportedModels.includes(options.model)) {
throw new Error(
`The model ${options.model} does not support background option.`,
Expand All @@ -277,11 +280,13 @@ export const validatePrompt = (options: ImageValidationOptions) => {
throw new Error('Prompt cannot be empty.')
}
if (
(options.model === 'gpt-image-1' || options.model === 'gpt-image-1-mini') &&
(options.model === 'gpt-image-2' ||
options.model === 'gpt-image-1' ||
options.model === 'gpt-image-1-mini') &&
options.prompt.length > 32000
) {
throw new Error(
'For gpt-image-1/gpt-image-1-mini, prompt length must be less than or equal to 32000 characters.',
'For gpt-image-2/gpt-image-1/gpt-image-1-mini, prompt length must be less than or equal to 32000 characters.',
)
}
if (options.model === 'dall-e-2' && options.prompt.length > 1000) {
Expand Down
23 changes: 23 additions & 0 deletions packages/typescript/ai-openai/src/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,28 @@ const GPT_IMAGE_1_MINI = {
OpenAIBaseOptions & OpenAIStreamingOptions & OpenAIMetadataOptions
>

const GPT_IMAGE_2 = {
name: 'gpt-image-2',
knowledge_cutoff: '2026-04-21',
pricing: {
input: {
normal: 5,
cached: 1.25,
},
output: {
normal: 30,
},
},
supports: {
input: ['text', 'image'],
output: ['image'],
endpoints: ['image-generation', 'image-edit'],
features: [],
},
} as const satisfies ModelMeta<
OpenAIBaseOptions & OpenAIStreamingOptions & OpenAIMetadataOptions
>

const O3_DEEP_RESEARCH = {
name: 'o3-deep-research',
context_window: 200_000,
Expand Down Expand Up @@ -2217,6 +2239,7 @@ export type OpenAIChatModel = (typeof OPENAI_CHAT_MODELS)[number]

// Image generation models (based on endpoints: "image-generation" or "image-edit")
export const OPENAI_IMAGE_MODELS = [
GPT_IMAGE_2.name,
GPT_IMAGE_1.name,
GPT_IMAGE_1_MINI.name,
DALL_E_3.name,
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript/ai-openrouter/src/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16379,7 +16379,10 @@ export const OPENROUTER_CHAT_MODELS = [
] as const

export type OpenRouterChatModelToolCapabilitiesByName = {
[K in (typeof OPENROUTER_CHAT_MODELS)[number]]: readonly ['web_search']
[K in (typeof OPENROUTER_CHAT_MODELS)[number]]: readonly [
'web_search',
'web_fetch',
]
}

export const OPENROUTER_IMAGE_MODELS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function ImageGenerator() {
### 1. Image Generation

Supported adapters: `openaiImage` (dall-e-2, dall-e-3, gpt-image-1,
gpt-image-1-mini) and `geminiImage` (gemini-3.1-flash-image-preview,
gpt-image-1-mini, gpt-image-2) and `geminiImage` (gemini-3.1-flash-image-preview,
imagen-4.0-generate-001, etc.).

```typescript
Expand Down
Loading