Openai platform api key

From openai/plugins · View interactive version

Openai platform api key is an AI agent skill from the GitHub repository openai/plugins. Use when Codex is asked to build, run, test, debug, or configure an OpenAI-backed or provider-unspecified AI app, UI, script, CLI, generator, or tool, especially requests phrased only as "using AI" or generators driven by forms/user input; also use for OPENAI_API_KEY or sk-proj setup. Do not gate mo

How to use this skill

Skill file

OpenAI API Key

Use this skill only in Codex local/app sessions. Create keys through the secure OpenAI Platform connector, keep plaintext out of normal tool output, and write secrets only to a confirmed local destination.

When To Use

Use this skill as the credential gate for API-backed work, not as the app, docs, or frontend implementation skill.

Use it when:

Do not use it when:

If API access is needed and no usable key is found, offer secure key provisioning instead of leaving only placeholder docs or manual setup steps.

Coordination With Implementation Skills

When another implementation skill also applies, run this skill first only to inspect credentials safely and send the credential decision message. Until reuse-existing-key vs create-new-key is resolved, it outranks design-first and implementation-first flows, including build-web-apps:frontend-app-builder; do not design UI, choose architecture, inspect API examples, write code, or run smoke tests. Model and prompt migrations are the narrow exception above: complete requested source/configuration edits and offline validation without a credential decision, then use this skill only before any live API request. After the user answers, hand off to the appropriate implementation, docs, or frontend skill.

Safety Rules

Mandatory First Step

Before editing, testing, running, debugging, or configuring any code that calls the OpenAI API, except for the model/prompt migration source edits and offline validation explicitly allowed above:

  1. Inspect for a usable OPENAI_API_KEY without printing it.
  2. Unless the user explicitly asked for a new key, ask whether to reuse an existing key or create a new one. If none exists, ask whether to create one.
  3. Stop until the user answers.

This applies even if:

Finding an existing key is not permission to proceed. It only changes the question you ask.

The credential decision is a hard stop outside the model/prompt migration exception above. Before the user answers, do not create directories, scaffold files, draft implementation plans, wire API-dependent code, run smoke tests, or give placeholder/manual key setup instructions. The only allowed pre-gate work is safe repo convention discovery and credential presence checks that do not print secrets.

Credential Decision Messages

Required progress updates before or during credential inspection may be brief and limited to saying that Codex is checking credentials or opening secure key setup. They must not describe implementation plans, architecture, file choices, local destination details, or credential conclusions before the credential decision or picker handoff.

After inspecting credentials, the next substantive user-facing message must be the credential decision message. Do not send another substantive message before this decision.

Use one of these branches:

After sending the credential decision message, stop until the user answers.

Workflow

  1. Inspect before acting:
  1. Based on that inspection:
  1. When creation is the chosen path, confirm the destination file/env var before writing. If the user has not already explicitly asked for a new key, ask whether to create one first.
  1. After confirmation, run the app tool preflight:
  1. Run prepare, keep private_key_path, and send only recipient_public_key_jwk to the connector.
  2. Call create_encrypted_openai_api_key with the confirmed key name plus the picker-confirmed organization_id and project_id when the picker path was used. In the text-only fallback, omit those fields so the connector preserves its default organization/project behavior.
  3. Run decrypt with the encrypted ciphertext, confirmed target path, env var name, and repo root as --workspace.
  4. Verify by running the relevant project command when practical. Do not reveal or inspect the secret value directly.

Helper

Use the helper by absolute path. prepare creates the temporary private key file plus a request JSON containing only the public JWK and requested key name:

node "<plugin root>/scripts/openai-platform-api-key.mjs" prepare --name "Codex"

After the connector returns encrypted_api_key.ciphertext, decrypt and write the key locally:

node "<plugin root>/scripts/openai-platform-api-key.mjs" decrypt \
  --private-key "<private key path from prepare>" \
  --ciphertext "<encrypted_api_key.ciphertext from connector result>" \
  --target "<confirmed env file path>" \
  --workspace "<repo root>" \
  --env-name OPENAI_API_KEY

The decrypt command updates or appends the env var, prints only safe write metadata, and refuses symlink or out-of-workspace targets.

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.