Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b9d0606
fix(py): make the Quick Start runnable as written
huangjeff5 Nov 9, 2026
b0b9800
fix(py): make google-genai README snippets runnable
huangjeff5 Nov 9, 2026
0cf431c
fix(py): wrap plugin README snippets in async main and drop retired C…
huangjeff5 Nov 9, 2026
a72f8b0
fix(py): refresh stale Genkit docstrings (gemini ref, streaming, defi…
huangjeff5 Nov 9, 2026
c6a65c0
fix(py): fix migration guide middleware hook name and typed refs; Dja…
huangjeff5 Nov 9, 2026
58d20c9
fix(py): point doc links at the Python docs and first-party Anthropic…
huangjeff5 Nov 9, 2026
cccc64d
fix(py): drop Gemini API 404 ids from GoogleAI autocomplete and add l…
huangjeff5 Nov 9, 2026
ec8051d
fix(py): document thinking_level support per model and replace retire…
huangjeff5 Nov 9, 2026
de9defc
fix(py): fix ToolApproval resume docs, scrub PII in history and tool …
huangjeff5 Nov 9, 2026
99e278c
fix(py): document partial chunk.output None fields and ToolContext re…
huangjeff5 Nov 9, 2026
29def21
fix(py): note async main for call-only snippets in provider READMEs
huangjeff5 Nov 9, 2026
ec717df
fix(py): wrap long plugin error line; format docstring example
huangjeff5 Nov 9, 2026
675e583
fix(py): drop google_search from the function-tool README example (Ge…
huangjeff5 Nov 9, 2026
849ec17
fix(py): match generate_stream docstring output to runtime
huangjeff5 Nov 9, 2026
a870e9f
fix(py): update docstring test for GoogleAI.gemini ref
huangjeff5 Nov 9, 2026
65453be
docs(py): describe returned failures under the raise_on_error=False d…
huangjeff5 Nov 10, 2026
860000d
fix(py): make google-genai README snippets runnable
huangjeff5 Nov 9, 2026
d2710f2
fix(py): hydrate every output_schema type through TypeAdapter
huangjeff5 Nov 9, 2026
eebac20
fix(py): restore google-genai README tool example from the base PR
huangjeff5 Nov 10, 2026
1ea19dc
test(py): cover Optional, union, and nested dataclass output_schema
huangjeff5 Nov 10, 2026
a48725b
fix(py): type response.output as OutputT when output_schema is a type
huangjeff5 Nov 9, 2026
6b6f15e
docs(py): say output is still None on the default path for a non-matc…
huangjeff5 Nov 10, 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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# API Reference

!!! note
Full Genkit documentation is available at [genkit.dev](https://genkit.dev/python/docs/get-started/)
Full Genkit documentation is available at [genkit.dev](https://genkit.dev/docs/python/get-started/)

## genkit

Expand Down
27 changes: 24 additions & 3 deletions docs/migrating-from-0.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ If you're a coding agent, replace each enum member with its string value. The va

Every removed name, and what to use instead:

- **Model enums** (`KnownGemini*`, `KnownGpt`, `KnownClaude`, `*Version`, `GeminiEmbeddingModels`, `VertexEmbeddingModels`): pass the model name as a string, such as `'openai/gpt-4o'`.
- **Model enums** (`KnownGeminiModels`, `KnownGemini*`, `KnownGpt`, `KnownClaude`, `*Version`, `GeminiEmbeddingModels`, `VertexEmbeddingModels`): pass a typed ref such as `GoogleAI.gemini('gemini-flash-latest')` or `OpenAI.gpt('gpt-4o')`, or the model name as a string, such as `'openai/gpt-4o'`.
- **Name helpers** (`bedrock_name`, `anthropic_name`, `ollama_name`, `openai_model`, `genkit_eval_name`, `package_name`): use the full `'plugin/model'` string.
- **`Candidate`**: use the response's `message`.
- **`Document.data`, `Document.data_type`, `Document.from_data()`**: build a `Document` with its constructor.
Expand Down Expand Up @@ -808,7 +808,10 @@ model = openai_model('gpt-4o')
**New:**

```python
model = 'openai/gpt-4o'
from genkit_openai import OpenAI

model = OpenAI.gpt('gpt-4o') # typed ref; autocompletes and binds OpenAIConfig
model = 'openai/gpt-4o' # plain string also works
```

## Ollama
Expand Down Expand Up @@ -907,6 +910,22 @@ if res.output is None:

With `raise_on_error=True`, an incomplete reply raises `GenkitError` with reason `INVALID_OUTPUT` instead.

## Non-model output schemas

`output_schema` now hydrates any type pydantic validates (`list[T]`, dataclasses, `TypedDict`, `Enum`, `Literal`, `Decimal`, `UUID`, `datetime`), not just `BaseModel`, so drop workarounds for the old raw JSON: index a dataclass by attribute (`res.output.name`, not `res.output['name']`), compare a plain `Enum` to its member (`Status.OPEN`, not `'OPEN'`), and do `Decimal` math instead of `float` math.

## Typed `output`

With `output_schema=T`, `response.output` types as `T` instead of `T | None`, for `generate`, `generate_stream`'s final response, and prompts. Drop the `cast()`. With no schema, or a JSON-schema dict, it types as `Any`. `chunk.output` stays `T | None`: early chunks have nothing to parse yet.

```python
res = await ai.generate(prompt='Suggest a dish.', output_schema=Dish)
print(res.output.name)
# => Smoked Salmon Tartine
```

The static type does not model `None`, but `output` is still `None` at runtime when the reply has no output. With the default `raise_on_error=False`, that includes a reply that doesn't match the schema (`error` is set). It also covers an interrupt, a `blocked` finish, or a stream you stopped early. Keep a guard, or pass `raise_on_error=True` so a non-matching reply raises instead. Under strict pyright, `if res.output is None:` now reports `reportUnnecessaryComparison`; guard on `res.error`, `res.finish_reason`, or `res.interrupts` instead.

## Flow input and output validation

Flow input and output are now validated against their type annotations. A flow that returns the wrong shape now raises. For served flows, `{"data": null}` means "use the default".
Expand Down Expand Up @@ -939,9 +958,11 @@ from genkit.middleware import Middleware, MiddlewareContext
@ai.middleware
class PiiRedact(Middleware[Cfg]):
name = 'pii_redact'
async def model(self, params, ctx: MiddlewareContext, next_fn): ...
async def wrap_model(self, params, ctx: MiddlewareContext, next_fn): ...
```

Hooks are now `wrap_generate`, `wrap_model`, and `wrap_tool`. A method still named `model` is never called; the class inherits the pass-through `wrap_model` and the request goes to the provider unchanged, with no error.

`tools()` returns `Tool` handles. `GenerateMiddleware`, `MiddlewareRef`, `MiddlewarePlugin` and `new_middleware` are removed.

### Defining models and embedders
Expand Down
13 changes: 10 additions & 3 deletions packages/genkit-amazon-bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,18 @@ from genkit_amazon_bedrock import Bedrock, BedrockConfig
claude = Bedrock.text('us.anthropic.claude-sonnet-4-5-20250929-v1:0', config=BedrockConfig(max_output_tokens=512))

# 2. Generate
response = await ai.generate(model=claude, prompt='Pair a wine with mushroom risotto.')
print(response.text)
# => A dry white such as a Pinot Grigio ...
async def main() -> None:
response = await ai.generate(model=claude, prompt='Pair a wine with mushroom risotto.')
print(response.text)
# => A dry white such as a Pinot Grigio ...


if __name__ == '__main__':
ai.run_main(main())
```

Later snippets use `await` and show only the call; run them inside `async def main()` as above.

The constructors follow Bedrock's output modalities: `Bedrock.text` (TEXT,
served over Converse, including models that take image or document input),
`Bedrock.stability` (IMAGE, the Stability text-to-image models), and
Expand Down
19 changes: 14 additions & 5 deletions packages/genkit-anthropic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ from genkit_anthropic import Anthropic

ai = Genkit(plugins=[Anthropic()])

res = await ai.generate(
model=Anthropic.claude('claude-sonnet-4-6'),
prompt='Explain recursion in 10 words.',
)
print(res.text)

async def main() -> None:
res = await ai.generate(
model=Anthropic.claude('claude-sonnet-4-6'),
prompt='Explain recursion in 10 words.',
)
print(res.text)
# => A function that solves a problem by calling itself repeatedly.


if __name__ == '__main__':
ai.run_main(main())
```

Later snippets use `await` and show only the call; run them inside `async def main()` as above.

Set `ANTHROPIC_API_KEY` in the environment, or pass `api_key=` to `Anthropic()`.
`base_url=` points the plugin at another server. Pass the origin with no `/v1`
suffix; the SDK appends `/v1/messages`. Any other `AsyncAnthropic` setting goes
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-django/src/genkit_django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def chat(prompt: str) -> str:
```

Requirements:
- Django 4.1+ (async views require ASGI)
- Django 5.0+ (async views require ASGI)
- An ASGI server such as ``uvicorn`` or ``daphne``:

```bash
Expand Down
10 changes: 6 additions & 4 deletions packages/genkit-fastapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ app = FastAPI()

@ai.flow()
async def ask_chef(prompt: str, ctx: FlowContext[str]) -> str:
stream = ai.generate_stream(prompt=prompt)
async for chunk in stream:
ctx.send_chunk(chunk.text)
return (await stream.response).text
result = ai.generate_stream(prompt=prompt)
# The context manager closes the model stream if the client disconnects.
async with result.stream as chunks:
async for chunk in chunks:
ctx.send_chunk(chunk.text)
return (await result.response).text


@app.post('/chat/stream')
Expand Down
11 changes: 9 additions & 2 deletions packages/genkit-google-cloud/src/genkit_google_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@

# All subsequent Genkit actions automatically export telemetry
ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))
await ai.generate(prompt='Hello, world!')
# => Traces exported asynchronously to Cloud Trace (latency, tokens, status)


async def main() -> None:
await ai.generate(prompt='Hello, world!')
# => Traces exported asynchronously to Cloud Trace (latency, tokens, status)


if __name__ == '__main__':
ai.run_main(main())
```

Requirements:
Expand Down
Loading
Loading