Skip to content

Claude via the OpenAI format

Call Claude models through the OpenAI Chat Completions endpoint (/v1/chat/completions) — model names, how thinking parameters are converted, images, tool calling, and the Claude features you can't use this way.

If you already use the OpenAI SDK, or a tool only supports the OpenAI format, change model to a Claude model name and call Claude through the Chat Completions endpoint. The gateway converts the request to Claude's Messages format for the upstream, then converts the response back to the OpenAI format. It serves the Claude models in Model Square that are also marked with the OpenAI endpoint type; the key's group decides which of them you can use (see Groups).

POST https://codaapi.com/v1/chat/completions

When you need features specific to Claude (see Claude features you can't use), use the Messages API instead.

Request headers

Name Required Description
Authorization Yes Bearer sk-…. This endpoint doesn't read x-api-key
Content-Type Yes application/json

Request body

The request is written as for OpenAI's Chat Completions. The table shows what the common parameters become on the Claude side. Parameters not in the table (for example n, logprobs, frequency_penalty, presence_penalty and seed) have no Claude equivalent and aren't sent upstream.

Parameter Type Required Becomes on the Claude side
model string Yes Claude model name, for example claude-sonnet-4-6. Names with a -thinking suffix work too; see Thinking parameters
messages array Yes system and developer messages are merged into Claude's system; tool_calls in assistant messages become tool_use blocks; tool messages become tool_result blocks. If the first message isn't user, the gateway adds a placeholder user message
max_completion_tokens or max_tokens integer No max_tokens. If neither is set, the gateway fills in a default; set it yourself for long answers or with thinking on
stream boolean No Streaming; see Streaming
temperature, top_p, top_k number No Passed through. With thinking on, sampling parameters the model doesn't accept are removed
stop string or array No stop_sequences
reasoning_effort string No Extended thinking; see Thinking parameters
reasoning object No Another way to set extended thinking (effort, max_tokens, enabled, exclude); see Thinking parameters
tools, tool_choice, parallel_tool_calls — No Claude's tool definitions and tool_choice; see Tool calling
web_search_options object No Claude's web search tool, carrying only user_location; see Web search. Whether it works depends on the model and the channel behind it

Thinking parameters

There are three ways to make Claude think. The gateway converts each into the thinking parameters the model supports:

Form Effect
"reasoning_effort": "low" (or minimal, low, medium, high, xhigh, max) Turns thinking on. Models that support adaptive thinking get {"type": "adaptive"} with the strength in output_config.effort; a level the model doesn't have is replaced with the nearest one. Models that only support the older form get {"type": "enabled"}, with budget_tokens set to a share of max_tokens by level (at least 1024 and less than max_tokens)
"reasoning": {"max_tokens": 4096} Sets a thinking budget. Models that support the older form use it as budget_tokens; models that only support adaptive thinking convert it to the nearest level
"reasoning_effort": "none" or "reasoning": {"enabled": false} Turns thinking off. Models that can't turn thinking off use their lowest setting instead
A model name ending in -thinking, for example claude-sonnet-4-6-thinking Turns thinking on and returns the thinking in the response. If it conflicts with thinking parameters in the request, the model name wins. See Claude format

A reasoning_effort value other than those above returns 400. "reasoning": {"exclude": true} means think, but don't return the thinking.

The thinking the model returns is in choices[0].message.reasoning_content (in delta.reasoning_content when streaming). This isn't a standard OpenAI field, and some clients don't show it.

Images

Put images in the content array as in OpenAI's format:

{
  "role": "user",
  "content": [
    {"type": "text", "text": "What's in this image?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
  ]
}

url can be an address reachable from the public internet or a data:image/png;base64,… URL. For an address, the gateway downloads the image first and sends it to Claude as base64, so the address must be publicly reachable. PDFs (file content) become Claude document blocks; Claude doesn't support audio or video, so those parts are dropped.

Tool calling

Tools in tools with type function become Claude tool definitions (parameters becomes input_schema). Write each tool the OpenAI way, with the function inside function; this endpoint doesn't accept Claude's native form (name and input_schema at the top level). See Function calling for an example. The tool_choice values auto, required, none and a named function map to Claude's auto, any, none and tool; "parallel_tool_calls": false maps to Claude's disable_parallel_tool_use.

When the model wants to call a tool, finish_reason is tool_calls and the calls are in message.tool_calls. After running the tool, add the result to messages as a role: "tool" message with the matching tool_call_id, and send the request again.

Request examples

curl

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "What is an API gateway?"}]
  }'

Python (pip install openai)

from openai import OpenAI

client = OpenAI(
    base_url="https://codaapi.com/v1",
    api_key="sk-your-key",  # better to read it from the OPENAI_API_KEY environment variable
)

response = client.chat.completions.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "What is an API gateway?"}],
)
print(response.choices[0].message.content)

Node.js (npm install openai)

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://codaapi.com/v1',
  apiKey: process.env.OPENAI_API_KEY,
});

const completion = await client.chat.completions.create({
  model: 'claude-sonnet-4-6',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'What is an API gateway?' }],
});
console.log(completion.choices[0].message.content);

