Skip to content

Commit 64fb4a1

Browse files
authored
Merge pull request #3741 from kev1n77/codex/chatgpt-standalone-images
fix(images): use standalone Images requests for ChatGPT subscriptions
2 parents 3ad73a2 + 83a83f7 commit 64fb4a1

13 files changed

Lines changed: 288 additions & 342 deletions

File tree

‎src/crates/adapters/ai-adapters/AGENTS.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,15 @@ and sends no inference request. This does not verify remote-host behavior.
376376
The image-generation filter uses synthetic HTTP credentials. The ignored Codex
377377
probe requires a real in-app subscription login and generates a billed image;
378378
run it explicitly only when live provider validation is needed.
379+
Set `PROBE_CODEX_IMAGE_OUTPUT_DIR` to save the generated image for visual review.
380+
Set `PROBE_CODEX_IMAGE_OUTPUT_FORMAT=gif` to request GIF output and
381+
`PROBE_CODEX_IMAGE_PROMPT` to describe the subject and looping motion. The probe
382+
checks the GIF signature; inspect frame count and timing in the saved file to
383+
confirm animation.
384+
The probe uses the production standalone subscription Images route and built-in
385+
image model. It does not discover or invoke a chat model. Saved legacy
386+
`/responses` endpoints are translated in memory to `/images/generations`.
387+
388+
```bash
389+
cargo test --locked -p openbitfun-ai-adapters --features image-generation,subscription-auth --lib client::image_generation::tests::probe_codex_subscription_image_generation -- --ignored --exact --nocapture
390+
```

‎src/crates/adapters/ai-adapters/src/client/image_generation.rs‎

Lines changed: 216 additions & 317 deletions
Large diffs are not rendered by default.

‎src/crates/assembly/core/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ For image-service selection and compatibility with saved subscription configurat
256256

257257
```bash
258258
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation,subscription-auth --lib agentic::image_generation::tests
259+
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation --lib agentic::tools::implementations::generate_image_tool::tests
259260
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation --lib agentic::tools::product_runtime::materialization::tests::image_tools_follow_independent_compiled_owners
260261
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-analysis --lib agentic::tools::product_runtime::materialization::tests::image_tools_follow_independent_compiled_owners
261262
```

‎src/crates/assembly/core/src/agentic/image_generation/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ fn service_with_auth_route(service: &ImageServiceConfig) -> ImageServiceConfig {
147147
service.dialect = ImageDialect::ChatgptCodex;
148148
service.base_url.clear();
149149
service.request_url = None;
150-
// An image-model ID cannot drive a Responses tool call. Resolve a chat
151-
// model from this subscription's live catalog instead.
150+
// The subscription Images adapter owns the image model. Keep the legacy
151+
// model slot empty in the resolved view without rewriting stored data.
152152
service.model_name.clear();
153153
service.params.n = Some(1);
154154
}

