Two request shapes, one app: mapping fields between the formats

APIClaudeKeyFree · Updated 2026-11-24 · 8 min read

Two different travel plug adapters on a desk
Two request formats, one purpose: getting text to a model and back.

If you build with more than one model provider, you will meet two request formats again and again. The OpenAI chat completions format has become a de facto standard that many providers, gateways and open-source servers accept, including the keyless endpoint on this site. Anthropic's native Messages API, used for Claude, has a similar spirit but a different structure. Many tools only accept one of them, which is why developers often end up writing translation code or wondering why a request that works in one place fails in another.

This comparison walks through the differences field by field, from authentication and system prompts to streaming and usage reporting, and ends with a small adapter you can adapt. It describes the formats in general, durable terms; for exact current details, always check each provider's official reference.

Frequently asked questions

What is the OpenAI chat completions format?

It is a JSON request to POST /v1/chat/completions with a model name and a messages list of objects with role and content. The response has a choices list whose first item holds the assistant's message.

What is the Anthropic Messages API?

It is Anthropic's native interface for Claude, a JSON request to POST /v1/messages with model, max_tokens and messages, and a separate top-level system field. The response holds a content list of typed blocks.

How does the system prompt differ between the two?

In the OpenAI format, the system prompt is a message with role system inside the list. In the Messages API, it is a top-level system parameter and the messages list contains only user and assistant turns.

Is max_tokens required?

In the Messages API, max_tokens is required. In the OpenAI format it is optional and the server applies a default. Always setting it is good practice in both.

Which format is better?

Neither is better in general. The OpenAI format is more widely supported across providers, which helps portability. The Messages API maps cleanly to Claude's features, such as typed content blocks. Many teams write their app against one and adapt to the other.

Can I call Claude with the OpenAI SDK?

Anthropic has documented an OpenAI SDK compatibility option, but its scope and support level can change. Check Anthropic's current documentation before relying on it for production; the native SDK is the fully supported route.

Does the free endpoint here speak the Messages format?

No. It accepts the OpenAI format only, at https://api.apiclaudekeyfree.com/v1 with model free-ai. It is not a Claude endpoint, and this site is not affiliated with Anthropic.

How are token counts reported?

The OpenAI format returns usage.prompt_tokens and usage.completion_tokens. The Messages API returns usage.input_tokens and usage.output_tokens. The meaning is the same; only the names differ.

Authentication and headers

The first difference appears before the body. OpenAI-style APIs typically expect an Authorization: Bearer header with the key. Anthropic's API expects the key in an x-api-key header and also requires an anthropic-version header that pins the API version your code was written for. Forgetting the version header is a common cause of confusing errors when calling the native API by hand.

Keyless endpoints such as the one here ignore the authorization header, but OpenAI SDKs still insist on a value, so any placeholder string works.

Version pinning

The Anthropic version header protects your code from breaking changes. Upgrade it deliberately, after reading the provider's change notes.

Keys never in the browser

Both formats are often called from servers. Paid keys should never be embedded in client-side code, whichever format you use.

System prompts and message roles

In the OpenAI format, everything is a message. A system message usually comes first, then alternating user and assistant messages. Some providers also accept multiple system messages or place them mid-conversation, though behaviour varies.

In the Messages API, the system prompt lives in its own top-level field, and the messages list must contain user and assistant turns only, starting with a user turn. Adapters therefore have to pull system messages out of the list and join them into the separate field.

Alternation rules

The Messages API expects user and assistant turns to alternate. If your history has two user messages in a row, merge them before sending.

Assistant prefill

Both formats let you end the list with a partial assistant message in some setups, to steer the start of the reply. Support differs between providers, so test before relying on it.

One envelope with a note clipped outside, another with it inside
One format puts the system prompt inside the message list, the other beside it.

Content: strings versus blocks

In the simplest OpenAI requests, content is a plain string. It can also be a list of parts for images or other inputs on providers that support them. In the Messages API, content can likewise be a string or a list of typed blocks, and the response always returns a list of blocks, each with a type such as text.

This means reading the answer differs. In the OpenAI format you take choices[0].message.content. In the Messages API you join the text of all text blocks in content. Code that assumes one block will break when a response includes several, for example when tools or reasoning are involved.

Read all blocks

Always iterate over the content blocks in a Messages response and collect the ones of type text, rather than reading only the first.

Side-by-side requests

The two requests below ask the same question. The first is the OpenAI format, sent to the keyless endpoint here. The second is the shape of a native Messages API request; replace the key and model with real values from your Anthropic console and documentation.

Notice the system prompt placement, the required max_tokens in the second request, and the different headers.

Model identifiers

Model names differ by provider and change as new versions ship. Read them from configuration rather than hard-coding them, and check the provider's model list for current identifiers.

Same intent, different shape

Once you see both side by side, the mapping is mechanical: move the system message, add required fields, change headers.

# OpenAI chat completions format (keyless endpoint)
curl https://api.apiclaudekeyfree.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "free-ai", "max_tokens": 200,
       "messages": [{"role": "system", "content": "Be brief."},
                    {"role": "user", "content": "What is a webhook?"}]}'

# Anthropic Messages API shape (needs your own key and a current model id)
curl https://api.anthropic.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{"model": "YOUR_MODEL_ID", "max_tokens": 200, "system": "Be brief.",
       "messages": [{"role": "user", "content": "What is a webhook?"}]}'
