diff --git a/gitbook/content/en/providers/subscription.md b/gitbook/content/en/providers/subscription.md index 830f429e..ffe5fb0d 100644 --- a/gitbook/content/en/providers/subscription.md +++ b/gitbook/content/en/providers/subscription.md @@ -111,6 +111,27 @@ Model: cx/gpt-5.2-codex | `cx/gpt-5.2` | GPT 5.2 | General tasks | | `cx/gpt-5.1-codex` | GPT 5.1 Codex | Stable coding | +### Image Generation + +The Codex image catalog includes `cx/gpt-5.6-sol-image`, +`cx/gpt-5.6-terra-image`, and `cx/gpt-5.6-luna-image`, alongside the existing +GPT 5.5, 5.4, and 5.3 image aliases. Select them under **Image → OpenAI Codex** +in the dashboard, or discover them with `GET /v1/models/image` after connecting +a Codex account. + +```bash +curl http://localhost:20128/v1/images/generations \ + -H "Authorization: Bearer $NINE_ROUTER_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{"model":"cx/gpt-5.6-sol-image","prompt":"A blue square","size":"1024x1024"}' +``` + +These are 9Router aliases: the image adapter removes `-image` and sends the +underlying model an `image_generation` tool through the Codex Responses API. +The same endpoint accepts an `image` reference for edits. Image generation +requires an eligible ChatGPT Plus or higher account; availability of each +underlying model and its image tool depends on the connected account. + ### Pro Tips - **5-hour rolling quota** - Fresh quota every 5 hours diff --git a/open-sse/providers/registry/codex.js b/open-sse/providers/registry/codex.js index 6fc7501d..427c47a4 100644 --- a/open-sse/providers/registry/codex.js +++ b/open-sse/providers/registry/codex.js @@ -59,6 +59,9 @@ export default { { id: "gpt-5.4-mini-review", name: "GPT 5.4 Mini Review", upstreamModelId: "gpt-5.4-mini", quotaFamily: "review" }, { id: "gpt-5.3-codex-spark", name: "GPT 5.3 Codex Spark" }, { id: "gpt-5.3-codex-spark-review", name: "GPT 5.3 Codex Spark Review", upstreamModelId: "gpt-5.3-codex-spark", quotaFamily: "review" }, + { id: "gpt-5.6-sol-image", name: "GPT 5.6 Sol Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, + { id: "gpt-5.6-terra-image", name: "GPT 5.6 Terra Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, + { id: "gpt-5.6-luna-image", name: "GPT 5.6 Luna Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, { id: "gpt-5.5-image", name: "GPT 5.5 Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, { id: "gpt-5.4-image", name: "GPT 5.4 Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, { id: "gpt-5.3-image", name: "GPT 5.3 Image", capabilities: ["text2img","edit"], params: ["size","quality","background","image_detail","output_format"], kind: "image" }, diff --git a/tests/unit/codex-image-models.test.js b/tests/unit/codex-image-models.test.js new file mode 100644 index 00000000..9a4e9c44 --- /dev/null +++ b/tests/unit/codex-image-models.test.js @@ -0,0 +1,76 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { getModelsByProviderId, getModelType, isValidModel } from "../../open-sse/config/providerModels.js"; +import { getModelInfoCore } from "../../open-sse/services/model.js"; +import { handleImageGenerationCore } from "../../open-sse/handlers/imageGenerationCore.js"; + +const models = ["gpt-5.6-sol", "gpt-5.6-luna", "gpt-5.6-terra"]; + +afterEach(() => vi.unstubAllGlobals()); + +describe("Codex GPT-5.6 image models", () => { + it.each(models)("exposes %s-image as an image model while retaining its chat entry", (model) => { + const catalog = getModelsByProviderId("codex"); + expect(catalog.filter((entry) => entry.id === `${model}-image`)).toHaveLength(1); + expect(catalog.find((entry) => entry.id === `${model}-image`)).toMatchObject({ + kind: "image", + capabilities: ["text2img", "edit"], + params: ["size", "quality", "background", "image_detail", "output_format"], + }); + expect(isValidModel("cx", `${model}-image`)).toBe(true); + expect(getModelType("cx", `${model}-image`)).toBe("image"); + expect(catalog.find((entry) => entry.id === model)).toBeDefined(); + expect(getModelType("cx", model)).not.toBe("image"); + }); + + it.each(models)("routes %s-image edits and streams image events", async (model) => { + const events = [ + ["response.image_generation_call.partial_image", { partial_image_b64: "cGFydGlhbA==", partial_image_index: 0 }], + ["response.output_item.done", { item: { type: "image_generation_call", result: "ZmluYWw=" } }], + ]; + const fetchMock = vi.fn().mockResolvedValue(new Response( + events.map(([event, data]) => `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`).join(""), + { headers: { "Content-Type": "text/event-stream" } }, + )); + vi.stubGlobal("fetch", fetchMock); + const onRequestSuccess = vi.fn(); + const modelInfo = await getModelInfoCore(`cx/${model}-image`); + expect(modelInfo).toEqual({ provider: "codex", model: `${model}-image` }); + expect(await getModelInfoCore(`codex/${model}-image`)).toEqual(modelInfo); + + const result = await handleImageGenerationCore({ + modelInfo, + body: { + prompt: "Make the square blue", + image: "data:image/png;base64,cmVmZXJlbmNl", + image_detail: "low", + size: "1024x1024", + quality: "high", + background: "transparent", + output_format: "WEBP", + }, + credentials: { accessToken: "test-token" }, + streamToClient: true, + onRequestSuccess, + }); + + expect(result.success).toBe(true); + expect(result.response.status).toBe(200); + expect(result.response.headers.get("content-type")).toBe("text/event-stream"); + const [url, options] = fetchMock.mock.calls[0]; + expect(url).toBe("https://chatgpt.com/backend-api/codex/responses"); + const upstreamBody = JSON.parse(options.body); + expect(upstreamBody.model).toBe(model); + expect(upstreamBody.tools).toEqual([{ + type: "image_generation", output_format: "webp", size: "1024x1024", + quality: "high", background: "transparent", + }]); + expect(upstreamBody.input[0].content).toContainEqual({ + type: "input_image", image_url: "data:image/png;base64,cmVmZXJlbmNl", detail: "low", + }); + const stream = await result.response.text(); + expect(stream).toContain('event: partial_image\ndata: {"b64_json":"cGFydGlhbA==","index":0}'); + expect(stream).toContain("event: done\n"); + expect(stream).toContain('"data":[{"b64_json":"ZmluYWw="}]'); + expect(onRequestSuccess).toHaveBeenCalledTimes(1); + }); +}); diff --git a/tests/unit/image-generation.test.js b/tests/unit/image-generation.test.js index e5504aec..12dce95d 100644 --- a/tests/unit/image-generation.test.js +++ b/tests/unit/image-generation.test.js @@ -316,7 +316,7 @@ describe("handleImageGenerationCore", () => { expect(responseBody.data[0].b64_json).toBeTruthy(); }); - it("generates image with Codex gpt-5.5-image using current Codex version header", async () => { + it.each(["gpt-5.5", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"])("generates image with Codex %s-image using current Codex version header", async (model) => { global.fetch.mockResolvedValueOnce( new Response( [ @@ -335,7 +335,7 @@ describe("handleImageGenerationCore", () => { size: "1024x1024", output_format: "png", }, - modelInfo: { provider: "codex", model: "gpt-5.5-image" }, + modelInfo: { provider: "codex", model: `${model}-image` }, credentials: { accessToken: "codex-token", providerSpecificData: { chatgptAccountId: "account-123" }, @@ -358,7 +358,7 @@ describe("handleImageGenerationCore", () => { const fetchCall = global.fetch.mock.calls[0]; const requestBody = JSON.parse(fetchCall[1].body); - expect(requestBody.model).toBe("gpt-5.5"); + expect(requestBody.model).toBe(model); expect(requestBody.tools).toEqual([ { type: "image_generation", output_format: "png", size: "1024x1024" }, ]);