OpenAI

OpenAI API

Call GPT-6 through the Responses API: streaming, JSON schemas, function calling, web search, embeddings, images, audio, files and batches.

AI & machine learningGuided#openai#gpt#llm#chat#embeddings#function-calling#vision

Fork copies the collection into your workspace, without the publisher's secrets, so you can add your own key and send requests. Star saves it to your starred APIs (Account › Marketplace) and helps others find it.

Overview

The OpenAI API gives your application the models behind ChatGPT: text generation and reasoning, coding, image understanding and generation, embeddings for search, speech-to-text and content moderation. New projects should build on the Responses API (POST /v1/responses), which handles plain prompts, multi-turn state, structured JSON, your own functions and OpenAI's built-in tools (web search, file search) in one endpoint. The older Chat Completions API is still supported and is included here because many libraries use its format.

Get an API key

  1. Sign up or log in at platform.openai.com.
  2. Add a payment method or prepaid credits under Billing. Without credits, requests fail with a 429 credit_balance_exhausted error.
  3. Open API keys and create a new secret key (keys belong to a project; the default project is fine to start). Copy it straight away: it is shown only once.
  4. Paste it into the apiKey variable of this collection. It is marked secret, so it is never shared when you fork or publish the collection.

Authentication

Every request sends Authorization: Bearer <your key>; the collection sets this for you. If your key can reach several organisations or projects, you can add the optional OpenAI-Organization and OpenAI-Project headers to choose which one is billed. Each response carries an x-request-id header: log it, support will ask for it.

Base URL: https://api.openai.com/v1.

Models

The model variable defaults to gpt-6-astra, OpenAI's flagship for complex reasoning and coding. gpt-6.1-sol comes close to it at a lower price, gpt-6.1-terra is a fast all-rounder, and gpt-6-luna is the cheapest for high-volume, simple tasks. Embeddings use text-embedding-3-small / -large, images use GPT Image models (gpt-image-2.6-flare / -sunburst), transcription uses gpt-transcribe and moderation uses omni-moderation-latest. The models page lists current IDs, context windows and prices; List models shows what your key can use.

How to use this collection

  • 1. Start here: list models and send your first response.
  • 2. Responses API: instructions, multi-turn state, streaming, JSON schema output.
  • 3. Tools: the two-step function-calling round trip, plus built-in web search.
  • 4. to 8.: image and PDF input, Chat Completions, Files, Embeddings, image generation, audio and moderation.
  • 9. Batch API and 10. Vector stores are multi-step flows; run their requests in order. IDs are saved into variables by each step's test script.

Common errors

StatusMeaningWhat to do
400Invalid requestRead error.message: a missing field, wrong type, or a parameter the model does not support.
401Invalid or missing keyCheck the key, or that it belongs to the right organisation/project; an IP allowlist can also cause it.
403Not allowedUnsupported country/region, or the project has no access to that model.
404Not foundWrong path, misspelled model ID, or an object from another project.
429Rate or spend limitSlow down and honour Retry-After; for credit_balance_exhausted or spend-limit codes, add credits or raise the limit.
500 / 503Server error or overloadedRetry with exponential backoff; check status.openai.com.

Limits and pricing

You pay per input and output token, at different rates per model; cached input is cheaper, the Batch API is discounted, and built-in tools such as web search add per-call fees. Rate limits (requests and tokens per minute) depend on your usage tier and model, and every response reports them in x-ratelimit-* headers. See Pricing, Rate limits, Error codes and the API reference.

Endpoints 29

1. Start here

  • GETList models/modelsLists every model your API key can call right now, including fine-tuned models owned by your organisation. Use it to check the key works and to copy the exact…
  • GETRetrieve a model/models/{{model}}Returns one model object: id, created, owned_by and shutdown_date. Handy as a quick check that the ID in your model variable exists and is not about to be…
  • POSTCreate a response (first request)/responsesThe Responses API (POST /v1/responses) is OpenAI's main endpoint for new projects: text in, text out, plus images, files, tools, structured output and stored…

2. Responses API

  • POSTInstructions and reasoning effort/responsesinstructions is the system (developer) message: the role, tone and rules the model should follow. It applies to this request only; when you continue with…
  • POSTContinue a conversation (previous_response_id)/responsesTo ask a follow-up, send only the new user turn and set previous_response_id to the id of the earlier response. OpenAI rebuilds the context from the stored…
  • POSTStream the answer (SSE)/responsesWith "stream": true the API sends Server-Sent Events while the answer is generated. Each event has a type: Streaming is the right choice for chat UIs and for…
  • POSTStructured output (JSON schema)/responsesSet text.format to {"type": "json_schema", ...} and the model's answer is guaranteed to match your JSON Schema (Structured Outputs). Use it for extraction,…
  • GETRetrieve a stored response/responses/{{responseId}}Fetches a response you created earlier with store: true, by ID. Useful for logging, for debugging what the model actually returned, and for polling responses…

3. Tools

  • POST1) Offer a function/responsesDescribe your own functions in tools and the model decides when to call them. Each function has a name, a description (say when to use it) and JSON Schema…
  • POST2) Send the function result back/responsesRun your function, then send its result as a function_call_output item with the same call_id. previous_response_id links this turn to the response that asked…
  • POSTWeb search (built-in tool)/responsesAdd {"type": "web_search"} to tools and the model can search the web before answering, for questions about recent events or facts that change. OpenAI runs the…

