ChatImg
ChatImg 是 ChatArch 的图片生成包,承接原 chattool image 中已经解耦的 provider 实现。
当前支持:
openai/crs:OpenAI-compatible Images API,走OPENAI_API_KEY,请求/v1/images/generations。codex/openai-codex:ChatGPT/Codex OAuth image bridge,复用 ChatEnvOpenAIprofile + runtime token-store,支持gpt-image-2-*preset。pollinations:Pollinations.ai image URL generation and model listing。siliconflow:SiliconFlow OpenAI-compatible image generation。huggingface:Hugging Face Inference image generation。liblib:LiblibAI signed API generation。tongyi:通义万相 / DashScope image generation。
安装
开发安装:
pip install -e ".[dev]"
通义万相 SDK 可选依赖:
pip install -e ".[images]"
CLI
chatimg --help
chatimg --version
chatimg --tree
chatimg openai generate "a small red apple icon" -o apple.png
chatimg codex auth-status --profile work
chatimg codex auth-refresh --profile work
chatimg codex list-models
chatimg pollinations list-models
生成示例:
chatimg openai generate "a watercolor fox in the snow" --model gpt-image-2-medium --size 1024x1024 -o fox.png
chatimg codex generate "a watercolor fox in the snow" --profile work --aspect-ratio square -o fox-codex.png
chatimg pollinations generate "a cyberpunk cat" --model flux --width 512 --height 512 -o cat.png
chatimg siliconflow generate "a cute dog" --size 1024x1024 -o dog.png
chatimg huggingface generate "A futuristic city at night" -o city.png
chatimg liblib generate "A cute dog" --model-id liblib-sdxl-model -o dog.png
chatimg tongyi generate "一只赛博朋克猫" --size "1024*1024" -o cat.png
OpenAI-compatible / CRS Images API
openai provider 对齐 OpenAI 官方 Images API:POST {OPENAI_API_BASE}/images/generations。官方 base 是 https://api.openai.com/v1,因此完整官方接口是 https://api.openai.com/v1/images/generations。CRS 兼容服务可用自己的带 /v1 base,例如 https://crs.example/openai/v1。
常用配置字段:
OPENAI_API_BASE:OpenAI-compatible API base,必须包含/v1。OPENAI_API_KEY:API key;不会 fallback 到 access token。OPENAI_IMAGE_MODEL:默认 image preset,例如gpt-image-2-medium,会拆成model=gpt-image-2与quality=medium。
chatenv use -t oai apple
chatimg openai generate "a small red apple icon" -o apple.png
CRS 验收建议分两步:先用同一个 API key 调普通 /responses 模型确认 key、账号绑定和模型路由,再调用 Images API。客户端始终只持有 OPENAI_API_KEY,不会读取或 fallback 到 OAuth access token。
chatimg openai generate \
"A simple orange paper airplane over a pale blue grid, no text" \
--model gpt-image-2-low \
--quality low \
--size 1024x1024 \
-o generated/crs-api-key-image.png
Codex / GPT Image2 实测示例
codex provider 走 ChatGPT/Codex OAuth-backed Responses API,请求里的 image tool model 是 gpt-image-2。它不是外部 Codex CLI。
chatimg codex 现在复用 ChatEnv 的 OpenAI profile 和 runtime token-store,不再需要维护单独的 Codex env 文件:
- runtime token-store:
~/.chatarch/tokens/OpenAI/<profile>.json,包含 access/refresh token 等动态状态,并且优先级最高。 - stable seed:
~/.chatarch/envs/OpenAI/<profile>.env(defaultprofile 使用 activeOpenAI/.env),只放 OAuth/backend/model seed 或 fallback。 - 常用 seed 字段:
OPENAI_OAUTH_BASE_URL、CHATGPT_BACKEND_BASE_URL、OPENAI_API_MODEL、OPENAI_IMAGE_MODEL。 - 请求地址默认由
CHATGPT_BACKEND_BASE_URL组合为${CHATGPT_BACKEND_BASE_URL}/codex/responses。 openai/crsAPI-key provider 仍只读取OPENAI_API_KEY,不会 fallback 到 OAuth token。
可以显式指定 OpenAI profile:
chatimg codex auth-status --profile work
chatimg codex auth-refresh --profile work
chatimg codex generate "a small orange paper airplane" \
--profile work \
--host-model gpt-5.5 \
--image-model gpt-image-2-low \
-o generated/codex-image.png
基础验收图:
chatimg codex generate \
"A clean minimal ChatImg acceptance test illustration: a friendly robot holding a small picture frame, modern flat design, white background, no text" \
--image-model gpt-image-2-low \
--aspect-ratio square \
-o generated/chatimg-gpt-image2-basic.png \
--timeout 300
快速排序流程图:
chatimg codex generate \
"Create a clean landscape technical design flowchart explaining quicksort. Use this exact example array: [6, 3, 8, 5, 1, 10, 2]. Pick pivot = 5. Partition correctly: left part [3, 1, 2] labeled < pivot, right part [6, 8, 10] labeled > pivot. Include steps: START, base case length <= 1?, pick pivot, partition array, recursively sort left part, recursively sort right part, concatenate sorted-left + pivot + sorted-right, END. Modern vector style, white background, blue/orange accents, arrows, decision diamond, readable simple English labels. Avoid mathematical mistakes." \
--image-model gpt-image-2-medium \
--aspect-ratio landscape \
-o generated/chatimg-gpt-image2-quicksort-flowchart.png \
--timeout 300
Python API
from chatimg.image import create_generator
generator = create_generator("codex", profile="work")
result = generator.generate("A cute cat astronaut")
配置
ChatImg 注册了 chatenv.configs entry point:
chatimg = "chatimg.config"
支持的主要环境变量:
OPENAI_API_BASE,OPENAI_API_KEY,OPENAI_IMAGE_MODELOPENAI_OAUTH_BASE_URL,CHATGPT_BACKEND_BASE_URL,OPENAI_API_MODEL,OPENAI_IMAGE_MODEL作为OpenAIprofile seed;runtime OAuth tokens 由tokens/OpenAI/<profile>.json管理POLLINATIONS_API_KEY,POLLINATIONS_MODEL_IDSILICONFLOW_API_KEY,SILICONFLOW_MODEL_IDHUGGINGFACE_HUB_TOKENLIBLIB_ACCESS_KEY,LIBLIB_SECRET_KEY,LIBLIB_MODEL_IDDASHSCOPE_API_KEY
开发验证
PYTHONPATH=src python -m pytest -q
PYTHONPATH=src python -m chatimg.cli --help
PYTHONPATH=src python -m chatimg.cli --tree
PYTHONPATH=src python -m chatimg.cli codex list-models
python -m build
python -m twine check dist/*
发布状态
PyPI ChatImg 从 0.1.x 开始发布功能版本;0.1.5 将 chatimg codex 切到 ChatEnv OpenAI profile + tokens/OpenAI/<profile>.json token-store,并补齐 --profile。
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 chatimg-0.1.5.tar.gz.
File metadata
- Download URL: chatimg-0.1.5.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a7df4b83d5d2d5b39044bfa5125593bbd666328c0285191ce84b5bdf599fe76
|
|
| MD5 |
c659364bd7b092b3eaf3dbe383c02f85
|
|
| BLAKE2b-256 |
66dad69ce6df4ef1719df5dba89d5316432862815439517f4de2fd20e449defe
|
Provenance
The following attestation bundles were made for chatimg-0.1.5.tar.gz:
Publisher:
publish.yml on ChatArch/ChatImg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chatimg-0.1.5.tar.gz -
Subject digest:
0a7df4b83d5d2d5b39044bfa5125593bbd666328c0285191ce84b5bdf599fe76 - Sigstore transparency entry: 2449283994
- Sigstore integration time:
-
Permalink:
ChatArch/ChatImg@cf5814963d903cf378daf7e7e49e5ea6ed874728 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/ChatArch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf5814963d903cf378daf7e7e49e5ea6ed874728 -
Trigger Event:
push
-
Statement type:
File details
Details for the file chatimg-0.1.5-py3-none-any.whl.
File metadata
- Download URL: chatimg-0.1.5-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a4986e34bfbe53c11ea183876776c80e277c6680b66b743d5c7a45e44826a17
|
|
| MD5 |
cb5afa2041dab0b7018b88f762e35686
|
|
| BLAKE2b-256 |
71576fe16c8b598eeddd6aef77cbb731d929504aff810c415750600ff5d4a6ff
|
Provenance
The following attestation bundles were made for chatimg-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on ChatArch/ChatImg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chatimg-0.1.5-py3-none-any.whl -
Subject digest:
7a4986e34bfbe53c11ea183876776c80e277c6680b66b743d5c7a45e44826a17 - Sigstore transparency entry: 2449284009
- Sigstore integration time:
-
Permalink:
ChatArch/ChatImg@cf5814963d903cf378daf7e7e49e5ea6ed874728 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/ChatArch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf5814963d903cf378daf7e7e49e5ea6ed874728 -
Trigger Event:
push
-
Statement type: