---
title: "OpenAI-compatible API request builder: curl, Python, JS"
description: "Build a chat completions request for any OpenAI-compatible API and copy it as curl, Python, Node or the OpenAI SDK, with streaming, tools and JSON output."
url: https://broadrouter.com/tools/api-request-builder/
lang: en
updated: 2026-11-15
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# OpenAI-compatible API request builder

Updated 2026-11-15

**In short:** An OpenAI-compatible request is a POST to the base URL plus /chat/completions, with an Authorization: Bearer header and a JSON body holding model and messages. With the OpenAI SDKs you change only base\_url and the key. This builder writes the same request as curl, Python requests, the OpenAI Python SDK, Node fetch and the Node SDK.

Free, no sign-up, runs in your browser: nothing you type is sent anywhere.

RequestBase URLModelDeepSeek V4.1 Flash (broadnet/deepseek-v4.1-flash)GLM 5.3 (broadnet/glm-5.3)Qwen3.8 27B (broadnet/qwen3.8-27b)BroadNet Gemma 4 VL 26B (broadnet/gemma-4-26b-a4b)Custom model…Custom model IDSystem messageYou are a concise assistant.User messageSay hello in English and Arabic.Temperaturemax\_tokensreasoning\_effortNot setlowmediumhighOutput formatPlain textJSON modeTools example Stream include\_usageAPI key environment variable

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-api-request-builder&utm_content=tool) ·

The code uses a placeholder: your key is read from an environment variable and is never typed into this page. BroadNet Gemma 4 VL 26B is the default because it runs on the $5 starting credit; the other BroadNet models need a top-up.

