Skip to content

OpenAI-compatible Chat Completions

Get an API key to send requests.

POSThttps://gptunnel.ru/v1/chat/completions

Get the full model response as JSON or receive it in an SSE stream. Choose an available model from the catalog and pass the conversation history in messages.

Request headers

ParameterTypeRequired?Description
AuthorizationstringRequiredAPI key

Request body

ParameterTypeRequired?Description
model#stringRequiredExact ID from GET /v1/models catalogue, e.g. gpt-6-luna
messages#arrayRequiredConversation history that provides context for the request.
stream#boolOptionalSet to true to stream the response over SSE. By default, the API returns the full response as JSON.
stream_options#objectOptionalWith stream: true, pass {"include_usage":true} to request token usage statistics.
max_tokens#numberOptionalMaximum number of tokens in the response. The supported limit depends on the model.
max_completion_tokens#numberOptionalAlternative name used by newer OpenAI SDKs. It applies when max_tokens is omitted.
temperature#numberOptionalControls sampling randomness on a scale from 0 to 1.
top_p#numberOptionalNucleus sampling. Does not apply to Claude models.
frequency_penalty#numberOptionalPenalty for repeated tokens. Does not apply to Claude models.
presence_penalty#numberOptionalPresence penalty. Does not apply to Claude models.
stop#string | string[]OptionalOne or more stop sequences. The model ends its response before a matching sequence.
functions#objectOptionalDefinitions of functions
tools#object[]OptionalDefinitions of tools available to models
tool_choice#string | objectOptionalTool choice: auto, none, required, or an object such as {"type":"function","function":{"name":"your_function"}}.
parallel_tool_calls#boolOptionalSet to false to limit the model to one tool call per response.
response_format#objectOptionalUse {"type":"json_object"} or set type to json_schema and include the json_schema object. See Structured output for a complete example.
reasoning_effort#stringOptionalReasoning effort, for example none, low, medium, or high. See Reasoning effort.
useWalletBalance#boolOptionalUse a personal account
web_search#boolOptionalEnable web search for this request.
obfuscate#boolOptionalMask personal data (PII) with placeholders before sending the prompt to the model. GPTunneL restores the original values in the response (alpha).
obfuscate_patterns#object[]OptionalCustom regex patterns for masking when obfuscate is enabled. Supply up to 20 entries of the form { pattern, label? }.

With obfuscate: true, GPTunneL replaces detected personal data in message text with placeholders before sending the request to the model. The original values are restored in the response, including streamed text and tool call arguments. The detector does not process images, and coverage depends on what it recognizes. If the masking service is unavailable, the API returns 503 without sending raw data to the provider.

See Personal Data Obfuscation for recognized data types, guarantees, and limitations.

Obfuscation costs 280 ₽ per 1 million tokens of message text scanned, in addition to the model’s price. There is no obfuscation charge for response tokens. See pricing.

Reasoning models use additional tokens before answering. Use reasoning_effort to control how much reasoning a model performs.

Value Behavior
none Request to disable reasoning if the model supports it
low Low reasoning level
medium Medium reasoning level
high High reasoning level
{
"model": "deepseek-v4-flash",
"messages": [{ "role": "user", "content": "Сколько будет 17 × 23?" }],
"reasoning_effort": "none"
}

Parameter availability depends on the model. Reasoning tokens are included in completion_tokens and billed as response tokens. Disabling reasoning can reduce token usage and waiting time.

On deepseek-v4-flash and deepseek-v4-pro, forced function calls are incompatible with reasoning. If you send tool_choice: "required" or tool_choice: {"type": "function", ...}, also set reasoning_effort: "none". Otherwise, the request takes longer than usual.

The response_format parameter accepts two forms.

  • {"type": "json_object"} asks the model to return a single JSON object.
  • {"type": "json_schema", "json_schema": {"schema": {...}}} requests a response that conforms to the supplied schema.

In OpenAI models, the parameter works as in the original API. For Claude, both forms are translated into Anthropic with different result guarantees. In other models, the field is passed directly to the provider without any modifications — see the note at the end of the section.

json_schema uses Claude’s native structured output. Anthropic requires additionalProperties: false on each object node. GPTunneL adds it where no value was supplied. GPTunneL does not resolve $ref or expand definitions. Inline referenced definitions in your schema before sending the request. A model that does not support structured output returns HTTP 400.

With json_object on Claude, GPTunneL adds a system instruction asking for a single JSON object. If the model wraps the response in a Markdown code fence, GPTunneL removes the fence. Valid JSON is not guaranteed in this mode. Validate the response and retry if needed.

If a strict JSON is needed without this layer, Claude models have a second entry point — Anthropic-compatible /v1/messages. The schema is transmitted via output_config; the limitations for models are described on the page for this format.

With gpt-6-luna, the request below returned HTTP 200 and the string {"answer":4} in choices[0].message.content. For JSON mode without a schema, replace the entire response_format value with {"type":"json_object"}. Keep the word “JSON” in the user message. This variant returned the same string with the same model.

curl --fail-with-body --silent --show-error \
--url 'https://gptunnel.ru/v1/chat/completions' \
--header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
--json '{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Return JSON with an integer answer field. What is 2 + 2?"
}
],
"max_completion_tokens": 128,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": { "answer": { "type": "integer" } },
"required": ["answer"],
"additionalProperties": false
}
}
}
}'