‎src/crates/assembly/core/src/agentic/tools/implementations/generate_image_tool.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl Tool for GenerateImageTool {
267267
"service_id": {"type": "string"},
268268
"service": {"type": "string"},
269269
"dialect": {"type": "string"},
270-
"model": {"type": "string"},
270+
"model": {"type": "string", "description": "Model ID requested from the image service."},
271271
"mime_type": {"type": "string"},
272272
"bytes": {"type": "integer", "minimum": 0, "description": "Byte length of the first generated image."},
273273
"summary": {"type": "string"}
@@ -368,7 +368,7 @@ impl Tool for GenerateImageTool {
368368
"service_id": resolved.service.id,
369369
"service": resolved.service.name,
370370
"dialect": format!("{:?}", resolved.service.dialect),
371-
"model": resolved.service.model_name,
371+
"model": target.requested_model(),
372372
"mime_type": persisted[0].mime,
373373
"bytes": persisted[0].bytes,
374374
"summary": summary,

‎src/crates/contracts/core-types/AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ node scripts/check-core-boundaries.mjs
2828
```
2929

3030
For documentation-only changes, run `git diff --check`.
31+
32+
For persisted image dialect values and endpoint compatibility, run
33+
`cargo test --locked -p openbitfun-core-types --lib ai::image_dialect_compatibility`.

‎src/crates/contracts/core-types/src/ai.rs‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,11 @@ pub enum ImageDialect {
920920
/// `POST {base}/services/aigc/multimodal-generation/generation`.
921921
#[serde(rename = "dashscope_native")]
922922
DashScopeNative,
923-
/// ChatGPT subscription images, driven through Codex CLI's ChatGPT backend:
924-
/// `POST {base}/responses` with an `image_generation` tool, streamed back as
925-
/// SSE `response.output_item.done` items. This is a separate billing and
926-
/// protocol path from [`Self::OpenAiImages`]: it takes the OAuth access token
927-
/// from a Codex subscription login and never reaches the platform image API.
923+
/// ChatGPT subscription images through the Codex subscription backend:
924+
/// `POST {base}/images/generations` with a standalone Images JSON body.
925+
/// This is a separate billing and protocol path from [`Self::OpenAiImages`]:
926+
/// it takes the OAuth access token from a Codex subscription login and never
927+
/// reaches the platform image API.
928928
#[serde(rename = "chatgpt_codex")]
929929
ChatgptCodex,
930930
}
@@ -935,7 +935,7 @@ impl ImageDialect {
935935
match self {
936936
Self::OpenAiImages => "/images/generations",
937937
Self::DashScopeNative => "/services/aigc/multimodal-generation/generation",
938-
Self::ChatgptCodex => "/responses",
938+
Self::ChatgptCodex => "/images/generations",
939939
}
940940
}
941941

@@ -944,7 +944,7 @@ impl ImageDialect {
944944
match self {
945945
Self::OpenAiImages => MAX_IMAGES_PER_GENERATION_REQUEST,
946946
Self::DashScopeNative => 6,
947-
// The subscription route returns one image per tool call.
947+
// The subscription route generates one image per request.
948948
Self::ChatgptCodex => 1,
949949
}
950950
}
@@ -956,6 +956,21 @@ impl ImageDialect {
956956
}
957957
}
958958

959+
#[cfg(test)]
960+
mod image_dialect_compatibility {
961+
use super::ImageDialect;
962+
963+
#[test]
964+
fn subscription_wire_value_survives_the_images_endpoint_upgrade() {
965+
let legacy = r#""chatgpt_codex""#;
966+
let dialect: ImageDialect = serde_json::from_str(legacy).unwrap();
967+
assert_eq!(serde_json::to_string(&dialect).unwrap(), legacy);
968+
assert_eq!(dialect.endpoint_path(), "/images/generations");
969+
assert!(dialect.requires_subscription());
970+
assert_eq!(dialect.max_images_per_request(), 1);
971+
}
972+
}
973+
959974
#[cfg(test)]
960975
mod remote_model_routing_compatibility {
961976
#[test]

‎src/web-ui/src/infrastructure/config/components/image-generation/imageDialects.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('image service authentication routing', () => {
1919
const result = withImageServiceAuth(legacyService, { type: 'subscription', provider: 'codex' });
2020
expect(result).toMatchObject({ id: 'saved-service', dialect: 'chatgpt_codex', model_name: '', params: { n: 1 } });
2121
expect(resolveImageEndpoint(result.base_url, result.request_url, result.dialect))
22-
.toBe('https://chatgpt.com/backend-api/codex/responses');
22+
.toBe('https://chatgpt.com/backend-api/codex/images/generations');
2323
expect(legacyService.request_url).toBe('https://api.openai.com/v1/images/generations');
2424
});
2525

@@ -36,10 +36,23 @@ describe('image service authentication routing', () => {
3636
expect(resolveImageEndpoint(result.base_url, result.request_url, result.dialect)).toBe('https://api.openai.com/v1/images/generations');
3737
});
3838

39-
it('preserves custom API-key gateways and explicitly chosen subscription models', () => {
39+
it('preserves custom API-key gateways and legacy subscription model slots', () => {
4040
expect(withImageServiceAuth(legacyService, { type: 'api_key' })).toEqual(legacyService);
4141
const auth = { type: 'subscription' as const, provider: 'codex' as const };
4242
const service = { ...withImageServiceAuth(legacyService, auth), model_name: 'account-model' };
4343
expect(withImageServiceAuth(service, auth).model_name).toBe('account-model');
4444
});
45+
46+
it('resolves old subscription endpoints without rewriting serialized settings', () => {
47+
const root = 'https://chatgpt.com/backend-api/codex';
48+
const auth = { type: 'subscription' as const, provider: 'codex' as const };
49+
const saved = JSON.parse(JSON.stringify({ ...withImageServiceAuth(legacyService, auth),
50+
request_url: `${root}/responses`, model_name: 'gpt-6.1-sol' }));
51+
const snapshot = JSON.stringify(saved);
52+
expect(resolveImageEndpoint(saved.base_url, saved.request_url, saved.dialect)).toBe(`${root}/images/generations`);
53+
expect(resolveImageEndpoint(`${root}/responses/`, undefined, 'chatgpt_codex')).toBe(`${root}/images/generations`);
54+
expect(resolveImageEndpoint(`${root}/images/generations`, undefined, 'chatgpt_codex')).toBe(`${root}/images/generations`);
55+
expect(JSON.stringify(saved)).toBe(snapshot);
56+
expect(resolveImageEndpoint(root, `${root}/responses`, 'openai_images')).toBe(`${root}/responses`);
57+
});
4558
});

‎src/web-ui/src/infrastructure/config/components/image-generation/imageDialects.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export const IMAGE_DIALECT_PRESETS: readonly ImageDialectPreset[] = [
7272
id: 'chatgpt_codex',
7373
labelKey: 'dialect.chatgptCodex.name',
7474
descriptionKey: 'dialect.chatgptCodex.description',
75-
endpointPath: '/responses',
75+
endpointPath: '/images/generations',
7676
// The login supplies this address; the value here only seeds a new draft.
7777
defaultBaseUrl: 'https://chatgpt.com/backend-api/codex',
78-
// Empty means "discover from the account catalog when sending".
78+
// The subscription adapter owns the image model; legacy chat model IDs stay readable.
7979
defaultModel: '',
8080
sizes: ['1024x1024', '1536x1024', '1024x1536'],
8181
maxImagesPerRequest: 1,
@@ -121,9 +121,12 @@ export function resolveImageEndpoint(
121121
dialect: ImageDialect,
122122
): string {
123123
const override = requestUrl?.trim();
124-
if (override) return override;
124+
const subscriptionUrl = (url: string) => dialect === 'chatgpt_codex'
125+
? url.replace(/\/responses\/?$/, '/images/generations')
126+
: url;
127+
if (override) return subscriptionUrl(override);
125128

126-
const root = baseUrl.trim().replace(/\/+$/, '');
129+
const root = subscriptionUrl(baseUrl.trim().replace(/\/+$/, ''));
127130
if (!root) return '';
128131
const path = findImageDialectPreset(dialect).endpointPath;
129132
return root.endsWith(path) ? root : `${root}${path}`;

‎src/web-ui/src/infrastructure/config/types/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ export interface DefaultModelsConfig {
386386
/**
387387
* Image request protocol.
388388
*
389-
* `chatgpt_codex` is the subscription route: it drives a chat model's
390-
* `image_generation` tool over the provider's own backend and never touches the
389+
* `chatgpt_codex` sends standalone Images JSON requests using the subscription
390+
* login over the provider's own backend and never touches the
391391
* API-key image endpoint.
392392
*/
393393
export type ImageDialect = 'openai_images' | 'dashscope_native' | 'chatgpt_codex';

0 commit comments

Comments
 (0)