Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a1510f8
feat(openai): send Mistral's field names when base_url is api.mistral.ai
adesinah Nov 11, 2026
d375efb
test(openai): cover Mistral request bodies against a fake server
adesinah Nov 11, 2026
9bed258
docs(openai): document the Mistral base_url recipe
adesinah Nov 11, 2026
fbb75a8
feat(py/openai): read Mistral thinking chunks, cover Codestral, forwa…
adesinah Nov 11, 2026
1c1d930
test(py/openai): enforce Mistral's closed schema in the fake server
adesinah Nov 11, 2026
70c5c50
docs(py/openai): Codestral host, api_key, reasoning and embedder note…
adesinah Nov 11, 2026
fc5aaba
chore(py/openai): merge main into feat/ai-832-mistral-openai-compat
adesinah Nov 12, 2026
8a22747
feat(py/openai): replay Mistral reasoning, map model_length, add EU/U…
adesinah Nov 12, 2026
b8c74fd
test(py/openai): cover Mistral reasoning replay, regional hosts and m…
adesinah Nov 12, 2026
904466d
docs(py/openai): describe Mistral reasoning via reasoning_effort and …
adesinah Nov 12, 2026
f789566
fix(py/openai): refuse top_k for Mistral before the request goes out
adesinah Nov 13, 2026
f446cad
fix(py/openai): replay only Mistral's reasoning, read MISTRAL_API_KEY…
adesinah Nov 17, 2026
0a8c4ca
fix(py/openai): replay each Mistral reasoning part as its own thinkin…
adesinah Nov 17, 2026
b85445e
fix(py/openai): default provider='mistral' to Mistral's base URL
adesinah Nov 17, 2026
667a87c
fix(py/openai): explain an ignored OPENAI_API_KEY and never hand Mist…
adesinah Nov 17, 2026
e5abec1
fix(py/openai): keep streamed signed thinking chunks as separate parts
adesinah Nov 17, 2026
7acd17e
fix(py/openai): accept reasoning_effort='max' for Mistral
adesinah Nov 17, 2026
19432fa
fix(py/openai): refuse non-image media for Mistral before the request
adesinah Nov 17, 2026
1351476
fix(py/openai): keep Mistral reasoning and text in the order they came
adesinah Nov 18, 2026
66e0b49
fix(py/openai): leave out OpenAI-only settings Mistral doesn't declare
adesinah Nov 18, 2026
a1476d2
feat(py/openai): name a Mistral target mistral and list it by capabil…
adesinah Nov 18, 2026
04cd7db
fix(py/openai): refuse logprobs on Mistral
adesinah Nov 18, 2026
53a9196
Merge remote-tracking branch 'origin/main' into HEAD
adesinah Nov 18, 2026
bdca0b7
fix(py/openai): keep json_object for Mistral ids outside the catalog
adesinah Nov 20, 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
96 changes: 96 additions & 0 deletions packages/genkit-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,102 @@ OpenAI(
)
```

## Mistral

`Mistral()` registers Mistral's models and embedders under `mistral/`, as the
JS and Dart SDKs do, so it can sit beside `OpenAI()`:

```python
from genkit import Genkit
from genkit_openai import Mistral, OpenAI

# The Mistral key comes from MISTRAL_API_KEY, the OpenAI one from OPENAI_API_KEY.
ai = Genkit(plugins=[OpenAI(), Mistral()])

res = await ai.generate(
model=Mistral.model('mistral-small-latest'), # or 'mistral/mistral-small-latest'
prompt='Suggest 2 names for a French bakery.',
config={'temperature': 0.3, 'seed': 42, 'max_output_tokens': 200},
)

embeddings = await ai.embed(embedder='mistral/mistral-embed', content='croissant')
```

`Mistral()` is `OpenAI(provider='mistral')`. `OpenAI(base_url=...)` with one of
Mistral's hosts (`OPENAI_BASE_URL` too) is the same plugin, also named
`mistral`. Its key comes from `api_key=` or `MISTRAL_API_KEY`, never
`OPENAI_API_KEY`. The EU and US endpoints, `https://api.eu.mistral.ai/v1` and
`https://api.us.mistral.ai/v1`, work the same way.

At startup it registers Mistral's own catalog, not OpenAI's:
`mistral-large-latest`, `mistral-large-4`, `mistral-small-latest`,
`ministral-14b-latest`, `ministral-8b-latest`, `ministral-3b-latest`,
`codestral-latest` and `mistral-medium-latest` (deprecated by Mistral), and
the `mistral-embed` (1024 dimensions) and `codestral-embed` (1536) embedders.
The Dev UI's model list comes from Mistral's `/models`, read by each entry's
`capabilities`: ids with `embed` are embedders, entries with `completion_chat`
are chat models, and OCR, moderation, transcription and speech models are left
out. A model outside the catalog takes tool and image support from
`function_calling` and `vision`. Any other id still resolves as a chat model
when named, e.g. `mistral/magistral-medium-latest`.

