Skip to main content

Gemini-first and OpenAI provider helpers for Codex

Project description

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 remains as a small text-only adapter, and 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 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(
    "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"},
)

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. Use generate_imagen_bytes() for Imagen models; that path uses generate_images and passes the requested MIME as output_mime_type.

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] Text-only OpenAI Chat Completions 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

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

codex_ai-0.2.4.tar.gz (132.3 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.4-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file codex_ai-0.2.4.tar.gz.

File metadata

  • Download URL: codex_ai-0.2.4.tar.gz
  • Upload date:
  • Size: 132.3 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.4.tar.gz
Algorithm Hash digest
SHA256 68fb08d3235c364f8f1a4f8eaa175fc7bedaa62e1513ee043bafe2fde62a0434
MD5 1014d5edfe2077072b06d5cefbfc1024
BLAKE2b-256 3bb546dd9f2b9a1bbc2ee41e0bb760a894887dee476b1d5f783cdc6033a251e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_ai-0.2.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: codex_ai-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 174fb2645df06ab33e8ded65bc6eefab48bd55df81ac63043cf9dd6684476f01
MD5 9f529faa987823f445c61b7c440cfd47
BLAKE2b-256 a293b8de5a746be97bc4dfa123a03b8d0ddefb94b7f03f0a6cfebcf82f371eab

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_ai-0.2.4-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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page