Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(openai): avoid sdk transport for image generation

hugohe3aa1215f10f9f
diff --git a/skills/ppt-master/requirements.txt b/skills/ppt-master/requirements.txt
index 1259c053..8a6a3ab0 100644
--- a/skills/ppt-master/requirements.txt
+++ b/skills/ppt-master/requirements.txt
@@ -100,8 +100,8 @@ curl_cffi>=0.7.0
# ─────────────────────────────────────────────────────────────
# Gemini backend / Gemini 后端 (IMAGE_BACKEND=gemini)
google-genai>=1.0.0
-# OpenAI-compatible backend / OpenAI 兼容后端 (IMAGE_BACKEND=openai)
-openai>=1.0.0
+# OpenAI-compatible backend uses requests from the web tooling section above.
+# OpenAI 兼容后端复用上方网页工具所需的 requests。
# ─────────────────────────────────────────────────────────────
# SVG Editor / SVG 编辑器 (skills/ppt-master/scripts/svg_editor/server.py)
diff --git a/skills/ppt-master/scripts/docs/image.md b/skills/ppt-master/scripts/docs/image.md
index ecd3d3c1..6de16dde 100644
--- a/skills/ppt-master/scripts/docs/image.md
+++ b/skills/ppt-master/scripts/docs/image.md
@@ -101,6 +101,8 @@ Current process environment wins over `.env`.
OpenAI backend notes:
- `gpt-image-2` is the default OpenAI model.
+- Requests are sent with plain `requests.post()` to improve compatibility with
+ OpenAI-compatible proxies that block the OpenAI SDK's `httpx` transport.
- For `gpt-image-2`, `image_size=512px` means a low-quality draft preset, not a literal 512px edge. The model requires both edges to be multiples of 16px, a long:short ratio no greater than 3:1, and total pixels between 655,360 and 8,294,400.
- `OPENAI_BACKGROUND=transparent` is not supported by `gpt-image-2`; use `auto` or `opaque`.
- If `OPENAI_OUTPUT_FORMAT=jpeg` or `webp`, generated files use `.jpg` or `.webp` extensions instead of `.png`.
diff --git a/skills/ppt-master/scripts/docs/troubleshooting.md b/skills/ppt-master/scripts/docs/troubleshooting.md
index f53ef502..9b177146 100644
--- a/skills/ppt-master/scripts/docs/troubleshooting.md
+++ b/skills/ppt-master/scripts/docs/troubleshooting.md
@@ -77,4 +77,4 @@ Important optional packages:
- `Pillow` for image utilities
- `numpy` for watermark removal
- `PyMuPDF` for PDF conversion
-- `google-genai` / `openai` for image generation backends
+- `google-genai` for Gemini image generation
diff --git a/skills/ppt-master/scripts/image_backends/backend_openai.py b/skills/ppt-master/scripts/image_backends/backend_openai.py
index 6c835645..4ee19288 100644
--- a/skills/ppt-master/scripts/image_backends/backend_openai.py
+++ b/skills/ppt-master/scripts/image_backends/backend_openai.py
@@ -15,7 +15,7 @@ Configuration keys:
OPENAI_MODERATION (optional) auto or low for GPT image models
Dependencies:
- pip install openai Pillow
+ pip install requests Pillow
"""
import sys
@@ -31,10 +31,11 @@ import time
import threading
from collections.abc import Mapping
-from openai import OpenAI
+import requests
from image_backends.backend_common import (
MAX_RETRIES,
download_image,
+ http_error,
is_rate_limit_error,
normalize_image_size,
resolve_output_path,
@@ -137,6 +138,7 @@ GPT_IMAGE_OUTPUT_EXTENSIONS = {
}
GPT_IMAGE_BACKGROUNDS = {"auto", "opaque", "transparent"}
GPT_IMAGE_MODERATION_VALUES = {"auto", "low"}
+DEFAULT_BASE_URL = "https://api.openai.com/v1"
def _field(value, name: str):
@@ -264,6 +266,29 @@ def _gpt_image_options(model: str) -> tuple[dict, str]:
return options, output_ext
+def _image_generations_url(base_url: str | None) -> str:
+ return f"{(base_url or DEFAULT_BASE_URL).rstrip('/')}/images/generations"
+
+
+def _post_image_generation(api_key: str, base_url: str | None, request: dict) -> dict:
+ headers = {
+ "Authorization": f"Bearer {api_key}",
+ "Content-Type": "application/json",
+ }
+ response = requests.post(
+ _image_generations_url(base_url),
+ headers=headers,
+ json=request,
+ timeout=300,
+ )
+ if not response.ok:
+ raise http_error(response, "OpenAI image generation")
+ try:
+ return response.json()
+ except ValueError as exc:
+ raise RuntimeError("OpenAI image generation returned invalid JSON.") from exc
+
+
# ╔══════════════════════════════════════════════════════════════════╗
# ║ Image Generation ║
# ╚══════════════════════════════════════════════════════════════════╝
@@ -283,8 +308,6 @@ def _generate_image(api_key: str, prompt: str,
Raises:
RuntimeError: When generation fails
"""
- client = OpenAI(api_key=api_key, base_url=base_url)
-
# Map parameters
size = _select_size(model, aspect_ratio, image_size)
quality = IMAGE_SIZE_TO_QUALITY.get(image_size, "auto")
@@ -335,7 +358,7 @@ def _generate_image(api_key: str, prompt: str,
hb_thread.start()
try:
- resp = client.images.generate(**request)
+ resp = _post_image_generation(api_key, base_url, request)
finally:
heartbeat_stop.set()
hb_thread.join(timeout=1)
diff --git a/skills/ppt-master/scripts/image_gen.py b/skills/ppt-master/scripts/image_gen.py
index 01b81f78..2e9ab3de 100644
--- a/skills/ppt-master/scripts/image_gen.py
+++ b/skills/ppt-master/scripts/image_gen.py
@@ -6,7 +6,7 @@ Dispatches to the appropriate backend based on explicit provider configuration.
Backend selection (`IMAGE_BACKEND` in `.env` or the current process environment):
IMAGE_BACKEND=gemini -> Gemini backend (google-genai SDK)
- IMAGE_BACKEND=openai -> OpenAI-compatible backend (openai SDK)
+ IMAGE_BACKEND=openai -> OpenAI-compatible backend (raw HTTP via requests)
IMAGE_BACKEND=minimax -> MiniMax image backend
IMAGE_BACKEND=stability -> Stability AI backend
IMAGE_BACKEND=bfl -> Black Forest Labs FLUX backend