{
 "kind": "api",
 "slug": "openai-api",
 "path": "apis/openai-api/",
 "name": "OpenAI API",
 "logo": "https://agentgid.com/media/avatars/openai.png",
 "maker": "OpenAI",
 "density": "full",
 "crumbs": [
  [
   "APIs",
   "apis/"
  ],
  [
   "Model hosting and inference",
   "apis/inference/"
  ]
 ],
 "lead": "GPT models for text, images and tools.",
 "chips": [
  {
   "label": "Model hosting and inference",
   "path": "apis/inference/"
  }
 ],
 "primary": {
  "label": "Copy prompt for your agent",
  "copy": "Add the OpenAI API to my app on the server only: read OPENAI_API_KEY from .env, call client.responses.create with a fixed model name, return response.output_text to the page, and never put the key in browser code."
 },
 "links": [
  {
   "label": "Website",
   "href": "https://developers.openai.com/api/docs"
  },
  {
   "label": "Pricing",
   "href": "https://developers.openai.com/api/docs/pricing"
  },
  {
   "label": "GitHub",
   "href": "https://github.com/openai/openai-node"
  }
 ],
 "track": "Outages, price changes and new versions on your dashboard",
 "verdicts": [
  {
   "key": "price",
   "label": "Price",
   "value": "Paid",
   "status": "info",
   "sub": "from $0.1",
   "quote": "Free User must be in an allowed geography $100 / month",
   "note": "No free tier on the pricing page. As reported on the official pricing page, checked Oct 22, 2026.",
   "src": "https://developers.openai.com/api/docs/pricing"
  },
  {
   "key": "commercial",
   "label": "Commercial use",
   "value": "With conditions",
   "status": "cond",
   "sub": "Does not train on your data",
   "quote": "You are responsible for ensuring that the content you input to our API does not violate any applicable law or our Terms of Use.",
   "note": "Paid use in your product is the normal case; you own inputs and outputs, and your content must follow the law and OpenAI's Terms of Use and usage policies (the policy pages block automated readers, so read them in a browser).",
   "src": "https://developers.openai.com/api/docs/guides/embeddings.md"
  },
  {
   "key": "key",
   "label": "Key & sign-up",
   "value": "API key, server only",
   "status": "info",
   "sub": "Env var OPENAI_API_KEY",
   "quote": "The OpenAI API accepts bearer credentials from API keys or from short-lived access tokens created with workload identity federation.",
   "note": "API key sent as a Bearer header from your server (Authorization: Bearer $OPENAI_API_KEY); short-lived workload identity tokens are an option for cloud servers",
   "src": "https://developers.openai.com/api/reference/overview.md"
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Docs for agents",
   "status": "info",
   "sub": "llms.txt · SDK",
   "quote": "This MCP server is documentation-only. It does not call the OpenAI API on your behalf.",
   "note": " Our agent check: 3 of 6 (Nov 13, 2026).",
   "src": "https://developers.openai.com/learn/docs-mcp.md"
  }
 ],
 "vfoot": "Checked against the maker's official pages, pricing on Oct 22, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What OpenAI API does",
   "parts": [
    {
     "t": "prose",
     "text": "The OpenAI API is a paid online service that lets your app use OpenAI's GPT models. Your server sends text or a picture and gets back an answer, a summary, neatly sorted data, or a request to run one of your own functions. You pay for each token, a small piece of text, at a price set per model."
    },
    {
     "t": "list",
     "items": [
      "OpenAI API is one of 41 APIs in the Model hosting and inference category on AgentGid.",
      "It is not among the 13 that can be started for free.",
      "6 of them ship an official MCP server; OpenAI API does not.",
      "Its official SDK is the 1st most downloaded in the category (152M a week)."
     ],
     "muted": true
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Writing help inside your app",
       "text": "Draft replies, product texts or short summaries right inside your app, so people do not copy text back and forth from a chat window.",
       "idea": false
      },
      {
       "title": "Turn messages into tidy records",
       "text": "Pull a name, a date and a list of people out of an email or a form message, in exactly the fields your database expects.",
       "idea": false
      },
      {
       "title": "Answers that use your own data",
       "text": "Let the assistant look up an order, a booking or an account in your system before it answers, and run the action you allow, such as a refund.",
       "idea": false
      },
      {
       "title": "Answers with today's news",
       "text": "Let the model search the web while it answers, for questions about prices, events or anything newer than its training.",
       "idea": false
      },
      {
       "title": "Describe photos people upload",
       "text": "Read a receipt, describe a product photo or check what a screenshot shows, and get the result back as text.",
       "idea": false
      },
      {
       "title": "Big jobs overnight at half price",
       "text": "Sort thousands of support tickets or product reviews in one batch that finishes within a day, when nobody waits for the answer.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "OpenAI API popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "148M",
       "l": "SDK downloads a week",
       "d": "+18.0% on the 4-week average",
       "up": true
      },
      {
       "n": "11.3K",
       "l": "GitHub stars, openai/openai-node"
      }
     ]
    },
    {
     "t": "small",
     "text": "SDK downloads from npm and PyPI, weekly. Numbers as of Nov 17, 2026."
    }
   ]
  },
  {
   "id": "pricing",
   "nav": "Pricing and limits",
   "h2": "Pricing",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Free tier",
       "v": "None"
      },
      {
       "l": "Cheapest plan",
       "v": "No monthly plan"
      },
      {
       "l": "Usage price",
       "v": "Per 1M tokens: GPT-6 Luna $0.10 in / $0.50 out; GPT-6.1 Sol $2 / $10; GPT-6 Astra $10 / $50"
      }
     ]
    },
    {
     "t": "h3",
     "text": "What one action costs"
    },
    {
     "t": "table",
     "head": [
      "Action",
      "Price"
     ],
     "num": true,
     "rows": [
      [
       "1M input tokens, GPT-6 Luna (short context, standard)",
       "$0.10"
      ],
      [
       "1M output tokens, GPT-6 Luna (short context, standard)",
       "$0.50"
      ],
      [
       "1M input / output tokens, GPT-6.1 Sol (short context, standard)",
       "$2.00"
      ],
      [
       "1M input / output tokens, GPT-6 Astra (short context, standard)",
       "$10.00"
      ],
      [
       "1,000 web search tool calls (plus search content tokens at model rates)",
       "$10.00"
      ]
     ]
    },
    {
     "t": "small",
     "text": "As reported on the official pricing page, checked Oct 22, 2026. Prices change: confirm before you buy.",
     "link": "developers.openai.com/api/docs/pricing",
     "href": "https://developers.openai.com/api/docs/pricing"
    }
   ]
  },
  {
   "id": "limits",
   "nav": null,
   "spy_as": "pricing",
   "h2": "Limits",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Free tier",
       "v": "Usage limit $100 a month; only in allowed countries",
       "src": "https://developers.openai.com/api/docs/guides/rate-limits.md"
      },
      {
       "l": "Build tier (after $5 in credit purchases)",
       "v": "Usage limit $500 a month; 5,000 requests and 1,000,000 tokens per minute for Astra, Sol and Terra models",
       "src": "https://developers.openai.com/api/docs/guides/rate-limits.md"
      },
      {
       "l": "Launch tier (after $100 in credit purchases)",
       "v": "Usage limit $5,000 a month; 10,000 requests and 4,000,000 tokens per minute for Astra, Sol and Terra models",
       "src": "https://developers.openai.com/api/docs/guides/rate-limits.md"
      },
      {
       "l": "Grow tier (after $500 in credit purchases)",
       "v": "Usage limit $200,000 a month",
       "src": "https://developers.openai.com/api/docs/guides/rate-limits.md"
      }
     ]
    },
    {
     "t": "small",
     "text": "From the official docs.",
     "link": "developers.openai.com/api/docs/guides/rate-limits.md",
     "href": "https://developers.openai.com/api/docs/guides/rate-limits.md"
    }
   ]
  },
  {
   "id": "access",
   "nav": "Access and terms",
   "h2": "Key and access",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "How it signs in",
       "v": "API key sent as a Bearer header from your server (Authorization: Bearer $OPENAI_API_KEY); short-lived workload identity tokens are an option for cloud servers"
      },
      {
       "l": "Environment variable",
       "v": "OPENAI_API_KEY",
       "code": true
      },
      {
       "l": "Safe in browser code",
       "v": "No, keep it on your server",
       "status": "no"
      },
      {
       "l": "Card at sign-up",
       "v": "Not stated on the pages we read"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Steps only a person can do"
    },
    {
     "t": "list",
     "items": [
      "Sign in to the OpenAI platform and create an API key (a project service account key for a deployed app). Put it in .env as OPENAI_API_KEY (kept out of git) and read it on the server only.",
      "Add a payment method and buy prepaid credits. No code change; requests start working once credits exist.",
      "Set a monthly spend alert or hard spend limit for the project. Handle 429 errors with code project_spend_limit_exceeded by showing a friendly message instead of retrying."
     ]
    }
   ]
  },
  {
   "id": "terms",
   "nav": null,
   "spy_as": "access",
   "h2": "Commercial use and your data",
   "parts": [
    {
     "t": "prose",
     "text": "It is a paid online service, not open source; the official code libraries are free under the Apache-2.0 license. You own what you send and what the models return. Your content must not break the law or OpenAI's terms of use."
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In a paid app",
       "v": "With conditions",
       "status": "cond",
       "sub": "Paid use in your product is the normal case; you own inputs and outputs, and your content must follow the law and OpenAI's Terms of Use and usage policies (the policy pages block automated readers, so read them in a browser).",
       "quote": "You are responsible for ensuring that the content you input to our API does not violate any applicable law or our Terms of Use.",
       "src": "https://developers.openai.com/api/docs/guides/embeddings.md"
      },
      {
       "l": "client-work",
       "v": "With conditions",
       "status": "cond",
       "sub": "Give each client app its own project and service account key instead of a developer's personal key.",
       "quote": "Don't share one developer's key across a team or use that person's identity as the permanent identity of a production application.",
       "src": "https://developers.openai.com/api/docs/guides/api-keys.md"
      },
      {
       "l": "inside-app-bundle",
       "v": "With conditions",
       "status": "cond",
       "sub": "The official libraries are Apache-2.0, so you may ship them in your app with their license notice; the key itself must never be bundled.",
       "quote": "\"license\":\"Apache-2.0\"",
       "src": "https://registry.npmjs.org/openai/7.54.0"
      },
      {
       "l": "Trains on what you send",
       "v": "“As of March 1, 2023, data sent to the OpenAI API is not used to train or improve OpenAI models (unless you explicitly opt in to share data with us).”",
       "quote": null,
       "src": "https://developers.openai.com/api/docs/guides/your-data.md"
      },
      {
       "l": "Keeps your data",
       "v": "Safety (abuse monitoring) logs up to 30 days; Responses API results stored at least 30 days unless store is false; Zero Data Retention only for approved customers.",
       "quote": "By default, abuse monitoring logs are generated for all API feature usage and retained for up to 30 days, unless longer retention is required by law, or is reasonably necessary to protect our services or any third party from harm.",
       "src": "https://developers.openai.com/api/docs/guides/your-data.md"
      },
      {
       "l": "Where data is stored",
       "v": "Data residency per project for eligible customers (via sales), with a 10% price uplift for newer models.",
       "quote": "Data residency controls are a project configuration option that allow you to configure the location of infrastructure OpenAI uses to provide services.",
       "src": "https://developers.openai.com/api/docs/guides/your-data.md"
      }
     ]
    }
   ]
  },
  {
   "id": "errors",
   "nav": null,
   "spy_as": "access",
   "h2": "Errors to handle",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "401 Incorrect API key provided",
       "v": "The key sent with the request is wrong or was revoked.",
       "sub": "Check the key in .env or create a new one in the dashboard; do not retry unchanged."
      },
      {
       "l": "429 Rate limit reached for requests",
       "v": "Too many requests in a short time for your tier.",
       "sub": "Slow down and retry after the Retry-After header; retry with backoff."
      },
      {
       "l": "429 credit_balance_exhausted",
       "v": "The organization has no prepaid credits left.",
       "sub": "Top up credits; retrying does not help."
      },
      {
       "l": "500 Server error",
       "v": "A problem on OpenAI's side.",
       "sub": "Retry after a short wait and check status.openai.com if it keeps happening."
      },
      {
       "l": "503 server_is_overloaded",
       "v": "The chosen model is temporarily overloaded.",
       "sub": "Follow Retry-After, then retry with backoff."
      }
     ]
    }
   ]
  },
  {
   "id": "agent",
   "nav": "For agents",
   "h2": "Use it from an agent",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Our agent check",
       "v": "3 of 6: llms.txt yes, OpenAPI no, SDK yes, MCP no, status page no, AI assistants allowed yes",
       "sub": "Checked Nov 13, 2026."
      },
      {
       "l": "MCP server",
       "v": "OpenAI Docs MCP (documentation only)",
       "sub": "claude mcp add --transport http openaiDeveloperDocs https://developers.openai.com/mcp"
      },
      {
       "l": "npm",
       "v": "npm install openai",
       "code": true
      },
      {
       "l": "PyPI",
       "v": "pip install openai",
       "code": true
      }
     ]
    },
    {
     "t": "h3",
     "text": "Instructions in its docs to check first"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The docs say",
       "v": "“Always use the OpenAI developer documentation MCP server if you need to work with the OpenAI API, plugins, ChatGPT, Codex,… without me having to explicitly ask.”",
       "sub": "The docs suggest pasting this standing instruction into AGENTS.md. Ask the person before changing their project's agent instructions; using the docs server for one task needs no file change."
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "OpenAI API",
       "me": true,
       "facts": [
        "from $0.1",
        "No free tier"
       ]
      },
      {
       "name": "Gemini API",
       "why": "Pick the Gemini API when you want a free tier to start, or need audio and video input as well as text and images.",
       "path": "apis/google-gemini-api/",
       "facts": [
        "Free plan",
        "Free tier"
       ]
      },
      {
       "name": "Mistral AI API",
       "why": "Pick Mistral when you want open-weight models you could later run yourself, behind one paid API.",
       "path": "apis/mistral-api/",
       "facts": [
        "from $0.5 per million input tokens",
        "No free tier"
       ]
      },
      {
       "name": "Groq (LLM inference)",
       "why": "Pick Groq when you want fast answers from open models such as GPT-OSS and Llama, priced per 1M tokens.",
       "path": "apis/groq/",
       "facts": [
        "from $0.075",
        "No free tier"
       ]
      }
     ],
     "more": "All model hosting and inference APIs",
     "more_path": "apis/inference/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Add the OpenAI API to my app on the server only: read OPENAI_API_KEY from .env, call client.responses.create with a fixed model name, return response.output_text to the page, and never put the key in browser code."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Create an API key in the OpenAI dashboard and put it in an environment variable on the server.",
       "code": "export OPENAI_API_KEY=\"your_api_key_here\"",
       "src": "https://developers.openai.com/api/docs/quickstart.md"
      },
      {
       "text": "Install the official package for your language (JavaScript shown; Python is pip install openai).",
       "code": "npm install openai",
       "src": "https://developers.openai.com/api/docs/quickstart.md"
      },
      {
       "text": "Send a first request from a server-side file and print the answer.",
       "code": "import OpenAI from \"openai\";\nconst client = new OpenAI();\n\nconst response = await client.responses.create({\n  model: \"gpt-6-astra\",\n  input: \"Write a one-sentence bedtime story about a unicorn.\",\n});\n\nconsole.log(response.output_text);\n",
       "src": "https://developers.openai.com/api/docs/quickstart.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "First request"
    },
    {
     "t": "tabs",
     "label": "First request",
     "items": [
      {
       "tab": "Request",
       "code": "curl https://api.openai.com/v1/responses \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"gpt-6-astra\",\n    \"input\": \"Tell me a three sentence bedtime story about a unicorn.\"\n  }'\n",
       "intro": null
      },
      {
       "tab": "Response",
       "code": "{\n  \"id\": \"resp_67ccd2bed1ec8190b14f964abc0542670bb6a6b452d3795b\",\n  \"object\": \"response\",\n  \"status\": \"completed\",\n  \"model\": \"gpt-6-astra\",\n  \"output\": [\n    {\n      \"type\": \"message\",\n      \"role\": \"assistant\",\n      \"content\": [\n        {\n          \"type\": \"output_text\",\n          \"text\": \"In a peaceful grove beneath a silver moon, a unicorn named Lumina discovered a hidden pool that reflected the stars. ...\"\n        }\n      ]\n    }\n  ],\n  \"usage\": {\n    \"input_tokens\": 36,\n    \"output_tokens\": 87,\n    \"total_tokens\": 123\n  }\n}\n"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "new OpenAI({ dangerouslyAllowBrowser: true }) in a React page with the real key",
       "fix": "Call OpenAI from your own server route and send only the answer to the page",
       "why": "The library blocks browsers by default because anyone can read a key shipped to the page and spend your credits."
      },
      {
       "dont": "client.chat.completions.create(...) with tools on gpt-6-astra or gpt-6.1-sol",
       "fix": "Use client.responses.create(...) with tools for these models",
       "why": "The newest models need the Responses API for tool calling."
      },
      {
       "dont": "Keeping only the message items of response.output when you build the next turn yourself",
       "fix": "Pass previous_response_id, or replay all output items in order (toResponseInputItems() in the JavaScript library)",
       "why": "Dropping reasoning or tool-call items can make the next request fail."
      },
      {
       "dont": "Retrying in a loop on 429 credit_balance_exhausted or a spend-limit error",
       "fix": "Read error.code; retry only rate-limit and server errors with backoff, and tell the person to top up for billing errors",
       "why": "Retries cannot fix billing, spend or quota errors."
      },
      {
       "dont": "Deploying the openai package 7.x on Node.js 20",
       "fix": "Use Node.js 22 or 24",
       "why": "Node.js 22 is the minimum supported version of the current library."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "How is it billed?",
       "a": "Per token, with separate prices for input and output and for each model. Requests run on prepaid credits.",
       "evidence": {
        "url": "https://developers.openai.com/api/docs/guides/error-codes.md",
        "quote": "Cause: Your organization has no prepaid credits remaining."
       }
      },
      {
       "q": "Does OpenAI train its models on what my app sends?",
       "a": "Not by default. Data sent to the API has not been used for training since March 1, 2023, unless you opt in.",
       "evidence": {
        "url": "https://developers.openai.com/api/docs/guides/your-data.md",
        "quote": "As of March 1, 2023, data sent to the OpenAI API is not used to train or improve OpenAI models (unless you explicitly opt in to share data with us)."
       }
      },
      {
       "q": "Can I call it straight from the web page?",
       "a": "No. The JavaScript library refuses to run in a browser unless you switch on dangerouslyAllowBrowser, because the key would be exposed. Call it from your server.",
       "evidence": {
        "url": "https://github.com/openai/openai-node/blob/master/README.md",
        "quote": "Web browsers: disabled by default to avoid exposing your secret API credentials."
       }
      },
      {
       "q": "Which model should I start with?",
       "a": "The models page suggests GPT-6 Astra if you are unsure, GPT-6.1 Sol to balance quality and cost, and GPT-6 Luna for cheap, high-volume work.",
       "evidence": {
        "url": "https://developers.openai.com/api/docs/models.md",
        "quote": "If you're not sure where to start, use GPT-6 Astra, our flagship model for complex reasoning and coding."
       }
      },
      {
       "q": "Who owns the text the model writes for me?",
       "a": "You do. The docs say customers own their input and output.",
       "evidence": {
        "url": "https://developers.openai.com/api/docs/guides/embeddings.md",
        "quote": "Yes, customers own their input and output from our models, including in the case of embeddings."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Maker",
   "OpenAI"
  ],
  [
   "Category",
   "Model hosting and inference"
  ],
  [
   "Price",
   "from $0.1"
  ],
  [
   "Official SDK",
   "npm openai, PyPI openai"
  ],
  [
   "Latest SDK",
   "7.54.0 on npm"
  ],
  [
   "Agent check",
   "3 of 6"
  ],
  [
   "Pricing checked",
   "Oct 22, 2026"
  ]
 ],
 "good": [
  "You need an OpenAI account and a secret key. Keep the key on your server; never put it in a web page or a phone app.",
  "You pay in advance with credits. When they run out, requests fail until someone adds more.",
  "How many requests you may send per minute grows with your usage tier, which rises as you buy more credits."
 ],
 "checked_line": "Read by AgentGid from 26 official pages, card checked Nov 10, 2026; usage numbers update daily."
}