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
Multi-API Aggregation

Combine Openai Embeddings and Supabase Vector Search in One Call

To solve combine openai embeddings and supabase vector search in one call, never execute unauthenticated requests or embed private tokens directly in client bundles. RealComposer acts as a sub-10ms edge gateway running on Cloudflare Workers that securely injects credentials from your Secret Vault, normalizes responses, and prevents unauthorized API usage. Route calls through your RealComposer edge URL to guarantee complete privacy, robust origin validation, and low mobile latency.

Sub-10ms edgeView Recipe

Related Concepts