Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cfe265d
feat(py/openai): refresh the OpenAI model catalog
cabljac Nov 13, 2026
3860d94
fix(py/openai): judge fine-tune ids by their base model, not their us…
cabljac Nov 16, 2026
a1a4040
refactor(py/openai): drop the redundant chatgpt-image match, which gp…
cabljac Nov 16, 2026
20cef9f
fix(py/openai): mark gpt-image-1.5, gpt-image-1-mini and chatgpt-imag…
cabljac Nov 16, 2026
f5b31ae
fix(py/openai): offer xhigh and max image quality only on the 2.5 and…
cabljac Nov 16, 2026
8e82f2f
test(py/openai): cover the DALL-E and diarize discovery filters and t…
cabljac Nov 16, 2026
1a2a60b
fix(py/openai): resolve shut-down chat ids with generic info instead …
cabljac Nov 16, 2026
a3c1c10
docs(py/openai): say shut-down chat ids leave the catalog but still r…
cabljac Nov 16, 2026
dd64239
fix(py/openai): give fine-tune ids generic info instead of their base…
cabljac Nov 16, 2026
91135fc
fix(py/openai): declare function tool support for gpt-6.1-terra
cabljac Nov 16, 2026
cf477c1
fix(py/openai): list gpt-4o-transcribe-diarize again as a transcripti…
cabljac Nov 16, 2026
df6d29f
fix(py/openai): hide text- and code- legacy completion ids from disco…
cabljac Nov 16, 2026
e97410c
fix(py/openai): hide computer-use, deep-research, Sora and -audio ids…
cabljac Nov 16, 2026
bf26efc
fix(py/openai): hide the shut-down gpt-image-1 from discovery
cabljac Nov 16, 2026
c30ec77
Merge remote-tracking branch 'origin/main' into feat/py-openai-catalog
cabljac Nov 16, 2026
2d42ac1
fix(py/openai): address final review feedback
cabljac Nov 16, 2026
a942ee3
Merge branch 'main' into feat/py-openai-catalog
cabljac Nov 17, 2026
f17f19c
fix(py/openai): preserve compatible host discovery and legacy capabil…
cabljac Nov 17, 2026
84c4f36
fix(py/openai): hide non-chat ids on every host and filter OpenAI reg…
cabljac Nov 17, 2026
aeee813
fix(py/openai): validate config.model against the resolved model info
cabljac Nov 17, 2026
0ad7738
fix(py/openai): keep JSON format instructions for dated snapshots
cabljac Nov 17, 2026
cb1cdac
fix(py/openai): only hide OpenAI realtime and moderation ids in disco…
cabljac Nov 17, 2026
9ca6513
fix(py/openai): hide every legacy completion id in discovery
cabljac Nov 17, 2026
61a3053
fix(py/openai): give gpt-5.2-chat-latest its legacy capabilities
cabljac Nov 17, 2026
3545354
Merge branch 'main' into feat/py-openai-catalog
cabljac Nov 17, 2026
84f4c3b
fix(py/openai): resolve shut-down chat ids with generic info
cabljac Nov 17, 2026
7117ddf
docs(py/openai): describe snapshot capabilities accurately
cabljac Nov 17, 2026
0958951
fix(py/openai): address catalog review feedback
cabljac Nov 30, 2026
d88e3f9
Merge remote-tracking branch 'origin/main' into feat/py-openai-catalog
cabljac Nov 30, 2026
4ccf6f2
test(py/openai): pin Mistral model labels after the main merge
cabljac Nov 30, 2026
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
36 changes: 33 additions & 3 deletions packages/genkit-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ OpenAI(
)
```

## Tools on reasoning models

On Chat Completions, some reasoning models, such as `gpt-6-sol`, accept
function tools only with `reasoning_effort='none'` and do not default to it.
Set it when you pass tools:

```python
res = await ai.generate(
model=OpenAI.gpt('gpt-6-sol'),
prompt='What is the weather in Paris?',
tools=['get_weather'],
config={'reasoning_effort': 'none'},
)
```

## Model discovery

Discovery lists the host's `/v1/models` ids, minus ids this plugin cannot
serve on that host. A hidden id still resolves by name. Ids that OpenAI has
shut down are not registered at startup. They resolve by name with generic
capabilities, for OpenAI-compatible hosts that still serve them. A dated
snapshot such as `gpt-5-2025-08-07` takes the capabilities and stage of its
alias.

## Image quality

`quality='xhigh'` and `quality='max'` work only on models that accept them.
On `gpt-image-2` and older GPT Image models they fail before the request is
sent. To send one anyway, pass it as `extra={'quality': 'xhigh'}`.

## Mistral

`Mistral()` registers Mistral's models and embedders under `mistral/`, as the
Expand Down Expand Up @@ -158,10 +188,10 @@ before the request is sent, so a typo fails by name:

```python
res = await ai.generate(
model=OpenAI.gpt('gpt-4o'),
model=OpenAI.gpt('gpt-5.5'),
prompt='Write a haiku about the sea.',
config={
'temperature': 0.2,
'reasoning_effort': 'low',
'max_output_tokens': 200, # caps reply length
'extra': {'user': 'diner-42'}, # a field OpenAIConfig doesn't declare
},
Expand All @@ -188,7 +218,7 @@ the plugin serves:

```python
res = await ai.generate(
model=OpenAI.gpt('gpt-4o'),
model=OpenAI.gpt('gpt-5.5'),
prompt='hi',
context={'secrets': {'api_key': tenant_key}},
)
Expand Down
90 changes: 30 additions & 60 deletions packages/genkit-openai/src/genkit_openai/_models/_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
capabilities via the OpenAI Audio API.

Supported TTS models: tts-1, tts-1-hd, gpt-4o-mini-tts
Supported STT models: gpt-4o-transcribe, gpt-4o-mini-transcribe, whisper-1
Supported STT models: gpt-transcribe, gpt-4o-transcribe, gpt-4o-mini-transcribe, whisper-1
"""

from __future__ import annotations
Expand All @@ -45,7 +45,7 @@
from pydantic import Field

from genkit import FinishReason, GenkitError, Message, ModelResponse, Part, Role
from genkit.model import ModelContext, ModelInfo, ModelRequest, ModelSupports
from genkit.model import ModelContext, ModelInfo, ModelRequest, ModelStage, ModelSupports
from genkit.plugin_api import GenkitConfig

_AUDIO_EXTRA_DESCRIPTION = (
Expand Down Expand Up @@ -103,72 +103,42 @@ class OpenAISttConfig(GenkitConfig):
'audio/mp4': 'mp4',
}

# Supported TTS models with their metadata.
_TTS_SUPPORTS = ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
)

_STT_SUPPORTS = ModelSupports(
media=True,
output=['text', 'json'],
multiturn=False,
system_role=False,
tools=False,
)

# Supported TTS models with their metadata. Shutdown 2027-01-06.
SUPPORTED_TTS_MODELS: dict[str, ModelInfo] = {
'tts-1': ModelInfo(
label='OpenAI - TTS 1',
supports=ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
),
),
'tts-1-hd': ModelInfo(
label='OpenAI - TTS 1 HD',
supports=ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
),
),
'gpt-4o-mini-tts': ModelInfo(
label='OpenAI - GPT-4o Mini TTS',
supports=ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
),
),
'tts-1': ModelInfo(label='OpenAI - TTS 1', supports=_TTS_SUPPORTS, stage=ModelStage.DEPRECATED),
'tts-1-hd': ModelInfo(label='OpenAI - TTS 1 HD', supports=_TTS_SUPPORTS, stage=ModelStage.DEPRECATED),
'gpt-4o-mini-tts': ModelInfo(label='OpenAI - GPT-4o Mini TTS', supports=_TTS_SUPPORTS, stage=ModelStage.DEPRECATED),
}

# Supported STT / transcription models with their metadata.
# Supported STT / transcription models with their metadata. Deprecated ids:
# shutdown 2027-02-26.
SUPPORTED_STT_MODELS: dict[str, ModelInfo] = {
'gpt-transcribe': ModelInfo(
label='OpenAI - GPT Transcribe', supports=_STT_SUPPORTS.model_copy(update={'output': ['text']})
),
'gpt-4o-transcribe': ModelInfo(
label='OpenAI - GPT-4o Transcribe',
supports=ModelSupports(
media=True,
output=['text', 'json'],
multiturn=False,
system_role=False,
tools=False,
),
label='OpenAI - GPT-4o Transcribe', supports=_STT_SUPPORTS, stage=ModelStage.DEPRECATED
),
'gpt-4o-mini-transcribe': ModelInfo(
label='OpenAI - GPT-4o Mini Transcribe',
supports=ModelSupports(
media=True,
output=['text', 'json'],
multiturn=False,
system_role=False,
tools=False,
),
),
'whisper-1': ModelInfo(
label='OpenAI - Whisper 1',
supports=ModelSupports(
media=True,
output=['text', 'json'],
multiturn=False,
system_role=False,
tools=False,
),
label='OpenAI - GPT-4o Mini Transcribe', supports=_STT_SUPPORTS, stage=ModelStage.DEPRECATED
),
'whisper-1': ModelInfo(label='OpenAI - Whisper 1', supports=_STT_SUPPORTS, stage=ModelStage.DEPRECATED),
}


Expand Down
20 changes: 0 additions & 20 deletions packages/genkit-openai/src/genkit_openai/_models/_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ def get_model_handler(
openai_model = OpenAIModel(model, client, supports=info.supports)
return cls(openai_model).generate

def _validate_version(self, version: str) -> None:
"""Validates whether the specified model version is supported.

Args:
version: The version of the model to be validated.

Raises:
ValueError: If the specified model version is not supported.
"""
model_info = _SUPPORTED_MODELS[self._model.name]
if model_info.versions is not None and version not in model_info.versions:
raise ValueError(f"Model version '{version}' is not supported.")

async def generate(self, request: ModelRequest, ctx: ModelContext) -> ModelResponse:
"""Processes the request using OpenAI's chat completion API.

Expand All @@ -91,13 +78,6 @@ async def generate(self, request: ModelRequest, ctx: ModelContext) -> ModelRespo

Returns:
A ModelResponse containing the model's response.

Raises:
ValueError: If the specified model version is not supported.
"""
request.config = self._model._normalize_config(request.config)

if request.config and hasattr(request.config, 'model') and request.config.model:
self._validate_version(request.config.model)

return await self._model.generate(request, ctx)
92 changes: 63 additions & 29 deletions packages/genkit-openai/src/genkit_openai/_models/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
"""OpenAI-compatible image generation model for Genkit.

Provides image generation capabilities via the OpenAI Images API,
supporting models like DALL-E 3 and GPT-Image-1.
supporting the GPT Image models (gpt-image-1-mini, gpt-image-1.5,
chatgpt-image-latest, gpt-image-2, gpt-image-2.5 and gpt-image-2.6).
"""

from __future__ import annotations

import re
from typing import Any, Literal

from genkit_openai._models._utils import (
Expand All @@ -36,8 +38,8 @@
from openai.types.images_response import ImagesResponse
from pydantic import Field

from genkit import FinishReason, Message, ModelResponse, Part, Role
from genkit.model import ModelContext, ModelInfo, ModelRequest, ModelSupports
from genkit import FinishReason, GenkitError, Message, ModelResponse, Part, Role
from genkit.model import ModelContext, ModelInfo, ModelRequest, ModelStage, ModelSupports
from genkit.plugin_api import GenkitConfig

_IMAGE_EXTRA_DESCRIPTION = (
Expand Down Expand Up @@ -68,9 +70,9 @@ class OpenAIGptImageConfig(GenkitConfig):
style: Literal['vivid', 'natural'] | None = None
user: str | None = None
n: int | None = Field(default=None, ge=1, le=10)
quality: Literal['low', 'medium', 'high'] | None = Field(
quality: Literal['low', 'medium', 'high', 'xhigh', 'max', 'auto'] | None = Field(
Comment thread
cabljac marked this conversation as resolved.
Resolved
default=None,
json_schema_extra={'enum': ['low', 'medium', 'high']},
json_schema_extra={'enum': ['low', 'medium', 'high', 'xhigh', 'max', 'auto']},
)
background: Literal['transparent', 'opaque', 'auto'] | None = None
moderation: Literal['low', 'auto'] | None = None
Expand All @@ -79,28 +81,54 @@ class OpenAIGptImageConfig(GenkitConfig):
extra: dict[str, Any] | None = Field(default=None, description=_IMAGE_EXTRA_DESCRIPTION)


# Supported image generation models with their metadata.
_STANDARD_QUALITY_GPT_IMAGE_MODEL = re.compile(
r'^(gpt-image-(1|1-mini|1\.5|2)|chatgpt-image-latest)(-\d{4}-\d{2}-\d{2})?$'
)
_MAX_QUALITY_VALUES = ('xhigh', 'max')


def _takes_max_quality(model_name: str) -> bool:
"""Whether a GPT Image model accepts quality ``xhigh`` and ``max``."""
return _STANDARD_QUALITY_GPT_IMAGE_MODEL.match(model_name) is None


def _limit_quality_options(model_name: str, custom_options: dict[str, Any]) -> None:
"""Drop ``xhigh`` and ``max`` from a published GPT Image config schema when the model rejects them."""
if _takes_max_quality(model_name):
return
quality = custom_options['properties']['quality']
for node in (quality, *quality.get('anyOf', ())):
if 'enum' in node:
node['enum'] = [value for value in node['enum'] if value not in _MAX_QUALITY_VALUES]


_GPT_IMAGE_SUPPORTS = ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
)

# Supported image generation models with their metadata. Other gpt-image
# ids still resolve by name.
SUPPORTED_IMAGE_MODELS: dict[str, ModelInfo] = {
'dall-e-3': ModelInfo(
label='OpenAI - DALL-E 3',
supports=ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
),
# Shutdown 2026-12-01.
'gpt-image-1-mini': ModelInfo(
label='OpenAI - GPT Image 1 Mini', supports=_GPT_IMAGE_SUPPORTS, stage=ModelStage.DEPRECATED
),
'gpt-image-1': ModelInfo(
label='OpenAI - GPT Image 1',
supports=ModelSupports(
media=False,
output=['media'],
multiturn=False,
system_role=False,
tools=False,
),
'gpt-image-1.5': ModelInfo(
label='OpenAI - GPT Image 1.5', supports=_GPT_IMAGE_SUPPORTS, stage=ModelStage.DEPRECATED
),
'chatgpt-image-latest': ModelInfo(
label='OpenAI - ChatGPT Image Latest', supports=_GPT_IMAGE_SUPPORTS, stage=ModelStage.DEPRECATED
),
# Shutdown 2027-02-10.
'gpt-image-2': ModelInfo(label='OpenAI - GPT Image 2', supports=_GPT_IMAGE_SUPPORTS, stage=ModelStage.DEPRECATED),
Comment thread
cabljac marked this conversation as resolved.
Resolved
'gpt-image-2.5-sunburst': ModelInfo(label='OpenAI - GPT Image 2.5 Sunburst', supports=_GPT_IMAGE_SUPPORTS),
'gpt-image-2.5-flare': ModelInfo(label='OpenAI - GPT Image 2.5 Flare', supports=_GPT_IMAGE_SUPPORTS),
'gpt-image-2.6-sunburst': ModelInfo(label='OpenAI - GPT Image 2.6 Sunburst', supports=_GPT_IMAGE_SUPPORTS),
'gpt-image-2.6-flare': ModelInfo(label='OpenAI - GPT Image 2.6 Flare', supports=_GPT_IMAGE_SUPPORTS),
}


Expand All @@ -118,7 +146,7 @@ def _to_image_generate_params(
image generation API parameters.

Args:
model_name: The OpenAI model name (e.g., 'dall-e-3').
model_name: The OpenAI model name (e.g., 'gpt-image-2.5-flare').
request: The Genkit generate request.

Returns:
Expand All @@ -128,15 +156,21 @@ def _to_image_generate_params(
config = extract_config_dict(request)
extra_body = pop_extra_body(config, managed=('prompt', 'model'), label='openai image')
reject_version(config, label='openai image')
quality = config.get('quality')
if quality in _MAX_QUALITY_VALUES and not _takes_max_quality(model_name):
raise GenkitError(
status='INVALID_ARGUMENT',
message=f'openai image: quality {quality!r} is not supported by {model_name}; '
f"use low, medium, high or auto, or move it to extra={{'quality': {quality!r}}} to send it anyway",
)

# Start with required params.
params: dict[str, Any] = {
'model': model_name,
'prompt': prompt,
}

# GPT Image 1 rejects the response_format parameter; its API always
# returns base64 image data. DALL-E models retain the existing default.
# GPT Image models reject response_format and always return base64 data.
if 'gpt-image' not in model_name.lower():
params['response_format'] = config.pop('response_format', 'b64_json')
else:
Expand Down Expand Up @@ -188,15 +222,15 @@ class OpenAIImageModel:
"""Handles image generation via the OpenAI Images API.

Args:
model_name: The image model to use (e.g., 'dall-e-3').
model_name: The image model to use (e.g., 'gpt-image-2.5-flare').
client: An async OpenAI client instance.
"""

def __init__(self, model_name: str, client: AsyncOpenAI) -> None:
"""Initialize the image model.

Args:
model_name: The image model to use (e.g., 'dall-e-3').
model_name: The image model to use (e.g., 'gpt-image-2.5-flare').
client: An async OpenAI client instance.
"""
self._model_name = model_name
Expand Down
Loading
Loading