A gateway in front of Mistral on another host needs `Mistral(base_url=...)`
(or `provider='mistral'`); without it the plugin can't tell the API behind it
is Mistral's and sends OpenAI's field names, which Mistral rejects. Pass the
gateway's own key as `api_key=`, or the plugin reads `MISTRAL_API_KEY`:

```python
Mistral(base_url='https://llm-gateway.example.com/v1', api_key=gateway_key)
```

`Mistral()` with no `base_url` goes to `https://api.mistral.ai/v1`;
`OPENAI_BASE_URL` isn't read then.

Mistral rejects any request field it doesn't declare, so with a Mistral host
(or `provider='mistral'`) the plugin sends Mistral's names for the settings
that differ:

- `max_output_tokens` goes out as `max_tokens`, never `max_completion_tokens`,
even with `reasoning_effort` set.
- `seed` goes out as `random_seed`.
- `top_k` is refused before the request goes out: Mistral's models reject
`top_k` sampling. So are `logprobs=True` and any `top_logprobs`: Mistral's
models answer "Logprobs are not enabled for this model". `logprobs=False`
is left out of the request.
- `reasoning_effort` also takes `'max'`, which Mistral's API declares and
OpenAI's doesn't; other targets refuse it before the request goes out.
Which values a model accepts varies: Mistral Small takes `none` and `high`,
Mistral Large `low`, `medium` and `high`.
- Streaming sends no `stream_options`; Mistral reports usage on the last chunk
without it.
- An embedder's `dimensions` goes out as `output_dimension`.
- Media other than images, such as a PDF, is refused before the request goes
out: every media part goes out as `image_url`. The type comes from the part's
`content_type`, else a `data:` URL's header; a remote URL with neither is
sent as an image.
- OpenAI-only settings Mistral doesn't declare are left out of the request,
with a warning in the log: `verbosity`, `safety_identifier`, `store`,
`logit_bias`, `prompt_cache_retention`, `web_search_options`, `modalities`
and `audio`. Mistral would fail the call with a 422 naming them.
`service_tier`, `prompt_cache_key`, `metadata`, `prediction` and
`parallel_tool_calls` are Mistral fields too and go out as given
(`service_tier` takes only `auto` or `standard_only`).
- `extra` gets the same renames: `seed` and `max_completion_tokens` there go
out as `random_seed` and `max_tokens`, and `stream_options` is dropped.
Nothing else in `extra` is dropped.

With `reasoning_effort` set, replies carry their reasoning in `thinking`
Comment thread
adesinah marked this conversation as resolved.
Resolved
chunks. Each comes back as its own reasoning part, in the order it came among
the text, with its own signature in `metadata['thoughtSignature']`; a streamed
reply's final message keeps the same order and joins each chunk's fragments
back into one part, ending a part at the fragment that carries a signature. On the next turn each part goes back to Mistral as its own
`thinking` chunk, in order, as Mistral asks, so a signature stays with the text
it signs. Only reasoning that came from Mistral goes back: each such part is
marked `metadata['reasoningSource'] == 'mistral'`, which survives saving the
history as JSON. Reasoning another model left in a mixed history is dropped.

Mistral-only fields like `min_tokens` go in `extra`.

## Config

`config` takes the settings `OpenAIConfig` declares. Any other key raises
Expand Down
9 changes: 6 additions & 3 deletions packages/genkit-openai/src/genkit_openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Registers OpenAI chat, image, text-to-speech, transcription, and embedding
models under ``openai/``, using the official OpenAI Python SDK. ``base_url=``
points it at any OpenAI-compatible server, such as Azure OpenAI or Together AI.
``Mistral()`` (or ``OpenAI(provider='mistral')``) registers Mistral's chat
models and embedders under ``mistral/``.

Example:
```python
Expand Down Expand Up @@ -48,7 +50,8 @@ async def main() -> None:
```

Credentials:
The plugin key comes from ``api_key=`` or ``OPENAI_API_KEY``. A
The plugin key comes from ``api_key=`` or ``OPENAI_API_KEY``
(``MISTRAL_API_KEY`` when the target is Mistral). A
``generate()`` or ``embed()`` call can bring its own key as
``context={'secrets': {'api_key': ...}}``; a plugin with no key of its
own serves only those calls.
Expand All @@ -57,7 +60,7 @@ async def main() -> None:
- OpenAI documentation: https://platform.openai.com/docs/
"""

from ._openai_plugin import OpenAI
from ._openai_plugin import Mistral, OpenAI
from ._typing import OpenAIConfig

__all__ = ['OpenAI', 'OpenAIConfig']
__all__ = ['Mistral', 'OpenAI', 'OpenAIConfig']
Loading
Loading