Skip to content

Integrate OpenAI Responses API for image-based solving with gpt-5-nano#2

Merged
brawliscool merged 1 commit into
mainfrom
codex/set-api-to-use-gpt-5-nano-model
Feb 24, 2026
Merged

Integrate OpenAI Responses API for image-based solving with gpt-5-nano#2
brawliscool merged 1 commit into
mainfrom
codex/set-api-to-use-gpt-5-nano-model

Conversation

@brawliscool
Copy link
Copy Markdown
Owner

Motivation

  • Replace the previous hard-coded demo solver with a live model call so users get actual AI-generated step-by-step solutions from uploaded images.
  • Allow users to supply their own OpenAI API key at runtime rather than baking credentials into source.
  • Ensure the solver returns structured data (problem + steps) so the UI can render reliable results.

Description

  • Added OPENAI_API_KEY_STORAGE_KEY and OPENAI_MODEL constants and a getOpenAiApiKey helper that prompts once and caches the key in localStorage.
  • Implemented generateSolutionWithOpenAI(imageDataUrl, apiKey) which calls https://api.openai.com/v1/responses using fetch, sends the image as input_image, and parses data.output_text as JSON containing problem and steps.
  • Converted the solve flow to an async handler for the solve button and replaced the hard-coded demo solution with a call to generateSolutionWithOpenAI using the configured model gpt-5-nano-2025-08-07.
  • Added failure handling that restores a spent credit, clears the loading state, shows an error toast, and leaves the UI ready for a retry.

Testing

  • Ran node --check script.js to validate there are no syntax errors, and it completed successfully.

Codex Task

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: e87d117dfc

ℹ️ 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 script.js

const getOpenAiApiKey = () => {
let apiKey = localStorage.getItem(OPENAI_API_KEY_STORAGE_KEY) || "";
if (apiKey) return apiKey;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-prompt for API key after auth failures

getOpenAiApiKey always returns the cached key once it exists, so if a user initially enters a mistyped/revoked key, every future solve attempt keeps reusing that invalid credential and fails (typically 401) without ever prompting for a replacement. Since this flow has no in-app reset for OPENAI_API_KEY_STORAGE_KEY, users can be stuck in a permanent failure loop until they manually clear local storage.

Useful? React with 👍 / 👎.

@brawliscool brawliscool merged commit d2f6df3 into main Feb 24, 2026
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.

1 participant