Skip to main content

codex-ai

PyPI version Python CI License

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:

codexdlc.github.io/codex-ai

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_ai-0.2.5.tar.gz (136.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_ai-0.2.5-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

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

Hashes for codex_ai-0.2.5.tar.gz
Algorithm Hash digest
SHA256 541b6f2d62209353033e7d316ad55d70fb08ac9cd8336a173dfe7ca54a0c0b94
MD5 a3a6909b73091ba295caadf263e8a0df
BLAKE2b-256 75cca3219eff366ee4c4140f7bb9a297be4820b50aa0f6b25ebe4ffb25bd3235

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_ai-0.2.5.tar.gz:

Publisher: publish.yml on CodexDLC/codex-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for codex_ai-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 10f06daf6d80e6a6ea25bfb4108919e8200e09598b7d984b61ab39c8a2475293
MD5 a51394e97312d9c7ef734e7d59f02ee4
BLAKE2b-256 09ef221dbc71387aba5994b2fffb39fdcfa5f78017779e3a549763cfcf75c691

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_ai-0.2.5-py3-none-any.whl:

Publisher: publish.yml on CodexDLC/codex-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

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