codex-ai
Gemini-first API helpers for the Codex ecosystem. The active surface is direct Gemini text, JSON, Gemini image, and Imagen generation. OpenAI provides modern Responses API text, structured JSON, and streaming helpers. The router/dispatcher layer is kept for legacy text 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 pathlib import Path
from pydantic import BaseModel
from codex_ai import GeminiProvider, ImageInput
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(
"Square tactical dark fantasy ruined capital city map, no labels.",
model="gemini-3-pro-image-preview",
response_mime_type="image/png",
image_config={"aspect_ratio": "1:1", "image_size": "4K"},
)
source_image_bytes = Path("source.png").read_bytes()
edited_bytes, edited_content_type = await gemini.generate_image_bytes(
"Keep the composition, but redraw it as a watercolor map.",
response_mime_type="image/png",
input_images=[ImageInput(data=source_image_bytes, mime_type="image/png")],
)
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. Pass Gemini image controls such as
aspect_ratio and image_size with image_config; if a 4K request is rejected,
the Gemini provider retries once with 2K. Pass input_images with ImageInput
items to provide reference/edit-source images for Gemini image models. Use generate_imagen_bytes() for
Imagen models; that path uses generate_images and passes the requested MIME as
output_mime_type.
OpenAI Responses API
from pydantic import BaseModel
from codex_ai import OpenAIProvider
class LootItem(BaseModel):
name: str
power: int
openai = OpenAIProvider(api_key="sk-...")
text = await openai.generate_text("Write one short tavern rumor.")
loot = await openai.generate_json("Create one loot item.", schema=LootItem)
async for chunk in openai.stream_text("Tell a short story."):
print(chunk, end="")
The OpenAI provider uses the Responses API and the openai 2.x SDK. Responses
are not stored by default. Its default gpt-5.6-luna model uses
reasoning={"effort": "none"} to retain a cost- and latency-sensitive role;
override the model and reasoning options per request when a workload needs more
capability.
Legacy Text Router
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!")
Use this path only when you already have prompt builders registered through LLMRouter.
New Gemini integrations should call generate_text(), generate_json(),
generate_image_bytes(), or generate_imagen_bytes() directly.
Modules
| Module | Extra | Description |
|---|---|---|
codex_ai.providers.gemini |
[gemini] |
Primary API: Gemini text, JSON, Gemini image, and Imagen generation via pinned google-genai |
codex_ai.providers.openai |
[openai] |
OpenAI Responses API text, structured JSON, and streaming adapter |
codex_ai.core |
- | Legacy text router/dispatcher contracts and shared provider exceptions |
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:
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.5.tar.gz.
File metadata
- Download URL: codex_ai-0.2.5.tar.gz
- Upload date:
- Size: 136.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
541b6f2d62209353033e7d316ad55d70fb08ac9cd8336a173dfe7ca54a0c0b94
|
|
| MD5 |
a3a6909b73091ba295caadf263e8a0df
|
|
| BLAKE2b-256 |
75cca3219eff366ee4c4140f7bb9a297be4820b50aa0f6b25ebe4ffb25bd3235
|
Provenance
The following attestation bundles were made for codex_ai-0.2.5.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.5.tar.gz -
Subject digest:
541b6f2d62209353033e7d316ad55d70fb08ac9cd8336a173dfe7ca54a0c0b94 - Sigstore transparency entry: 2197779402
- Sigstore integration time:
-
Permalink:
CodexDLC/codex-ai@7c535e3c6715191303c55def931c1ebc3f3483f2 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/CodexDLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c535e3c6715191303c55def931c1ebc3f3483f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_ai-0.2.5-py3-none-any.whl.
File metadata
- Download URL: codex_ai-0.2.5-py3-none-any.whl
- Upload date:
- Size: 21.5 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 |
10f06daf6d80e6a6ea25bfb4108919e8200e09598b7d984b61ab39c8a2475293
|
|
| MD5 |
a51394e97312d9c7ef734e7d59f02ee4
|
|
| BLAKE2b-256 |
09ef221dbc71387aba5994b2fffb39fdcfa5f78017779e3a549763cfcf75c691
|
Provenance
The following attestation bundles were made for codex_ai-0.2.5-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.5-py3-none-any.whl -
Subject digest:
10f06daf6d80e6a6ea25bfb4108919e8200e09598b7d984b61ab39c8a2475293 - Sigstore transparency entry: 2197779695
- Sigstore integration time:
-
Permalink:
CodexDLC/codex-ai@7c535e3c6715191303c55def931c1ebc3f3483f2 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/CodexDLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c535e3c6715191303c55def931c1ebc3f3483f2 -
Trigger Event:
push
-
Statement type: