Skip to content

Keep the API key out of browser code in the SDXL Turbo web app tutorial - #986

Merged
lavanya-gunreddi merged 2 commits into
mainfrom
promptless/sdxl-turbo-backend-api-key
Nov 20, 2026
Merged

lavanya-gunreddi merged 2 commits into
mainfrom
promptless/sdxl-turbo-backend-api-key

Conversation

@promptless

@promptless promptless Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Open in Promptless

The "Integrate Serverless with a web application" tutorial put a Runpod API key in script.js, which runs in the browser, and only warned about it after the code. Anyone who followed the tutorial and deployed the result would ship a key that can create, modify, and delete resources on their account to every visitor. This also contradicted the tutorial's own advice in step 2.

This change reworks the tutorial so the key never reaches the browser:

  • script.js posts {"prompt": ...} to /api/generate on the same origin and renders the returned base64 PNG. It has no API key, no api.runpod.ai URL, and no authorization header.
  • A new server.py Flask backend serves the frontend, reads RUNPOD_ENDPOINT_ID and RUNPOD_API_KEY from environment variables, calls /runsync, and returns only output.images[0].image.
  • Step 5 installs Flask and requests, sets the environment variables (bash and PowerShell), runs flask --app server run --port 8000, and opens http://localhost:8000. The "open the HTML file directly" option is removed, with a Note explaining that a file:// page can't reach /api/generate.
  • The step 2 Tip becomes a Warning that states what an API key can do.
  • Requirements add Python 3.8 or later, the intro describes the backend, and a "What you'll learn" section is added per the tutorial style guide.

Fixes DOCS-557.

Verification: extracted the three files from the page and ran them. node --check passes on script.js. A Flask test client with a mocked Runpod API confirmed /api/generate sends {"input": {"prompt": ...}} to https://api.runpod.ai/v2/{ENDPOINT_ID}/runsync with the bearer header and returns {"image": ...}, returns 400 for an empty prompt, and serves / and /script.js. flask --app server run --port 8000 starts and serves the page. The tooltip and redirect validation scripts pass. No live endpoint call was made.

Trigger Events


Tip: Assign suggestions to team members in the Promptless dashboard to claim work 👥

@mintlify

mintlify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
runpod-docs 🟢 Ready View Preview Nov 20, 2026, 8:55 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@lavanya-gunreddi
lavanya-gunreddi merged commit 80c0c09 into main Nov 20, 2026
2 checks passed
@lavanya-gunreddi
lavanya-gunreddi deleted the promptless/sdxl-turbo-backend-api-key branch November 20, 2026 20:59

This branch was successfully deployed

1 active deployment
staging — e54ad02c Deployed Nov 20, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant