Prompt to API Code
Convert your prompt into ready-to-run cURL, Python or Node.js code for OpenAI, Anthropic and Google APIs. Free online tool.
Your input stays in your browser — nothing is uploaded to our servers.
Testing a prompt in a chat window is easy; turning it into a working API call means remembering each provider’s endpoint, headers, request shape and SDK. This tool writes that code for you, as a cURL command, Python or Node.js, for OpenAI, Anthropic (Claude) and Google (Gemini), with your prompt safely escaped so quotes, apostrophes and line breaks don’t break it.
How to turn a prompt into API code
- Choose the model and the output format: cURL, Python or Node.js.
- Type your system prompt (optional) and your user prompt, and set the maximum number of tokens for the answer.
- Copy the generated code. Set your API key as an environment variable (
OPENAI_API_KEY,ANTHROPIC_API_KEYorGEMINI_API_KEY) and run it. - For Python and Node.js, install the SDK first with the command shown at the top of the code.
What the generated code does
Each provider has its own current API. The OpenAI code uses the Responses API, which the OpenAI SDK documents as the primary interface; the system prompt goes in instructions. The Anthropic code uses the Messages API with a top-level system field. The Gemini code uses the Interactions API from Google’s current google-genai SDKs, with system_instruction, and sends the key in the x-goog-api-key header rather than in the URL.
Escaping is where hand-written snippets usually break. In the cURL command the JSON body is passed through a quoted heredoc (<<'EOF'), so the shell doesn’t touch quotes, $ signs or backticks in your prompt. In Python and Node.js every value is written as a JSON string literal, which is valid in both languages. Our tests run the generated code with prompts full of quotes, backslashes, tabs, newlines and emoji to check that the text arrives unchanged.
The SDKs read the API key from an environment variable, so the key never appears in the code. Keep it that way: never put API keys in front-end JavaScript or commit them to a repository.
Frequently asked questions
Is it safe to paste my API key here?
You don’t need to: the generated code reads the key from an environment variable, so it never appears in the snippet. Nothing you type on this page is sent to any server, but as a rule, don’t paste API keys into websites.
Why does the OpenAI code use the Responses API instead of Chat Completions?
The current OpenAI SDK documentation describes the Responses API as the primary way to call its models, and Chat Completions’ max_tokens parameter is deprecated. Chat Completions still works if your code base already uses it.
Why does the Gemini cURL command send the key in a header?
Google’s current documentation sends the key in the x-goog-api-key header. A key in the URL ends up in shell history, proxy logs and server logs, so the header is the safer choice.
My prompt has quotes and line breaks. Will the code still run?
Yes. The cURL body uses a quoted heredoc, so the shell doesn’t interpret anything inside it, and Python and Node.js values are written as properly escaped string literals. This is covered by automated tests for every provider and format.
What should I set max tokens to?
It caps the length of the answer. Too low and long answers get cut off; too high only matters if the model actually writes that much. Reasoning models count their hidden reasoning against this limit too, so give them more room than you would a simple chat model.