4. Images and files as input

  • POSTImage input (from a URL)/responsesTo ask about an image, send input as a message whose content is an array: an input_text part with your question and an input_image part with image_url (a…
  • POSTAsk about an uploaded PDF/responsesUpload the PDF first with 6. Files > Upload a file (purpose = user_data); its test saves fileId. Then send an input_file content part with that file_id next…

5. Chat Completions

  • POSTCreate a chat completion/chat/completionsPOST /v1/chat/completions takes the whole conversation as a messages array every time (it keeps no state) and returns the next assistant message. Many SDKs…
  • POSTStream a chat completion/chat/completionsSet "stream": true to get chat.completion.chunk objects as Server-Sent Events. Each chunk has choices[0].delta with the next piece of content; the stream ends…

6. Files

  • POSTUpload a file/filesUploads a file as multipart/form-data. Pick the file in the body tab and set purpose: Optional expires_after sets an expiry. What comes back: a file object…
  • GETList files/filesLists files in your project, newest first. Filter with purpose (for example batch) and page with limit and after (a file ID from the previous page; check…

7. Embeddings

  • POSTCreate embeddings/embeddingsReturns one vector per input. Compare vectors with cosine similarity: texts with similar meaning have close vectors. What comes back: data[] with embedding…

8. Images, audio and moderation

  • POSTGenerate an image/images/generationsCreates images from a text prompt with a GPT Image model. The imageModel variable defaults to gpt-image-2.6-flare (fast iteration); gpt-image-2.6-sunburst is…
  • POSTText to speech/audio/speechDeprecation notice: every model this endpoint accepts (tts-1, tts-1-hd, gpt-4o-mini-tts and its snapshots) is deprecated and scheduled to shut down on 6…
  • POSTTranscribe audio/audio/transcriptionsConverts speech in an audio file to text. Send multipart/form-data: choose the audio file in the body tab (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav or webm;…
  • POSTModerate text/moderationsChecks text (or images, with omni-moderation-latest) against categories such as harassment, hate, self-harm, sexual content, violence and illicit activity.…

9. Batch API

  • POST1) Upload the batch input file/filesA batch input is a .jsonl file: one request per line, each with a unique custom_id, method, url and body (the same body you would send to that endpoint). All…
  • POST2) Create a batch/batchesStarts processing the uploaded file. What comes back: a batch object with status: "validating". The test saves its id into batchId.
  • GET3) Check the batch/batches/{{batchId}}Poll this until status is final. Statuses: validating, in_progress, finalizing, then completed, or failed, expired, cancelling / cancelled. request_counts…
  • GET4) Download the results/files/{{batchOutputFileId}}/contentDownloads the output JSONL. Each line has your custom_id and a response with status_code and the endpoint's normal body. Lines are not in input order: match…

10. Vector stores and file search

  • POSTCreate a vector store/vector_storesA vector store chunks, embeds and indexes files so they can be searched. Pass file_ids of files you uploaded (upload with purpose = assistants or user_data);…
  • POSTSearch a vector store/vector_stores/{{vectorStoreId}}/searchRuns a semantic search over a vector store and returns the best-matching chunks, without calling a model. Use it to build your own RAG prompt or to debug what…
  • POSTAnswer with file search (Responses)/responsesGives the model the built-in file_search tool over your vector store: it searches, reads the matching chunks and answers with file_citation annotations…

API details

Base URL
https://api.openai.com/v1
Authentication
A bearer token in the Authorization header
Operations
29 operations on 29 pathsPOST 23GET 6
Main resources
1. Start here 310. Vector stores and file search 32. Responses API 53. Tools 34. Images and files as input 25. Chat Completions 26. Files 27. Embeddings 18. Images, audio and moderation 49. Batch API 4
Description format
Swastik Codes guided collection, API version checked against the docs on 2026-11-17

How to test the OpenAI API in Swastik Codes

  1. Open the APISelect “Fork & run in Swastik Codes” on this page. Sign in or create a free account if asked.
  2. Fork it into your workspaceChoose a workspace. You get your own copy of the OpenAI API collection, without the publisher's secrets.
  3. Add your credentialsThis API uses A bearer token in the Authorization header. Add yours in the collection's variables or an environment; the requests already reference it.
  4. Send a requestPick an endpoint, for example “List models” (GET /models), and press Send. Check the response, add tests and run the whole collection with the runner.

Frequently asked questions

What is the OpenAI API?

Call GPT-6 through the Responses API: streaming, JSON schemas, function calling, web search, embeddings, images, audio, files and batches. It is listed under AI & machine learning and has 29 endpoints.

Who publishes the OpenAI API?

It is listed from OpenAI's public API description (an OpenAPI document), not published by OpenAI on Swastik Codes. Anyone who controls openai.com can claim the profile by adding a DNS TXT record.

What is the base URL of the OpenAI API?

Requests go to https://api.openai.com/v1. Endpoint paths are added to this base URL.

How do I authenticate with the OpenAI API?

With A bearer token in the Authorization header.

How many endpoints does the OpenAI API have?

29 operations on 29 paths (23 POST, 6 GET). The largest groups are 1. Start here, 10. Vector stores and file search, 2. Responses API, 3. Tools.

Is forking the OpenAI API free?

Yes. Forking copies the collection into your workspace for free. It has been starred 0 times and forked 0 times.

Suggest an API

Tell us which public API is missing. We check it, then add it here with its endpoints when it has an OpenAPI (Swagger) description.