Create chat completion
Creates a model response for the given chat conversation. OpenAI-compatible — point an OpenAI SDK at the Platform API base URL and swap the API key to migrate most apps.
Supports streaming via SSE (stream: true), function calling, structured output (json_schema), and multi-modal input (images, files).
Supported request fields: messages, model, max_completion_tokens (or its deprecated alias max_tokens), temperature, tools, parallel_tool_calls, reasoning_effort, response_format, stream, stream_options, prompt_cache_key, custom_gpt_id. Other OpenAI fields — including top_p, n, stop, presence_penalty, frequency_penalty, seed, user, logit_bias, and tool_choice — are silently ignored. If you need tool_choice, use /v2/responses.
Custom GPTs. Send custom_gpt_id to answer with a Custom GPT: its instructions and attached files are applied server-side, while model from your request is always used. See the custom_gpt_id field below.
Prompt caching (Anthropic models). Cache lifetime is five minutes only — ttl: "1h" is
NOT supported on this endpoint. Mark the last element of a stable prefix with
cache_control and that prefix is cached upstream, so a later request that repeats it
byte-for-byte is billed at the cache-read rate. Nothing is cached unless you ask: we never
insert breakpoints on your behalf, because whether a cache write pays for itself depends
on your access pattern, not on ours. Every cache lives five minutes — ttl: "1h" is
accepted but not supported yet, and is reported as marker_ttl_unsupported rather than
applied. prompt_cache in the response carries that warning plus any marker we could not
place exactly as written. See Billing → Prompt caching.
Prompt caching (Mistral models). Mistral caches prefixes automatically, so cache_control
does nothing there — send prompt_cache_key instead: one stable string per conversation or
session, repeated on every request that shares a prefix. It is applied unconditionally and
costs nothing extra (Mistral has no cache-write premium), your value is namespaced to your
workspace, and a hit is a likelihood rather than a guarantee. See
Billing → Mistral models.
Tool calls re-send the whole prompt
A request with tools takes several model steps. With your own function tools, every round trip (your tool result sent back) is a new request that carries the whole conversation again. With a custom GPT (custom_gpt_id), the knowledge search, and reading its CSV or Excel files as tables, add model steps on our side within the one request. Every step pays for
the whole prompt again, so without caching one request with tools can cost several times a
single answer.
Mark the stable part of your prompt with cache_control (see Billing → Prompt caching): each
later step then reads it at the cache-read rate. Measured on our side for a two-step request
with a 7,600-token prompt and a cache point at the end of each step: about 20 % cheaper with
a cold cache, and up to about 80 % cheaper when the same prompt comes again within five
minutes.
Time limits. A request without stream: true is limited to 5 minutes in total and is aborted if the generation takes longer. For long generations, use stream: true: a stream has no total time limit (its length is bounded by max_completion_tokens) and is ended only after 5 minutes without model output, with a data: chunk carrying an error object, without [DONE]. While the model is working without output you can see, the stream carries a keepalive every 15 seconds: an SSE comment line (: keepalive), which SSE clients ignore.
Output limit. max_completion_tokens (or max_tokens) caps the completion, reasoning tokens included. Without it, most models may write up to their maximum output length. A completion cut off by the limit ends with finish_reason: "length".
Example request
curl https://api.deutschlandgpt.de/v2/chat/completions \
-X POST \
-H "Authorization: Bearer $DGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "system",
"content": null
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": false,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": true,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
}'curl https://api.deutschlandgpt.de/v2/chat/completions \
-X POST \
-H "Authorization: Bearer $DGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "system",
"content": null
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": false,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": true,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
}'import os, requests
response = requests.post(
"https://api.deutschlandgpt.de/v2/chat/completions",
headers={"Authorization": f"Bearer {os.environ['DGPT_API_KEY']}"},
json={
"messages": [
{
"role": "system",
"content": None
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": False,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": True,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
},
)
print(response.json())import os, requests
response = requests.post(
"https://api.deutschlandgpt.de/v2/chat/completions",
headers={"Authorization": f"Bearer {os.environ['DGPT_API_KEY']}"},
json={
"messages": [
{
"role": "system",
"content": None
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": False,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": True,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
},
)
print(response.json())const response = await fetch('https://api.deutschlandgpt.de/v2/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.DGPT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"messages": [
{
"role": "system",
"content": null
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": false,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": true,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
}),
});
console.log(await response.json());const response = await fetch('https://api.deutschlandgpt.de/v2/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.DGPT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"messages": [
{
"role": "system",
"content": null
}
],
"model": "gpt-4o",
"max_completion_tokens": 0,
"max_tokens": 0,
"temperature": 0,
"stream": false,
"stream_options": {},
"tools": [
{
"type": "function",
"function": {
"name": "string"
}
}
],
"parallel_tool_calls": true,
"reasoning_effort": "none",
"response_format": {
"type": "text"
},
"prompt_cache_key": "conversation-42",
"custom_gpt_id": "00000000-0000-0000-0000-000000000000"
}),
});
console.log(await response.json());Request body
messagesMessage[]requiredConversation history. Include system, user, assistant, tool, and developer messages.
modelstringrequiredModel ID (e.g. gpt-4o, claude-4.5-sonnet, gemini-2.5-flash). Use /v2/models to list available text models.
max_completion_tokensintegeroptionalUpper bound for generated tokens, including visible output and reasoning tokens. If you send no limit, most models may write up to their maximum output length.
max_tokensintegeroptionalDeprecated alias of max_completion_tokens, accepted because OpenAI SDKs still send it. If both are set, max_completion_tokens applies.
temperaturenumberoptionalSampling temperature (0–2). Higher = more random output. Do not set both temperature and top_p.
streambooleanoptionalIf true, stream incremental tokens as server-sent events. Each data: line is a JSON delta. Stream terminates with data: [DONE]. Not compatible with json_schema response format.
stream_optionsobjectoptionalOptions for streaming responses. Only valid when stream: true.
include_usagebooleanoptionalIf true, send a final chunk with token usage statistics before [DONE].
toolsFunctionTool[]optionalFunctions the model may call. When the model calls a function, return the result in a tool message.
typestringrequiredfunctionobjectrequirednamestringrequiredFunction name (a-z, A-Z, 0-9, underscores, dashes)
descriptionstringoptionalWhat the function does — used by the model to decide when to call it
parametersobjectoptionalJSON Schema describing function parameters
cache_controlCacheControloptionalCache the tool definitions (and the system prompt with them, since Anthropic orders tools first). Requires a system message in the same request — with none, the marker is dropped rather than moved onto the first user turn, which would change every request and never produce a hit.
typestringrequiredttlstringoptionalCache lifetime. On THIS endpoint 1h is NOT SUPPORTED: it is accepted so an existing integration keeps working, but the breakpoint is placed with the default five-minute lifetime, billed at the five-minute cache-write rate (1.25x the input rate, not 2x), and reported as a marker_ttl_unsupported warning in prompt_cache. Because every breakpoint therefore has the same lifetime, mixing the two values is accepted and Anthropic's 1h-before-5m ordering rule is not enforced. 1h IS honoured on /anthropic/v1/messages, where cache_control is Anthropic's own field. Where nothing is cached the markers are ignored entirely.
parallel_tool_callsbooleanoptionalAllow the model to call multiple tools in a single turn.
reasoning_effortstringoptionalReasoning budget for reasoning models (e.g. o3, o4-mini). Lower = faster and cheaper; none disables extended thinking.
response_formatobject | objectoptionalConstrain the output format. Use json_schema for structured output (streaming not supported).
prompt_cache_keystringoptionalOptional stable identifier for requests that share a prompt prefix — a conversation, session or workflow id. Raises the prompt-cache hit rate on models that cache prefixes automatically (Mistral). Ignored by models that cache on explicit cache_control breakpoints (Anthropic) and by models with no prompt cache. Your value is namespaced to your workspace server-side, so it can never collide with another tenant or aim at their cache. Hits are best-effort and never guaranteed — a miss is billed exactly like an uncached request, so there is nothing to lose by sending it. Do not put secrets or personal data in it.
custom_gpt_idstring<uuid>optionalOptional ID of a Custom GPT to apply. Its instructions are prepended as a system message (your own system messages still follow), and its attached files are searched server-side and used for the answer; the search itself is not shown in the response. The Custom GPT's own model is ignored: model is still required and always decides. List the IDs with GET /v2/custom-gpts. If the API key is restricted to specific Custom GPTs, this one must be allowed, otherwise the request fails with 404, as it does for an unknown ID.
Response
{
"id": "chatcmpl-xR4qT5Uy",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "string",
"tool_calls": [
null
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
}
},
"prompt_cache": {
"cache_write_tokens": {
"5m": 0,
"1h": 0
},
"warnings": [
{
"code": "breakpoint_limit_exceeded",
"message": "string"
}
]
}
}{
"id": "chatcmpl-xR4qT5Uy",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "string",
"tool_calls": [
null
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
}
},
"prompt_cache": {
"cache_write_tokens": {
"5m": 0,
"1h": 0
},
"warnings": [
{
"code": "breakpoint_limit_exceeded",
"message": "string"
}
]
}
}Chat completion (JSON) or SSE stream when stream: true
Also available as text/event-stream
idstringobjectstringcreatedintegerUnix timestamp
modelstringchoicesChatCompletionChoice[]indexintegermessageobjectrolestringcontentstring | nulltool_callsToolCall[]finish_reasonstring | nullusageUsageprompt_tokensintegercompletion_tokensintegertotal_tokensintegerprompt_tokens_detailsobjectThe cache split of prompt_tokens. prompt_tokens is the INCLUSIVE total, so these are subsets of it, not additions to it.
cached_tokensintegerInput tokens served from the prompt cache, billed at the cache-read rate.
cache_write_tokensintegerInput tokens written to the prompt cache.
prompt_cacheobjectDeutschlandGPT extension. What happened to the cache_control breakpoints you sent. Omitted entirely when there is nothing to report, so a request without cache_control is unchanged. See Billing -> Prompt caching.
cache_write_tokensobjectCache-write tokens by TTL, as the upstream host reported them: 125% of the input rate for 5m, 200% for 1h. On /v2/chat/completions and /v2/responses the 1h bucket is always 0, because those endpoints do not support the one-hour cache and write a ttl: "1h" breakpoint with the five-minute lifetime instead.
5mintegerTokens written at the default 5-minute TTL.
1hintegerTokens written at the extended 1-hour TTL.
warningsobject[]Breakpoints that could not be honoured exactly as written. Present only when at least one was affected.
codestringrequiredStable machine-readable reason, so a client can branch without parsing prose.
messagestringrequiredHuman-readable explanation naming the affected position.
Response codes
Chat completion (JSON) or SSE stream when stream: true
Validation error or unsupported combination
ErrorMissing or invalid API key
ErrorInsufficient credits
ErrorFeature not enabled for this workspace
ErrorModel not found
Error