Skip to content

Migrate to new OpenAI SDK (Responses API) and upgrade dependencies#86

Open
yisding wants to merge 1 commit into
mainfrom
codex/modernize-application-codebase-with-gpt-5.5-rcn9vr
Open

Migrate to new OpenAI SDK (Responses API) and upgrade dependencies#86
yisding wants to merge 1 commit into
mainfrom
codex/modernize-application-codebase-with-gpt-5.5-rcn9vr

Conversation

@yisding
Copy link
Copy Markdown
Owner

@yisding yisding commented May 24, 2026

Motivation

  • Update the codebase to use the new openai SDK and the Responses API model for image generation and chat-style endpoints.
  • Bump multiple dependencies (Next, React, ESLint, Prettier, Tailwind, OpenAI client, etc.) to recent compatible versions.

Description

  • Replaced legacy OpenAIApi usage with the new OpenAI client and instantiated it via new OpenAI({ apiKey: process.env.OPENAI_API_KEY }) across API handlers.
  • Converted image generation to openai.images.generate with model: "gpt-image-1" and updated response extraction to response.data?.[0]?.url in pages/api/image.ts.
  • Rewrote text/chat endpoints (pages/api/wordgrade.ts, pages/api/wordpieces.ts, pages/api/words.ts) to call openai.responses.create using instructions + input and JSON schema formatting via the text.format block, then read response.output_text and JSON.parse it.
  • Upgraded package.json and package-lock.json with numerous dependency bumps (e.g. next, react, react-dom, openai, eslint, prettier, tailwindcss, @sentry/nextjs, etc.) and moved some previously top-level packages into devDependencies or updated their versions.

Testing

  • No automated tests were run as part of this change.

Codex Task

@yisding yisding marked this pull request as ready for review May 24, 2026 18:55
@yisding yisding requested a review from Copilot May 24, 2026 18:55
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28eeb59b9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pages/api/image.ts
});

res.status(200).json({ url: response.data.data[0].url });
res.status(200).json({ url: response.data?.[0]?.url });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return image bytes for gpt-image-1 instead of URL

Switching this endpoint to model: "gpt-image-1" but still reading response.data?.[0]?.url breaks image delivery, because GPT image models return base64 image data (b64_json) rather than a hosted URL. In practice this causes successful generations to come back with url: undefined, so clients that expect a usable image URL will fail for every request to this route.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the app’s Next.js API routes from the legacy OpenAI SDK (OpenAIApi / Chat Completions) to the newer openai client using the Responses API (structured JSON outputs) and updates image generation to openai.images.generate, alongside a broad dependency upgrade.

Changes:

  • Refactors /api/words, /api/wordpieces, and /api/wordgrade to use openai.responses.create with JSON schema formatting and output_text.
  • Updates /api/image to use openai.images.generate with the gpt-image-1 model.
  • Upgrades Next/React/OpenAI SDK and related tooling dependencies.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pages/api/words.ts Switches to Responses API with JSON schema formatted text output and parsing into word lists.
pages/api/wordpieces.ts Switches to Responses API with JSON schema formatted output for phoneme/character segmentation.
pages/api/wordgrade.ts Switches to Responses API with JSON schema formatted output for grade classification.
pages/api/image.ts Migrates image generation to openai.images.generate and updates response extraction.
package.json Upgrades major dependencies (Next/React/OpenAI SDK) and moves some tooling packages to devDependencies.
Comments suppressed due to low confidence (3)

pages/api/words.ts:114

  • JSON.parse(responseJson) can throw if the model returns non-JSON (or JSON with leading/trailing text). Right now that exception will bubble up and produce a 500 without a controlled error response. Wrap the parse (and ideally the OpenAI call) in try/catch and return a 502/503 with a helpful error message.
  const responseJson = response.output_text;

  if (!responseJson) {
    res.status(503).json({ error: "No response" });
    return;
  }

  const responseData: string[] = JSON.parse(responseJson);

pages/api/wordpieces.ts:115

  • JSON.parse(responseJson) is not guarded; if the model ever emits invalid JSON, this handler will throw and fail the request with an unhandled 500. Consider wrapping parsing (and the OpenAI call) in try/catch and returning a structured error response.
  const responseJson = response.output_text;

  if (!responseJson) {
    res.status(503).json({ error: "No response" });
    return;
  }

  const responseData: { characters: string; phonemes: string }[] =
    JSON.parse(responseJson);

pages/api/wordgrade.ts:68

  • JSON.parse(responseJson) is unguarded; any non-JSON output will throw and cause an unhandled 500. Wrap parsing (and/or the OpenAI request) in try/catch and return a controlled error response so the client can handle it.
  const responseJson = response.output_text;

  if (!responseJson) {
    res.status(503).json({ error: "No response" });
    return;
  }

  const responseData: { grade: string } = JSON.parse(responseJson);


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pages/api/wordpieces.ts
Comment on lines +36 to 38
Word: pig
Output: [ { "phonemes": "p", "characters": "p" }, { "phonemes": "ɪ", characters: "i" }, { "phonemes": "g", "characters": "g" } ]

Comment thread pages/api/wordpieces.ts
Comment on lines 39 to 41
Word: blue
Output: [ { "phonemes": "b", "characters": "b" }, { "phonemes": "l", characters: "l" }, { "phonemes": "u:", "characters": "ue" } ]

Comment thread pages/api/wordpieces.ts
Comment on lines 42 to +43
Word: happy
Output: [ { "phonemes": "h", "characters": "h" }, { "phonemes": "æ", characters: "a" }, { "phonemes": "p", "characters": "pp" },{ "phonemes": "i", "characters": "y" } ]`,
},
{
role: "user",
content: `Word: ${word}
Output:`,
},
];
Output: [ { "phonemes": "h", "characters": "h" }, { "phonemes": "æ", characters: "a" }, { "phonemes": "p", "characters": "pp" },{ "phonemes": "i", "characters": "y" } ]`;
Comment thread pages/api/image.ts
Comment on lines +24 to 31
const response = await openai.images.generate({
model: "gpt-image-1",
prompt: `clip art of ${word}`,
n: 1,
size: "256x256",
});

res.status(200).json({ url: response.data.data[0].url });
res.status(200).json({ url: response.data?.[0]?.url });
}
Copy link
Copy Markdown

@charliecreates charliecreates Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking feedback

  1. gpt-image-1 request/response handling here will break image delivery — .../api/image.ts#L24-L30

If you want me to push fixes, reply with item numbers (for example: please fix 1).

Comment thread pages/api/image.ts
model: "gpt-image-1",
prompt: `clip art of ${word}`,
n: 1,
size: "256x256",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gpt-image-1 does not support size: "256x256", and this model returns b64_json image bytes rather than url. With the current call shape, /api/image can fail validation or return { url: undefined }, so generated images will not render in the UI.

Suggested fix: use a GPT-image-supported size (for example 1024x1024 or auto) and return an image derived from b64_json (for example a data:image/png;base64,... URL or a stored asset URL). If this endpoint must keep hosted URL output at 256x256, use a DALL·E model instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants