OPENAI WORKFLOW · 02 / 10

Authenticate OpenAI API requests securely

Keep the API key on your server and send it as a bearer credential.

Documentation checked · Loomwell editorial guide · Examples have not been live API tested.

Steps

  1. Load OPENAI_API_KEY from your deployment secret settings. The Python client reads it when initialized without an explicit key.
  2. For direct HTTP requests, supply Authorization: Bearer followed by the key. Keep it out of browser code, URLs, screenshots, and repository files.

Example

Python · Python API examples require OPENAI_API_KEY and OPENAI_MODEL in your server environment. API calls may incur OpenAI charges.

import os
from openai import OpenAI

if not os.environ.get("OPENAI_API_KEY"):
    raise RuntimeError("Configure OPENAI_API_KEY on the server")
client = OpenAI()

Check the result

This checks configuration only; it does not prove the key is valid. Use the first-response guide for an authenticated request. Never print the key while debugging.

Official source

OpenAI API authentication

Check current provider documentation and model support before deployment. This guide is separate from the approved evidence records listed in the catalog.

Use Loomwell with your coding agent

Inspect the published record coverage before starting a trial or connecting MCP.