curl to SDK Converter
Paste a curl command for any AI API and get Python, TypeScript and Go SDK code.
Parsed: POST https://api.anthropic.com/v1/messages · 3 headers · bodyanthropic API detected — SDK variant included
import os
import requests
response = requests.post(
"https://api.anthropic.com/v1/messages",
headers={
"x-api-key": os.environ["ANTHROPIC_API_KEY"],
"anthropic-version": "2023-06-01",
"content-type": "application/json",
},
json={
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": "Hello, Claude"
}]
},
)
response.raise_for_status()
print(response.json())
# — or with the official anthropic SDK (reads ANTHROPIC_API_KEY automatically) —
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[{
"role": "user",
"content": "Hello, Claude"
}],
)
print(message.content)API keys from headers are replaced with environment-variable lookups — never hardcode credentials.
How it works
Every API doc gives you a curl example; almost no project ships curl in production. This converter bridges the gap: paste the curl command and get equivalent code in Python, TypeScript and Go, each behind its own tab with a copy button. The parser runs entirely in your browser and tolerates the messiness of real commands — multi-line backslash continuations, single or double quotes, and flags in any order.
Parsing extracts four things: the HTTP method (from -X, defaulting to GET, or POST when a body is present), the URL, every -H header, and the -d body. From those it generates a Python requests call, a TypeScript fetch call, and a Go net/http program — faithful translations that send exactly the same request the curl would. When the URL belongs to a recognized AI provider (api.anthropic.com or api.openai.com), the Python and TypeScript tabs also include the official-SDK version of the same call, with the JSON body unpacked into the SDK's named parameters the way the vendor's own documentation writes it.
One opinionated choice: API keys found in headers are never hardcoded into the generated code. The snippets reference an environment variable instead, because the most common way keys leak into git history is copy-pasting a working example that had a real credential inline. The SDK variants lean on each library's default environment-variable lookup, which is the documented best practice anyway.
The page loads prefilled with an Anthropic Messages API example so you can see the output shape immediately — replace it with your own command and the three tabs re-render as you type. Bodies that are not valid JSON are passed through as raw strings rather than rejected, and unknown flags are skipped without breaking the rest of the conversion. For going the other direction, or moving a request between OpenAI and Anthropic formats, see the API Translator in the related tools below. Everything here is computed locally as you type — no command you paste, and no key it might contain, ever leaves the page.
Frequently asked questions
Which APIs does the converter support?
Any HTTP API — the parser reads the method, URL, headers and body from the curl command and emits generic requests, fetch and net/http code that works against anything. On top of that, when the URL matches api.anthropic.com or api.openai.com, the Python and TypeScript tabs additionally emit idiomatic official-SDK calls (anthropic / openai packages) with the message body mapped to the SDK's named parameters.
How is authentication handled in the generated code?
Header-based auth (x-api-key, Authorization: Bearer) is carried through verbatim into the generic snippets, but the generated code deliberately references an environment variable instead of inlining the literal key — pasting a curl with a real key should not produce code that hardcodes it. The SDK variants rely on the SDK's own default env-var lookup (ANTHROPIC_API_KEY, OPENAI_API_KEY), which is the pattern the vendors document.
What about streaming responses?
If your curl body sets "stream": true, the generic snippets still work — requests and fetch return the raw SSE stream — but you need to iterate it instead of calling .json(). The SDK variants are the better path for streaming: both the anthropic and openai packages expose iterator-based streaming helpers that parse server-sent events for you. The converter flags a streaming body with a note rather than silently emitting blocking code.
Which curl flags does the parser understand?
The tolerant inline parser handles the flags that appear in real API documentation: -X/--request for the method, -H/--header for headers, -d/--data/--data-raw/--data-binary for the body, and URL detection anywhere in the command. Quoted strings with single or double quotes are handled, including JSON bodies spanning multiple lines with backslash continuations. Exotic flags (--form, --cookie, proxies) are ignored with the rest of the command still converted.
Why would I use an SDK instead of raw HTTP?
Raw HTTP is fine for a one-off script, but SDKs earn their dependency weight in production: they implement retries with exponential backoff, parse provider-specific error types, handle streaming protocols, keep up with API version headers, and type the request and response shapes. The converter shows both so you can start with the raw call to understand the wire format, then graduate to the SDK call for anything long-lived.
Built by FORG — AI cost observability for agentic coding. Free tools, no signup, nothing leaves your browser.
Learn about FORG