IN ENGLISH · API DOCS

Function calling, structured output and vision

The gateway does not translate a request body: the fields tools and tool_choice, response_format (including json_schema) and image_url parts reach the model's vendor as you sent them, and the vendor's answer comes back as it is. So a model that has these capabilities at its own vendor has them here; which of them a given model accepts is up to its vendor. Server-side tools are a separate matter: only the ones whose cost can be metered are allowed.

Last updated:

[01]FUNCTION CALLING AND STRUCTURED OUTPUT

What passes through

Fields that pass through unchanged
CapabilityFieldsRoute
Function callingFields:tools (type: "function"), tool_choice, parallel_tool_callsRoute:/v1/chat/completions, /v1/responses
Structured outputFields:response_format (json_object, json_schema)Route:/v1/chat/completions
VisionFields:An image_url part in content (a URL or a data URL)Route:/v1/chat/completions
Audio inputFields:An input_audio part in contentRoute:/v1/chat/completions
Reasoning parametersFields:reasoning_effort, reasoningRoute:/v1/chat/completions, /v1/responses
Anthropic toolsFields:tools, tool_choice, thinking, cache_controlRoute:/anthropic/v1/messages
Gemini toolsFields:tools.functionDeclarations, generationConfig.responseSchemaRoute:/gemini/v1beta/models/{model}:generateContent
  • The only changes the gateway makes to a body are in this list. One of them matters here: for DeepSeek models, json_schema becomes json_object (state the schema in the prompt as well).
  • When a model does not accept a field, the vendor's own error reaches you with its status, and nothing is billed.
  • Images and files inside a request count toward the body size.
[02]FUNCTION CALLING AND STRUCTURED OUTPUT

Example: function calling

POST /v1/chat/completionscurl
curl https://1xai.ir/v1/chat/completions \
  -H "Authorization: Bearer 1xai-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5-mini",
    "messages": [{"role": "user", "content": "What is the weather in Tehran?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }],
    "tool_choice": "auto"
  }'

The answer has the function's name and arguments in choices[0].message.tool_calls. Run the function yourself and return its result in a message with the role tool and the same tool_call_id.

[03]FUNCTION CALLING AND STRUCTURED OUTPUT

Example: structured output

POST /v1/chat/completionscurl
curl https://1xai.ir/v1/chat/completions \
  -H "Authorization: Bearer 1xai-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5-mini",
    "messages": [{"role": "user", "content": "Give the title and year of one famous book."}],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "book",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {"title": {"type": "string"}, "year": {"type": "integer"}},
          "required": ["title", "year"],
          "additionalProperties": false
        }
      }
    }
  }'
[04]FUNCTION CALLING AND STRUCTURED OUTPUT

Example: vision

POST /v1/chat/completionscurl
curl https://1xai.ir/v1/chat/completions \
  -H "Authorization: Bearer 1xai-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-flash",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}
      ]
    }]
  }'

Send the image as a data URL (base64), so that you do not depend on a URL being reachable from the vendor's side. The whole request body may be up to 25 MiB.

[05]FUNCTION CALLING AND STRUCTURED OUTPUT

Hosted (server-side) tools

A hosted tool is one the vendor runs itself and charges for apart from tokens. Only the ones whose cost we can meter exactly are allowed; the rest are refused before anything is sent, and cost nothing.

Hosted tools by route
RouteAllowedRefused
/v1/chat/completionsAllowed:Function tools (function, custom); the web_search_options fieldRefused:Any other tool type
/v1/responsesAllowed:Function tools and web_searchRefused:code_interpreter, file_search, image_generation, computer_use, mcp
/anthropic/v1/messagesAllowed:Your own tools, and web_search, web_fetch, bash, text_editor, computer and memoryRefused:code_execution
/gemini/…:generateContentAllowed:functionDeclarations and Google Search groundingRefused:Google Maps grounding
  • Web search is billed per search at the model's search rate. Before the call the price of a few searches (up to 3 on OpenAI and Anthropic) is held, and after the answer the searches actually made are charged.
  • A model with no search rate answers 400 with code search_not_priced when a search tool is requested.
  • A refused tool answers 400 with code hosted_tool_unmetered (on Gemini, Google Maps grounding answers 402 with the same code).
  • The Anthropic tools bash, text_editor, computer and memory are executed by your own application; they cost tokens only.

1xAi is an independent gateway. It is not affiliated with, endorsed by, or a reseller for OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Z.ai, Alibaba Qwen, MiniMax or Tencent Hunyuan. Requests are relayed upstream rather than answered by models of our own, so each provider's own usage policies apply to what their models will and will not do, and their model availability is theirs to change. Current reachability is published on the status page.