A bento box beside a single bowl of food
Responses come as one string in one format and as typed blocks in the other.

Responses, stop reasons and usage

An OpenAI-format response contains choices, each with a message and a finish_reason such as stop or length. A Messages API response contains content blocks and a stop_reason such as end_turn or max_tokens. Both signal the same thing: whether the model finished naturally or was cut off.

Usage fields have different names but the same meaning. If you meter usage, as described in per-user token budgets, normalise both into one internal structure.

Detect truncation

Check the finish or stop reason on every response. A truncated answer that looks complete is a common source of broken JSON and half-finished code.

  • Answer text: choices[0].message.content vs joined text blocks in content.
  • Finish signal: finish_reason vs stop_reason.
  • Cut-off value: length vs max_tokens.
  • Token counts: prompt_tokens/completion_tokens vs input_tokens/output_tokens.

Streaming events

Both formats stream with server-sent events, but the event structure differs. OpenAI-style streams send a series of data: lines, each holding a chunk whose choices[0].delta.content contains the next piece of text, and end with data: [DONE]. The free endpoint here follows that pattern.

The Messages API sends named events, such as a message start, content block starts, content block deltas carrying text, and a message stop. A streaming adapter has to translate those events into whatever your UI expects. More on choosing whether to stream at all is in streaming vs full responses.

Use the SDKs for streaming

Both official SDKs parse their own stream formats into convenient objects. Hand-parsing is possible but easy to get subtly wrong.

Normalise early

Convert provider-specific stream events into a single internal event type, such as text delta and done, as close to the network layer as possible.

A river splitting around rocks and rejoining
Streaming events differ in shape but carry the same text.

A thin adapter

Most apps need only a small translation layer: a function that takes OpenAI-style messages and produces the fields the Messages API needs, and another that turns either response into plain text plus usage. The sketch below handles the common text-only case. It does not cover tools, images or streaming, which need more work.

Keeping the app's internal format close to the OpenAI style is a practical choice, because so many backends accept it directly. Then only one adapter is needed, for the Messages API.

Scope it honestly

Start with text-only support and add features as you need them. A partial adapter that is well tested beats a complete one that nobody trusts.

Test both directions

Run your regression prompts through each backend after adapter changes, so a mapping bug does not reach users.

def to_messages_api(openai_messages):
    system = "\n\n".join(m["content"] for m in openai_messages if m["role"] == "system")
    turns = []
    for m in openai_messages:
        if m["role"] == "system":
            continue
        if turns and turns[-1]["role"] == m["role"]:
            turns[-1]["content"] += "\n\n" + m["content"]  # keep strict alternation
        else:
            turns.append({"role": m["role"], "content": m["content"]})
    return system, turns

def text_and_usage(resp, fmt):
    if fmt == "openai":
        u = resp.get("usage") or {}
        return resp["choices"][0]["message"]["content"], u.get("prompt_tokens"), u.get("completion_tokens")
    text = "".join(b.get("text", "") for b in resp["content"] if b.get("type") == "text")
    u = resp.get("usage") or {}
    return text, u.get("input_tokens"), u.get("output_tokens")

system, turns = to_messages_api([
    {"role": "system", "content": "Be brief."},
    {"role": "user", "content": "Hi"},
    {"role": "user", "content": "What is a webhook?"},
])
print(system, turns)

Parameters that do not map one to one

Beyond the core fields, both formats accept optional parameters that control generation. Temperature and top_p exist in both, though accepted ranges and defaults can differ, so a value tuned for one provider may behave differently on another. Stop sequences are called stop in the OpenAI format and stop_sequences in the Messages API. Some OpenAI-format parameters, such as requesting several alternative completions with n, have no direct equivalent in the native Claude API.

Provider-specific extras need care too. The free endpoint here accepts an optional "reasoning": true field, which is not part of either standard format. Claude has its own extended thinking settings with different field names. An adapter should pass such options through only to the backend that understands them, and drop or translate them for the others.

Keep a mapping table

Document which internal option maps to which field on each backend, including options that are unsupported. It makes behaviour predictable and saves debugging time when a parameter silently has no effect.

Validate before sending

Reject or strip unknown fields in your adapter. Some APIs return an error for unexpected parameters, others ignore them silently, and both outcomes are confusing if you do not know which to expect.

Retest tuned values

Temperature and length settings tuned on one model rarely transfer perfectly. After switching backends, re-run a few representative prompts and adjust.

A pipe fitting joining two pipes of different sizes
A thin adapter lets the same app talk to both formats.

When the difference matters for resilience

Format differences become urgent during incidents. If your app speaks only one format and its provider is unavailable, rate limited or your account is blocked, every alternative that uses the other format is out of reach until someone writes an adapter under pressure. The scenarios in what to do after an account suspension are much easier to survive with an adapter already in place.

The keyless endpoint here is one OpenAI-format backend you can keep as a fallback. It serves free-ai, an independent open-weight model of about 35B parameters that is not Claude; this site is not affiliated with Anthropic. For demanding tasks Claude will usually be the stronger model, and the adapter simply lets you choose per situation.

Write it before you need it

An adapter written calmly and tested on a normal day is far more reliable than one written during an outage.

Try the free API

Send a test request to the keyless, OpenAI-compatible endpoint on the home page and see how it fits your project.

Read also