Forcing thinking

Switch to the model name with the -thinking suffix. The request needs no thinking parameters, and the response includes the thinking; if you leave out max_tokens, the gateway fills it in:

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6-thinking",
    "messages": [{"role": "user", "content": "How many r letters are in the word strawberry?"}]
  }'
response = client.chat.completions.create(
    model="claude-sonnet-4-6-thinking",
    messages=[{"role": "user", "content": "How many r letters are in the word strawberry?"}],
)
message = response.choices[0].message
print(message.content)
# The thinking isn't a standard OpenAI field, so read it with getattr
print(getattr(message, "reasoning_content", None))

In the returned message, the answer is in content and the thinking is in reasoning_content:

{
  "role": "assistant",
  "content": "There are 3 r's in strawberry.",
  "reasoning_content": "Let me spell it out: s-t-r-a-w-b-e-r-r-y…"
}

Models with the -thinking suffix are only in some groups; see Claude format. To control thinking with parameters such as reasoning_effort instead of changing the model name, see Thinking parameters.

Image understanding

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
      ]
    }]
  }'

For the requirements on image addresses and base64, see Images above.

Function calling

Define tools in OpenAI's function format: set type to function and put the function's name, description and JSON Schema parameters inside function. The gateway turns them into Claude tool definitions:

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}},
          "required": ["location"]
        }
      }
    }],
    "messages": [{"role": "user", "content": "What is the weather like in San Francisco?"}]
  }'

When the model decides to check the weather, finish_reason is tool_calls and message.tool_calls holds the function to call and its arguments (arguments is a JSON string). After running the function, add the model's reply and then the result to messages and send the request again: the result goes in a role: tool message whose tool_call_id matches the call's id. For a complete round trip, see Function calling and structured output.

Add OpenAI's web_search_options to the request, and the gateway turns it into Claude's web search tool; the search runs upstream:

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "How do I update a web app to TypeScript 5.5?"}],
    "web_search_options": {}
  }'

To bias the results toward a place, add user_location. The country (two-letter country code), city, region and timezone in approximate are passed on:

"web_search_options": {
  "user_location": {
    "type": "approximate",
    "approximate": {"country": "US", "city": "San Francisco"}
  }
}

The answer is in choices[0].message.content, and the pages it cites are in choices[0].message.annotations: each item has type set to url_citation, with the page's address and title in url_citation.url and url_citation.title.

This way you can only set a location: Claude-specific parameters such as max_uses (the most searches one request may run), allowed_domains and blocked_domains can't be written in web_search_options, and search_context_size has no Claude equivalent. If you need them, use the native API instead; see Web search in the Claude format. Whether it works depends on the model and the channel behind it.

Response

The response is in the OpenAI Chat Completions format:

{
  "id": "msg_01…",
  "object": "chat.completion",
  "model": "claude-sonnet-4-6",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "An API gateway is…"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 180,
    "total_tokens": 205,
    "prompt_tokens_details": {"cached_tokens": 0}
  }
}
Field Description
choices[0].message.content The answer text
choices[0].message.reasoning_content The thinking (only when the model returns it; see Forcing thinking)
choices[0].message.tool_calls Tools to call
choices[0].finish_reason Converted from Claude's stop_reason: end_turn and stop_sequence → stop, max_tokens → length, tool_use → tool_calls, refusal → content_filter
usage Token counts; prompt_tokens_details.cached_tokens is the tokens read from the prompt cache

Streaming

With "stream": true the response comes in OpenAI's SSE format: one data: {…} line per chunk, text in choices[0].delta.content, thinking in choices[0].delta.reasoning_content, and a final data: [DONE] line. By default the last chunk carries usage.

Claude features you can't use

After conversion from the OpenAI format, the following aren't available. If you need them, use the Messages API:

  • Prompt cache breakpoints: cache_control written in the OpenAI format isn't passed to Claude.
  • Structured output: response_format (JSON mode, JSON Schema) isn't converted, so Claude never sees the requirement. For output in a fixed shape, use tool calling or the native API.
  • Claude server tools other than web search: Claude-specific tool types such as code execution, web fetch and the MCP connector can't be expressed in the OpenAI format.
  • Web search parameters: web search can only be turned on with web_search_options, and nothing but the location can be set; max_uses, allowed_domains and blocked_domains have to be set through the native API (see Web search).
  • Sending thinking back: in a multi-turn conversation, the reasoning_content of earlier assistant messages isn't sent back to Claude (Claude's thinking blocks have to be returned unchanged with their signatures). With thinking on and multi-turn tool calls, the native API is the safer choice.
  • Audio and video input: Claude doesn't support them, so they're dropped.

Errors

Errors come back in the OpenAI format ({"error": {"message": …, "type": …, "code": …}}), with the request id at the end of message. See Error formats; for what to do about each status code, see Troubleshooting.

Billing

Same price as calling the same model through the native API, based on the usage the upstream returns. For the rules, see Pricing and multipliers; for each group's prices, see the price list.

Updated