Skip to main content

Genkit OpenAI Plugin

OpenAI-compatible model provider for Genkit (OpenAI, Azure OpenAI, and other compatible endpoints).

Building with a coding agent? Install the Genkit Python skill first.

npx skills add genkit-ai/skills --skill developing-genkit-python

It teaches your agent the current Genkit Python APIs and common gotchas. Source, manual install and skills for other languages: genkit-ai/skills.

Installation

uv add genkit-openai

Usage

from genkit import Genkit
from genkit_openai import OpenAI

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

res = await ai.generate(
    model=OpenAI.gpt('gpt-5.2'),
    prompt='Suggest 2 catchy names for an AI newsletter.',
)
print(res.text)

Set OPENAI_API_KEY in the environment, or pass api_key= to OpenAI(). base_url= points the plugin at another OpenAI-compatible server. Pass the URL up to and including /v1; the SDK appends /chat/completions. Any other AsyncOpenAI setting goes in client_options:

OpenAI(
    api_key=key,
    base_url='https://openrouter.ai/api/v1',
    client_options={'organization': 'org-123', 'timeout': 30, 'max_retries': 5},
)

Config

config takes the settings OpenAIConfig declares. Any other key raises before the request is sent, so a typo fails by name:

res = await ai.generate(
    model='openai/gpt-4o',
    prompt='Write a haiku about the sea.',
    config={
        'temperature': 0.2,
        'max_output_tokens': 200,  # caps reply length
        'extra': {'reasoning': {'effort': 'low'}},  # fields OpenAIConfig doesn't declare
    },
)
  • max_output_tokens (maxOutputTokens in the Dev UI) caps reply length. It goes out as max_tokens, or as max_completion_tokens on reasoning models. stop_sequences goes out as stop. OpenAI's own names (max_tokens, max_completion_tokens, stop) are not declared on OpenAIConfig, so passing them at the top level raises INVALID_ARGUMENT.
  • extra goes out as top-level request body fields. A key in extra replaces a setting of the same name (including max_tokens or max_completion_tokens for OpenAI-compatible servers). An API key in config or extra raises INVALID_ARGUMENT; it belongs in context.secrets.

Per-request API key

To bill a call to someone else's OpenAI account, pass their key in context.secrets. It's used for that call only, on chat, image, text-to-speech, and transcription models:

res = await ai.generate(
    model='openai/gpt-4o',
    prompt='hi',
    context={'secrets': {'api_key': tenant_key}},
)
  • apiKey works as well as api_key. Other entries in context.secrets are left alone, so a call whose secrets hold no key runs on the plugin's key. A key that is blank or not a string raises INVALID_ARGUMENT.
  • The tenant call sends only the tenant's key. The plugin's organization, project, OPENAI_ORG_ID and OPENAI_PROJECT_ID are left off; base_url, timeouts and other default_headers carry over. A plugin whose default_headers pin Authorization refuses a tenant key with FAILED_PRECONDITION.
  • The plugin doesn't need a key of its own for chat, image, text-to-speech, and transcription models: OpenAI() with no OPENAI_API_KEY serves every call that brings a key in context.secrets, and a call without one fails with FAILED_PRECONDITION.
  • Embedders run on the plugin's key only, since ai.embed() takes no context. On a plugin without a key they fail with FAILED_PRECONDITION.

Metadata

Release files for genkit-openai 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genkit-openai 0.13.0
File Size Uploaded Provenance Actions
genkit_openai-0.13.0.tar.gz 79.1 kB With provenance Details for genkit_openai-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genkit-openai 0.13.0
File Interpreter ABI Platform Actions
genkit_openai-0.13.0-py3-none-any.whl Python 3 none any Details for genkit_openai-0.13.0-py3-none-any.whl

Total release size: 126.7 kB

Release files / genkit_openai-0.13.0.tar.gz

Download URL genkit_openai-0.13.0.tar.gz
Size 79.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2e6d84679e9cdb8a2c26aea7c95863991a92a467ba448d1a8b0b5d32e7444d5e
BLAKE2b-256 checksum
How to use checksums
264d525ec4a032be45990c511f7ea52048271da6937c9fdd69c18585646f37fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / genkit_openai-0.13.0-py3-none-any.whl

Download URL genkit_openai-0.13.0-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db1849850cb462f1f29e120f87b3ee14770f83284a25bb33086d3e7ae4a8932b
BLAKE2b-256 checksum
How to use checksums
4b44a4e1678f691ac703f6b43809c6a9df1f131eeb2519d12a3876f566b2ac54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for genkit-openai 0.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for genkit_openai-0.13.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page