RealComposer

OpenAI Safe & Unsafe Practices

Direct Answer

OpenAI API keys are server-only. Any key shipped in a browser or app can be extracted and used to run up your bill. Call OpenAI from a server or edge proxy, use project-scoped keys with spending limits, and enforce model and token caps on the server.

Credentials & Where They Belong

Server only
Project API key (sk-proj-)

Bills usage to your organization. Scope per project and environment.

Safe Practices

  • Fix model and max tokens on the server

    Clients send the user message only. The proxy chooses the model, system prompt, and output limits.

  • Use separate project keys with budgets

    Set monthly budgets and usage alerts per project so one leak cannot drain the whole org.

  • Authenticate and rate limit callers

    Require a client token or session and apply per-user limits before forwarding prompts.

Unsafe Practices

  • Using NEXT_PUBLIC_ or VITE_ variables for the key

    Build tools inline those into the bundle, where bots scrape them within minutes.

  • Letting the client choose model and parameters

    Attackers will switch to the most expensive model and max out token limits.

  • Forwarding raw OpenAI responses with usage metadata

    Return only the generated text the UI needs to keep payloads small.

The RealComposer Pattern

Store OPENAI_API_KEY in the vault, lock model and max tokens inside the pipeline config, and require an rc_live_ client token so only your app can call the endpoint.

START BUILDING FREE

Frequently Asked Questions

Q:Can I call the OpenAI API directly from React?

Not safely in production. The key would be visible to every visitor. Use a server or edge proxy that injects it.

Security & Secret Vault

How to Hide OpenAI API Key in Client-Side React Apps

To use OpenAI in a client-side React app without leaking your secret key, never include OPENAI_API_KEY or REACT_APP_OPENAI_API_KEY in frontend .env files. Instead, route your fetch calls through a RealComposer edge endpoint that injects your secret key server-side on Cloudflare Workers and enforces CORS origin whitelisting.

Sub-10ms edgeView Recipe
Security & Secret Vault

Call OpenAI API from WeWeb Securely

An OpenAI key pasted into a WeWeb REST action is published with the app and readable in DevTools. Send WeWeb requests to a RealComposer pipeline instead. The edge injects OPENAI_API_KEY from the vault, checks the calling origin, and returns only the assistant message text.

Sub-10ms edgeView Recipe
Security & Secret Vault

Hide OpenAI API Key in a Flutter App

OpenAI keys bundled in Flutter apps through env files, assets, or dart-define are extractable from release builds. Route chat requests through a RealComposer pipeline that injects OPENAI_API_KEY at the edge, applies per-client rate limits, and returns only the reply text to the app.

Sub-10ms edgeView Recipe

Related Concepts