Skip to main content

Generate images from Python through Codex's Responses API bridge.

Project description

codex-image-gen

Python helpers for generating images through codex responses.

This package uses the Codex CLI as the transport. It sends a raw Responses API JSON payload to codex responses, which means authentication is handled by your existing Codex login rather than by an OPENAI_API_KEY.

Install

uv add codex-image-gen

For local development:

uv sync --dev

Usage

from pathlib import Path

from codex_image_gen import generate_image

result = generate_image(
    "Draw a small lighthouse on a cliff at sunrise",
    size="1024x1024",
    quality="medium",
)

image = result.images[0]
Path("lighthouse.png").write_bytes(image.data)

Reference images can be passed as local paths, http(s) URLs, data: URLs, or file IDs. Mapping inputs also support the Responses input_image.detail field:

result = generate_image(
    "Edit the reference image into a watercolor postcard",
    images=["reference.png", {"file_id": "file_123", "detail": "high"}],
    action="edit",
)

All Responses image generation tool options are exposed:

result = generate_image(
    "Edit the logo area and keep the product shape",
    images=["product.png"],
    input_image_mask="mask.png",
    moderation="low",
    partial_images=2,
    size="2048x2048",
    quality="high",
    output_format="webp",
    output_compression=70,
    background="opaque",
    action="edit",
)

for partial in result.partial_images:
    Path(f"partial-{partial.index}.webp").write_bytes(partial.data)

Notes

  • codex must be installed and logged in.
  • The default Responses model is gpt-5.4.
  • The image generation tool is fixed to gpt-image-2.
  • codex responses requires store=false, so prior response/item references are not exposed by this library. Use image bytes or file IDs as inputs for follow-up edits.
  • gpt-image-2 does not support background="transparent" or input_fidelity; the library does not expose input_fidelity and rejects transparent backgrounds before calling Codex.
  • partial_images are collected and returned after codex responses exits. This function does not expose a live streaming callback.
  • The package returns image bytes and metadata; it does not write files.
  • Tests mock codex responses and do not make live API calls.

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_image_gen-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

codex_image_gen-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file codex_image_gen-0.1.0.tar.gz.

File metadata

  • Download URL: codex_image_gen-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codex_image_gen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b92e430dbdd9d400923ac17fdd70cbde0a84caf3b4bc0fcceca858015b6270d
MD5 b473f14f4b8375f1054474d6ef02be3d
BLAKE2b-256 a1b945b9b0617c560b71281356040d2ac62dda63124588732bc6f2723956f80c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_image_gen-0.1.0.tar.gz:

Publisher: workflow.yml on smturtle2/codex-image-gen

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_image_gen-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_image_gen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c103ed712457b120fd691d12cbe52d8febf743ca873d11e1d898e3f779496f4
MD5 7446bfcbacc1c09d2e5035cc165437b0
BLAKE2b-256 ba733415e59b0e7a57517ba9780779205217df773e773ae57df578ccd45608a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_image_gen-0.1.0-py3-none-any.whl:

Publisher: workflow.yml on smturtle2/codex-image-gen

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