Skip to main content
Glama

Create chat completion

create_chat_completion
Destructive

Send OpenAI-format chat messages to any supported model to get text, tool calls, or images. Use it when you need one completions endpoint across Anthropic, Gemini, and OpenAI routes.

Instructions

OpenAI-compatible chat completions endpoint, multiplexed across every model Gumloop supports (Anthropic, OpenAI, Google Gemini, OpenRouter routes). Set stream: true for Server-Sent Events, or omit it for a unary JSON response. Image-generation models (gpt-image-*, gemini-*-image-preview, dall-e-*) are dispatched automatically when modalities includes "image" and yield image attachments on choices[0].message.images.

Streaming host

Chat completions live on the streaming host. Send all requests — unary or streaming — to:

POST https://ws.gumloop.com/api/v1/chat/completions

api.gumloop.com does not serve this endpoint; the Python SDK routes there automatically.

Tool calls, images, and tool_choice

Send messages in the OpenAI shape and Gumloop translates them for the model's provider (Anthropic, OpenAI, and Google Gemini). Models served through OpenRouter and other OpenAI-compatible providers receive the messages as sent.

  • Tool-result turns: after the model replies with finish_reason: "tool_calls", append its assistant message (with tool_calls) and one {"role": "tool", "tool_call_id": ..., "content": ...} message per call, then send the conversation again. Every tool call needs a matching tool message, and every tool message must match a tool call in an earlier assistant message.

  • Images: user messages accept image_url content parts alongside text parts. The URL can be an http(s) URL or a base64 data URL (data:image/png;base64,...). Images must be JPEG, PNG, GIF, or WebP and at most 20 MB. Redirects are not followed when downloading an image.

  • tool_choice: "auto" (the default when tools are sent), "none", "required", or {"type": "function", "function": {"name": "..."}} to force one tool.

  • developer messages are treated like system messages.

{
  "model": "claude-sonnet-4-5",
  "tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}],
  "messages": [
    {"role": "user", "content": [
      {"type": "text", "text": "What's the weather where this photo was taken?"},
      {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
    ]},
    {"role": "assistant", "content": null, "tool_calls": [
      {"id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Ottawa\"}"}}
    ]},
    {"role": "tool", "tool_call_id": "call_1", "content": "12°C and sunny"}
  ]
}

A request that can't be translated returns 400 invalid_request with param set to the field at fault (for example messages[3].tool_call_id). When the provider itself rejects the request (HTTP 400, 404, 413, or 422), the error message relays the provider's reason, prefixed with The provider rejected the request:.

Billing