[Report a wrong price or number](mailto:info@broadnet.ai?subject=Wrong%20price%20or%20number%20on%20OpenAI-compatible%20API%20request%20builder&body=Page%3A%20https%3A%2F%2Fbroadrouter.com%2Ftools%2Fapi-request-builder%2F%0A%0AWhat%20looks%20wrong%20(model%2C%20figure%20shown%2C%20correct%20figure%20and%20a%20source%20link%20if%20you%20have%20one)%3A%0A) (email to info@broadnet.ai, with this page's link and your inputs filled in).

## How it works

1.  Set the base URL (any OpenAI-compatible API) and pick a model, or choose "Custom model" and type an ID.
2.  Write the system and user messages and set options: temperature, max\_tokens, reasoning\_effort, streaming with usage, and JSON mode or a tools example.
3.  Pick an output tab: curl, Python requests, OpenAI Python SDK, Node fetch or OpenAI Node SDK.
4.  Copy the code, set your key in the environment variable it names, and run it. Copy the page link to share the same request.

## Anatomy of a chat completions request

```
POST https://inference.broadnet.ai/v1/chat/completions
Authorization: Bearer $BROADNET_API_KEY
Content-Type: application/json

{
  "model": "broadnet/gemma-4-26b-a4b",
  "messages": [
    {"role": "system", "content": "You are a concise assistant."},
    {"role": "user", "content": "Say hello in English and Arabic."}
  ],
  "max_tokens": 1000,
  "stream": true,
  "stream_options": {"include_usage": true}
}
```

| Parameter | What it does |
| --- | --- |
| `model` | The model ID. On BroadNet: [`broadnet/deepseek-v4.1-flash`](https://broadrouter.com/models/deepseek-v4.1-flash/), [`broadnet/glm-5.3`](https://broadrouter.com/models/glm-5.3/), [`broadnet/qwen3.8-27b`](https://broadrouter.com/models/qwen3.8-27b/), [`broadnet/gemma-4-26b-a4b`](https://broadrouter.com/models/gemma-4-vl-26b/). |
| `messages` | The conversation: `system`, `user`, `assistant` and `tool` turns, oldest first. |
| `temperature` | Randomness, 0 to 2. Leave it unset unless you need it. |
| `max_tokens` | Cap on generated tokens, reasoning included. See [max tokens](https://broadrouter.com/glossary/max-tokens/). |
| `reasoning_effort` | low, medium or high thinking on reasoning models. |
| `stream`, `stream_options` | Server-Sent Events; `include_usage` adds token counts in the last chunk. See [streaming](https://broadrouter.com/glossary/streaming/). |
| `response_format` | `json_object` for JSON mode, or `json_schema` for [structured output](https://broadrouter.com/glossary/structured-output/). |
| `tools`, `tool_choice` | Functions the model may call. See [tool calling](https://broadrouter.com/glossary/tool-calling/). |

## Common mistakes

-   Base URL with or without `/v1`: SDKs append `/chat/completions` to the base URL, so the base must end in `/v1`.
-   JSON mode without the word "JSON" in the prompt: many servers reject or misbehave. The builder adds an instruction for you.
-   `max_tokens` too low on a reasoning model: the answer comes back empty with `finish_reason: "length"`.
-   Tools on a model that does not support them: on BroadNet, GLM 5.3 and Qwen3.8 27B are listed with tools.
-   Hard-coded keys in code or in shared links. Keep keys in environment variables and rotate any that leak; see [API keys and IP allow-lists](https://broadrouter.com/guides/api-keys-ip-allow-lists/).

## Questions

### How do I call an OpenAI-compatible API?

Send a POST to `BASE_URL/chat/completions` with an `Authorization: Bearer` header and a JSON body with `model` and `messages`. With the OpenAI SDKs, set `base_url` (Python) or `baseURL` (Node) and your key; the rest of your code stays the same. For BroadNet Inference the base URL is `https://inference.broadnet.ai/v1`.

### How do I convert a curl request to Python?

Fill in the form once and switch tabs: the builder writes the same request as curl, Python requests, the OpenAI Python SDK, Node fetch and the OpenAI Node SDK, with identical parameters.

### How do I get token usage when streaming?

Add `stream_options: {"include_usage": true}`. The last chunk before `data: [DONE]` carries `usage` and an empty `choices` list, so check for both. [Streaming chat completions](https://broadrouter.com/guides/streaming-chat-completions/).

### What is the difference between JSON mode and structured output?

JSON mode (`response_format: {"type": "json_object"}`) only promises valid JSON, and the prompt must ask for JSON. Structured output (`json_schema` with `strict: true`) makes the reply match your schema. Build a schema with the [JSON schema generator](https://broadrouter.com/tools/json-schema-generator/).

### What does reasoning\_effort do?

On reasoning models it sets how long the model thinks before answering: low, medium or high. Reasoning tokens are billed as output and count toward `max_tokens`, so a low `max_tokens` can return an empty answer. [Why answers come back empty](https://broadrouter.com/guides/reasoning-tokens-empty-response/).

### Can I use this builder with other providers?

Yes. Any OpenAI-compatible base URL works: type it in Base URL and choose "Custom model" to enter its model ID. Parameter support differs between providers, so check their docs for tools, JSON mode and reasoning\_effort.

## Go deeper

-   [curl quickstart](https://broadrouter.com/guides/curl-quickstart/)
-   [OpenAI Python SDK with a custom base URL](https://broadrouter.com/guides/openai-python-sdk/)
-   [OpenAI Node SDK with a custom base URL](https://broadrouter.com/guides/openai-node-sdk/)
-   [Streaming chat completions](https://broadrouter.com/guides/streaming-chat-completions/)
-   [Vercel AI SDK with an OpenAI-compatible API](https://broadrouter.com/guides/vercel-ai-sdk-openai-compatible/)
-   [LangChain with a custom base URL](https://broadrouter.com/guides/langchain-openai-base-url/)

## More free tools

-   [**LLM API cost calculator**Price a workload on every model at once, with cache hits, reasoning and a flat-plan check.](https://broadrouter.com/tools/llm-api-cost-calculator/)
-   [**Speech-to-text cost calculator**Hours, calls or voice notes to a monthly transcription bill, against your current provider.](https://broadrouter.com/tools/speech-to-text-cost-calculator/)
-   [**LLM token counter**Exact token counts with each model's real tokenizer, with a token view and cost.](https://broadrouter.com/tools/token-counter/)
-   [**Arabic token counter**Arabic vs English token counts per tokenizer: the "Arabic tax" in tokens and money.](https://broadrouter.com/tools/arabic-token-counter/)
-   [**Tokens to words converter**Tokens ↔ words ↔ characters ↔ pages, by language and content type.](https://broadrouter.com/tools/tokens-to-words/)
-   [**Context window calculator**Will it fit? Window used per model, room left for output, cost to send.](https://broadrouter.com/tools/context-window-calculator/)
-   [**Flat-rate vs per-token LLM cost calculator**Break-even between an unlimited plan and paying per token, per agent.](https://broadrouter.com/tools/flat-rate-vs-per-token-calculator/)
-   [**Prompt caching savings calculator**Bill with and without caching, by prefix share and hit rate.](https://broadrouter.com/tools/prompt-caching-calculator/)
-   [**Image token calculator**Tokens and cost per image under each model's documented rule. Drop an image; nothing is uploaded.](https://broadrouter.com/tools/image-token-calculator/)
-   [**Self-hosting vs API cost calculator**GPU rental against your current API and BroadNet per-token and flat-plan prices: cost per 1M tokens and break-even volume.](https://broadrouter.com/tools/self-hosting-vs-api-calculator/)
-   [**Embedding cost calculator**Index, update and query costs for a corpus at OpenAI, Google, Voyage, Mistral and Jina list prices.](https://broadrouter.com/tools/embedding-cost-calculator/)
-   [**LLM rate limit and concurrency calculator**Which limit binds first: RPM, TPM or concurrency, with Little's law.](https://broadrouter.com/tools/llm-rate-limit-calculator/)
-   [**JSON schema generator for LLM structured output**Sample JSON to strict schema, Pydantic, Zod and a ready request.](https://broadrouter.com/tools/json-schema-generator/)
-   [**Audio file splitter for speech-to-text limits**Chunk count, overlap and copy-ready ffmpeg commands to fit a transcription file-size limit.](https://broadrouter.com/tools/audio-splitter-ffmpeg/)
-   [**Agent run cost estimator**Context growth per step, total tokens and cost of one agent run, with a DeepSeek session comparison.](https://broadrouter.com/tools/agent-run-cost-estimator/)
-   [**OpenAI to BroadNet migration helper**Paste OpenAI SDK code; get base URL, key and model edits, a diff and the checks that remain.](https://broadrouter.com/tools/openai-to-broadnet-migration/)
-   [**Arabic text normalizer**Tashkeel, tatweel, alef, ya, ta marbuta, digits and invisible characters, with a matching Python function.](https://broadrouter.com/tools/arabic-text-normalizer/)
-   [**RAG chunking calculator**Chunks, embedding tokens, input per query, context check and monthly LLM cost for a RAG pipeline.](https://broadrouter.com/tools/rag-chunking-calculator/)
-   [**max\_tokens calculator for reasoning models**Answer length + reasoning budget + margin = a max\_tokens that does not cut the answer off.](https://broadrouter.com/tools/reasoning-token-budget/)
-   [**LLM batch job planner**Run time, binding limit, cost per model and the flat sessions needed to finish a big job by a deadline.](https://broadrouter.com/tools/llm-batch-job-planner/)
-   [**LLM JSON output validator**Parse errors by line and column, safe repairs, cut-off detection and JSON Schema checks for model output.](https://broadrouter.com/tools/llm-json-output-validator/)
-   [**Prompt token diff**Two prompt versions side by side: changed lines, exact token delta and the monthly cost difference.](https://broadrouter.com/tools/prompt-token-diff/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-api-request-builder&utm_content=page-cta) ·

**Sources**

-   [BroadNet Inference machine-readable prices (pricing.json)](https://inference.broadnet.ai/pricing.json?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-api-request-builder&utm_content=sources)
-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-api-request-builder&utm_content=sources)