Set GPTUNNEL_API_KEY and select the standard response or stream.

import json
import os
from urllib.request import Request, urlopen
body = {
'model': "gpt-6-luna",
'messages': [{"role":"user","content":"What's 2 + 2? Answer with a digit."}],
'max_completion_tokens': 128,
}
request = Request(
'https://gptunnel.ru/v1/chat/completions',
method='POST',
headers={
'Authorization': os.environ['GPTUNNEL_API_KEY'],
'Content-Type': 'application/json',
},
data=json.dumps(body).encode('utf-8'),
)
with urlopen(request, timeout=30) as response:
print(json.load(response)['choices'][0]['message']['content'])

Read the response text from choices[0].message.content and the total cost from usage.total_cost. Here is an excerpt from a verified response using gpt-6-luna.

{
"object": "chat.completion",
"model": "gpt-6-luna",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "4" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 19,
"total_tokens": 39,
"prompt_cost": 0.0004,
"completion_cost": 0.0019,
"total_cost": 0.0023
}
}

Select Streaming (SSE) in the request example above. With stream: true, the server responds as text/event-stream. In the response below, gpt-6-luna returned the digit 4:

data: {"choices":[{"index":0,"delta":{"content":"4"},"finish_reason":null}]}

The streaming guide explains how to assemble text and tool arguments, record usage and detect an interrupted connection.

Set "web_search": true in the request body. The example below returned an answer with links to MDN documentation when run with gpt-6-luna.

{
"model": "gpt-6-luna",
"max_completion_tokens": 128,
"messages": [
{
"role": "user",
"content": "Найди официальную страницу MDN про Server-sent events. Ответь одним предложением со ссылкой."
}
],
"web_search": true
}

The API returns sources in choices[].message.annotations. This excerpt shows one source from the verified response.

{
"title": "Using server-sent events - Web APIs | MDN",
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events"
}

In a stream, look for sources in choices[].delta.annotations. The usage object includes the tokens and cost of model calls for search and the final response.

For Claude models, GPTunneL automatically enables prompt caching at the provider. Caching can speed up requests with the same long prefix, such as a system prompt, instructions, or a catalog. You can also set cache_control breakpoints on message blocks or pass prompt_cache_key for OpenAI-compatible models. The request format stays the same.

Billing depends on the account that pays for the request.

Personal account. All prompt tokens are charged at the model’s standard input rate, regardless of provider-side cache hits. GPTunneL retains any cache savings. Billable input for the same request remains consistent.

Business account. An organization owner or administrator enables prompt caching in the business dashboard under API → Prompt caching in API. It is off by default.

  • Enabled. Cache reads cost less than regular input and cache writes cost more. GPTunneL sets Claude cache breakpoints even if you omit cache_control. The first request with a new long prefix writes it to the cache and costs more. A repeated request with the same prefix can read the cache and costs less. Claude uses Anthropic multipliers relative to the regular input price: ×0.1 for reads, ×1.25 for a 5-minute write, and ×2.0 for a 1-hour write. Other model families offer different read discounts, such as ×0.5 for OpenAI models, and charge standard input rates for writes.
  • Disabled. GPTunneL adds no breakpoints and removes cache_control and prompt_cache_key from your request. All prompt tokens are charged at the standard input rate. Some providers, such as OpenAI, still cache automatically. This automatic cache has no effect on the price when the setting is off.

The provider’s cache counters appear in usage when available:

{
"usage": {
"prompt_tokens": 12480,
"prompt_tokens_details": { "cached_tokens": 11900, "cache_write_tokens": 520 },
"completion_tokens": 210,
"total_tokens": 12690,
"prompt_cost": 0.3744,
"completion_cost": 0.0189,
"total_cost": 0.3933
}
}
  • prompt_tokens is the total prompt token count, including cache reads and writes.
  • prompt_tokens_details.cached_tokens is the number of prompt tokens read from cache.
  • prompt_tokens_details.cache_write_tokens is the number written by this request. The field name follows OpenRouter. It appears when the provider reports cache writes, for example Claude or OpenRouter. Providers with fully automatic caching may not report writes.
  • prompt_cost is the input cost for your tariff. With caching off it is prompt_tokens multiplied by the input price. With caching on, the relevant multipliers apply.

Streaming returns the same fields in the last chunk containing usage. To see cost and cache usage by key and model, go to the business dashboard and open Analytics → API.

Check the HTTP status, then read error.type, error.code, and error.param. When error.param is set, it identifies the field to check in the request body. For errors from other services, see API Error Diagnostics.

Unknown model (404) #

Find the exact ID in the catalog of models available to your key and pass it in the model field. For an unknown ID, the verified response is shown below.

{
"error": {
"message": "Model not found",
"type": "invalid_model_error",
"param": "model",
"code": null
}
}

No model field (400) #

Include model as a top-level field alongside messages.

{
"error": {
"message": "model is required",
"type": "invalid_request_error",
"param": "model",
"code": null
}
}
HTTP What to check
401 Check that the Authorization header contains an active API key.
402 Check the balance of the account selected for the request.
403 / model_not_allowed Check the allowed models in your key settings and the model catalog.
503 / obfuscation_unavailable The PII masking service is temporarily unavailable.