This guide calls the OpenAI API from Windows cmd.exe. The Responses API is recommended for new applications. ChatGPT and the API Platform are separate services, and API usage is billed separately from a ChatGPT subscription. Check API billing setup before making requests.
Set the API key as an environment variable
Create a key on the API Platform API keys page. Do not put it in source code or the request file. In Windows, press Win+R, run sysdm.cpl, and choose Advanced > Environment Variables > User variables > New. Set the variable name to OPENAI_API_KEY and its value to your key, then open a new Command Prompt. You can check that it is set without displaying the secret:
| |
An environment variable keeps the key out of the application source; it does not make the key safe to publish or share. Revoke and replace a leaked key on the API keys page. See API key security best practices.
Create the request
Save this JSON as request.json in your working folder. Save the file as UTF-8 if you include non-ASCII text.
| |
Model IDs can change, and model access depends on the API project. Check the current model catalog before using the example model.
Send the request with curl.exe
In Command Prompt, change to the folder containing request.json and run:
| |
--include displays the HTTP status and response headers. The Responses API returns JSON. Generated text is in an output_text content item inside an output message. Tool calls and other response types can add different items, so use a JSON parser and inspect each item’s type instead of assuming a fixed array index. See the Responses API reference.
Errors and usage
401can indicate a missing, invalid, or unauthorized API key. Check the key configuration without printing or sharing the value.429can indicate a rate limit or an exhausted credit or usage limit. Read the response body and check API Platform Usage and Billing.- API cost depends on the model and input/output tokens. Check current pricing and project usage in the API Platform, and configure limits or alerts if needed.