Each completion charges the caller's credit balance based on token usage (with cache-token semantics per provider) plus a flat 30-credit fee for image-gen calls. Users who configure their own provider API key get a 50% discount. Explicit confirmation is required for this exact account operation. Runs can spend credits or trigger downstream actions; never resubmit unknown outcomes automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelNoModel slug. Use the `id` from `GET /models` or one of Gumloop's preset routes.
toolsNoOpenAI-shape tool definitions (`{type: "function", function: {name, description, parameters}}`). Pass `tool_choice` to constrain selection.
streamNoOnly non-streaming JSON is supported. Streaming requests are refused before fetch.
accountNoNamed private Gumloop account; selects private credentials and user/team identity.
confirmNoSet true only when the user asked for exactly this action.
payloadNoComplete JSON request body instead of body flags. Preserves current endpoint fields and values.
messagesNo
providerNoOpenRouter provider routing config. Caller fields like `sort` and `order` are honored; ZDR/data_collection policy is server-enforced.
modalitiesNoOutput modalities. Include `"image"` to route to an image-generation model.
temperatureNoSampling temperature.
tool_choiceNo
image_configNo
payload_fileNoRegular local JSON body file, at most 5 MB. Cannot be mixed with body flags or payload.
response_formatNo
max_completion_tokensNoCap on completion tokens. Replaces the deprecated `max_tokens` field.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed31 schema fields changedv3.0.0
    • addedInput schema / $defs / image_config
      Added value: +{
      +  "description": "Image-generation parameters (size, quality, aspect_ratio, background, output_format, partial_images). Optional. Image-generation models accept either `modalities: [\"image\"]` or `image_config` (or both); chat models ignore this field.",
      +  "type": "object"
      +}
    • addedInput schema / $defs / messages
      Added value: +{
      +  "description": "Conversation history. Roles `system`, `developer`, `user`, `assistant`, and `tool`. User messages accept multipart `content` with `text` and `image_url` parts. Assistant messages can carry `tool_calls`; answer each one with a `tool` message whose `tool_call_id` matches the call's `id`.",
      +  "items": {
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
    • addedInput schema / $defs / response_format
      Added value: +{
      +  "description": "Constrain the response. `{type: \"json_object\"}` returns a JSON object; `{type: \"json_schema\", json_schema: {name, strict, schema}}` returns JSON matching the supplied schema.\n",
      +  "type": "object"
      +}
    • addedInput schema / $defs / tool_choice
      Added value: +{
      +  "description": "`\"auto\"` lets the model choose and is the default when `tools` are sent. `\"none\"` disables tool calls, `\"required\"` forces a tool call, and `{\"type\": \"function\", \"function\": {\"name\": \"...\"}}` forces a specific tool.",
      +  "oneOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "object"
      +    }
      +  ]
      +}
    • changedInput schema / properties / confirm / description
      Previous value: -"Must be true for this exact requested account change, agent/flow execution, upload or deletion."New value: +"Set true only when the user asked for exactly this action."
    • addedInput schema / properties / image_config / $ref
      Added value: +"#/$defs/image_config"
    • removedInput schema / properties / image_config / description
      Removed value: -"Image-generation parameters (size, quality, aspect_ratio, background, output_format, partial_images). Optional. Image-generation models accept either `modalities: [\"image\"]` or `image_config` (or both); chat models ignore this field."
    • removedInput schema / properties / image_config / type
      Removed value: -"object"
    • addedInput schema / properties / messages / $ref
      Added value: +"#/$defs/messages"
    • removedInput schema / properties / messages / description
      Removed value: -"Conversation history. Roles `system`, `developer`, `user`, `assistant`, and `tool`. User messages accept multipart `content` with `text` and `image_url` parts. Assistant messages can carry `tool_calls`; answer each one with a `tool` message whose `tool_call_id` matches the call's `id`."
    • removedInput schema / properties / messages / items
      Removed value: -{
      -  "type": "object"
      -}
    • removedInput schema / properties / messages / type
      Removed value: -"array"
    • addedInput schema / properties / payload / properties / image_config / $ref
      Added value: +"#/$defs/image_config"
    • removedInput schema / properties / payload / properties / image_config / description
      Removed value: -"Image-generation parameters (size, quality, aspect_ratio, background, output_format, partial_images). Optional. Image-generation models accept either `modalities: [\"image\"]` or `image_config` (or both); chat models ignore this field."
    • removedInput schema / properties / payload / properties / image_config / type
      Removed value: -"object"
    • addedInput schema / properties / payload / properties / messages / $ref
      Added value: +"#/$defs/messages"
    • removedInput schema / properties / payload / properties / messages / description
      Removed value: -"Conversation history. Roles `system`, `developer`, `user`, `assistant`, and `tool`. User messages accept multipart `content` with `text` and `image_url` parts. Assistant messages can carry `tool_calls`; answer each one with a `tool` message whose `tool_call_id` matches the call's `id`."
    • removedInput schema / properties / payload / properties / messages / items
      Removed value: -{
      -  "type": "object"
      -}
    • removedInput schema / properties / payload / properties / messages / type
      Removed value: -"array"
    • addedInput schema / properties / payload / properties / response_format / $ref
      Added value: +"#/$defs/response_format"
    • removedInput schema / properties / payload / properties / response_format / description
      Removed value: -"Constrain the response. `{type: \"json_object\"}` returns a JSON object; `{type: \"json_schema\", json_schema: {name, strict, schema}}` returns JSON matching the supplied schema.\n"
    • removedInput schema / properties / payload / properties / response_format / type
      Removed value: -"object"
    • addedInput schema / properties / payload / properties / tool_choice / $ref
      Added value: +"#/$defs/tool_choice"
    • removedInput schema / properties / payload / properties / tool_choice / description
      Removed value: -"`\"auto\"` lets the model choose and is the default when `tools` are sent. `\"none\"` disables tool calls, `\"required\"` forces a tool call, and `{\"type\": \"function\", \"function\": {\"name\": \"...\"}}` forces a specific tool."
    • removedInput schema / properties / payload / properties / tool_choice / oneOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "object"
      -  }
      -]
    • addedInput schema / properties / response_format / $ref
      Added value: +"#/$defs/response_format"
    • removedInput schema / properties / response_format / description
      Removed value: -"Constrain the response. `{type: \"json_object\"}` returns a JSON object; `{type: \"json_schema\", json_schema: {name, strict, schema}}` returns JSON matching the supplied schema.\n"
    • removedInput schema / properties / response_format / type
      Removed value: -"object"
    • addedInput schema / properties / tool_choice / $ref
      Added value: +"#/$defs/tool_choice"
    • removedInput schema / properties / tool_choice / description
      Removed value: -"`\"auto\"` lets the model choose and is the default when `tools` are sent. `\"none\"` disables tool calls, `\"required\"` forces a tool call, and `{\"type\": \"function\", \"function\": {\"name\": \"...\"}}` forces a specific tool."
    • removedInput schema / properties / tool_choice / oneOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "object"
      -  }
      -]
  2. First observedv2.0.1

TDQS

B3.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations by disclosing billing semantics (per-token credit charge, flat 30-credit image-gen fee, 50% discount with own provider key), error shapes (400 invalid_request with param, provider-rejection prefixing), and a confirmation requirement for account-affecting operations. The main defect is the inaccurate streaming/SSE behavior, which is a schema contradiction rather than an annotation contradiction, so it does not trigger that flag.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It is a reference doc rather than a tool description: three headers, a code block, a full JSON example, and repeated image/streaming material. Streaming is discussed twice, once in the intro and again under its own heading, and the closing 'Explicit confirmation...' paragraph reads as grafted from another tool. Front-loaded purpose is present, but the length is not earned.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

A 15-parameter, nested, mutation-capable tool with 0 required params and no output schema warrants substantial detail, and the tool-call loop and error handling are covered. But several parameters are left undocumented and the description asserts a streaming capability the schema forbids, so an agent cannot fully trust it as a complete spec.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 73%, so the schema carries most parameter meaning; the description adds value for tool_choice values, image_url content parts (accepted types, 20 MB limit, no redirects), and the tool/tool_call_id pairing rule. It says nothing about temperature, max_completion_tokens, provider, payload_file, account, or confirm, so it does not fully compensate for the remaining gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening line names a specific verb+resource ('chat completions endpoint') and its distinguishing trait — multiplexed across Anthropic, OpenAI, Gemini, OpenRouter — which separates it from siblings like route_model or list_models. It stops short of a 5 because the purpose is muddied by a streaming claim (see below) that misrepresents what the tool actually does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives real usage context: when image-gen models dispatch (modalities includes 'image'), how to continue after finish_reason: tool_calls, and tool_choice options. But the primary 'when to use' guidance — 'Set stream: true for SSE, or omit it for a unary JSON response' — directly conflicts with the schema, which pins stream to const:false and refuses streaming, so the routing advice is actively misleading.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools