Gemini-first and OpenAI provider helpers for Codex
Project description
codex-ai
Gemini-first and OpenAI provider helpers for the Codex ecosystem. The library keeps the legacy prompt router for text generation, and exposes direct provider methods for practical Gemini workflows.
Install
pip install codex-ai
pip install "codex-ai[gemini]"
pip install "codex-ai[openai]"
pip install "codex-ai[openai,gemini]"
Requires Python 3.12 or newer.
Gemini Direct API
from pydantic import BaseModel
from codex_ai import GeminiProvider
class LootItem(BaseModel):
name: str
power: int
gemini = GeminiProvider(api_key="AIza...")
text = await gemini.generate_text("Write one short tavern rumor.")
loot = await gemini.generate_json("Create one loot item.", schema=LootItem)
image_bytes, content_type = await gemini.generate_image_bytes(
"A fantasy clan banner, game icon style.",
response_mime_type="image/webp",
)
imagen_bytes, imagen_content_type = await gemini.generate_imagen_bytes(
"A fantasy clan banner, game icon style.",
response_mime_type="image/jpeg",
)
answer(prompt) remains available as a compatibility wrapper for text generation.
generate_image_bytes() targets Gemini image models through generate_content and treats
response_mime_type as a preferred/fallback MIME type. It does not pass image MIME values
to Gemini's text response_mime_type config field. Use generate_imagen_bytes() for
Imagen models; that path uses generate_images and passes the requested MIME as
output_mime_type.
Router Pipeline
from codex_ai import GeminiProvider, LLMDispatcher, LLMMessage, LLMRouter, PromptResult
router = LLMRouter()
@router.prompt("chat")
async def build_chat(text: str, **kw) -> PromptResult:
return PromptResult(
messages=[LLMMessage(role="user", content=text)],
system="You are a helpful assistant.",
)
dispatcher = LLMDispatcher(provider=GeminiProvider(api_key="AIza..."))
dispatcher.include_router(router)
response = await dispatcher.process("chat", text="Hello!")
Modules
| Module | Extra | Description |
|---|---|---|
codex_ai.core |
- | Dispatcher, router, protocol types, sync wrapper, and shared exception contract |
codex_ai.providers.gemini |
[gemini] |
Google Gemini text, JSON, Gemini image, and Imagen generation via pinned google-genai |
codex_ai.providers.openai |
[openai] |
OpenAI Chat Completions text provider |
Development
uv sync --extra dev
uv run pytest
uv run mypy src/
uv run pre-commit run --all-files
uv build --no-sources
Documentation
Full docs with architecture, API reference, and data flow diagrams:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_ai-0.2.1.tar.gz.
File metadata
- Download URL: codex_ai-0.2.1.tar.gz
- Upload date:
- Size: 131.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea35d73d23556ccbe5ce32771f820a30d05b3afe7298add8c37123ea10c84e83
|
|
| MD5 |
36cd1e11ee540e1c415af1ba8184039c
|
|
| BLAKE2b-256 |
fedd3d2991ae9faf44162530f34685f6884e653de67821c482209b27342a0655
|
Provenance
The following attestation bundles were made for codex_ai-0.2.1.tar.gz:
Publisher:
publish.yml on CodexDLC/codex-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_ai-0.2.1.tar.gz -
Subject digest:
ea35d73d23556ccbe5ce32771f820a30d05b3afe7298add8c37123ea10c84e83 - Sigstore transparency entry: 1549785003
- Sigstore integration time:
-
Permalink:
CodexDLC/codex-ai@7e86df70216fe239a22f9b385d25423bf8f41c51 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/CodexDLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7e86df70216fe239a22f9b385d25423bf8f41c51 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_ai-0.2.1-py3-none-any.whl.
File metadata
- Download URL: codex_ai-0.2.1-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
024920a7b880f14fbe8620c42a135beddb52205c789259cdbb9795e7b5fdd565
|
|
| MD5 |
59bdcb4986c11e0626bc472d785fc27c
|
|
| BLAKE2b-256 |
e65241f349ab63365ca69c7cc26afe58c83386b2bac0ab20d77b220c6a741bf1
|
Provenance
The following attestation bundles were made for codex_ai-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on CodexDLC/codex-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_ai-0.2.1-py3-none-any.whl -
Subject digest:
024920a7b880f14fbe8620c42a135beddb52205c789259cdbb9795e7b5fdd565 - Sigstore transparency entry: 1549785035
- Sigstore integration time:
-
Permalink:
CodexDLC/codex-ai@7e86df70216fe239a22f9b385d25423bf8f41c51 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/CodexDLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7e86df70216fe239a22f9b385d25423bf8f41c51 -
Trigger Event:
push
-
Statement type: