Saltar al contenido principal

Documentation Index

Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt

Use this file to discover all available pages before exploring further.

La Responses API Beta admite capacidades completas de llamada a herramientas (Tool Calling), permitiendo al modelo:
  • Llamada a funciones (Function Calling)
  • Ejecutar múltiples herramientas en paralelo
  • Gestionar flujos de trabajo complejos de múltiples pasos

Definición básica de una herramienta

Cabecera de la solicitud

curl -X POST https://aihubmix.com/v1/responses \
  -H "Authorization: Bearer YOUR_AIHUBMIX_API_KEY" \
  -H "Content-Type: application/json" \

Cuerpo de la solicitud

{
  "model": "claude-sonnet-4-6",
  "input": [
    {
      "type": "message",
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "What is the weather in San Francisco?"
        }
      ]
    }
  ],
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "Get the current weather at a location",
      "strict": null,
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  ],
  "tool_choice": "auto",
  "max_output_tokens": 5000
}

Estrategia de invocación de herramientas

El parámetro tool_choice controla cuándo y cómo invoca el modelo las herramientas.
ParámetroDescripción
autoEl modelo decide automáticamente si invocar herramientas
noneImpide que el modelo invoque cualquier herramienta

Definición de múltiples herramientas

En tareas complejas, se pueden definir múltiples herramientas, permitiendo al modelo elegir la apropiada según las necesidades del usuario.
import requests

# Weather tool
weather_tool = {
    "type": "function",
    "name": "get_weather",
    "description": "Get current weather information for a city",
    "parameters": {
        "type": "object",
        "properties": {
            "city": {
                "type": "string",
                "description": "The name of the city"
            }
        },
        "required": ["city"]
    }
}

# Calculator tool
calculator_tool = {
    "type": "function",
    "name": "calculate",
    "description": "Perform mathematical calculations",
    "parameters": {
        "type": "object",
        "properties": {
            "expression": {
                "type": "string",
                "description": "The mathematical expression to evaluate"
            }
        },
        "required": ["expression"]
    }
}

response = requests.post(
    "https://aihubmix.com/v1/responses",
    headers={
        "Authorization": "Bearer AIHUBMIX_API_KEY",
        "Content-Type": "application/json",
    },
    json={
        "model": "glm-5",
        "input": [
            {
                "type": "message",
                "role": "user",
                "content": [
                    {
                        "type": "input_text",
                        "text": "What is 25 * 4?"
                    }
                ]
            }
        ],
        "tools": [weather_tool, calculator_tool],
        "tool_choice": "auto",
        "max_output_tokens": 5000
    }
)

print(response.json())

Respuesta con invocación de herramientas

{
  "id": "resp_09b8eb7c272559fc0069affbaab5cc8194a5005746b80f3b57",
  "object": "response",
  "created_at": 1773140906,
  "completed_at": 1773140908,
  "status": "completed",
  "background": false,
  "error": null,
  "model": "gpt-54",
  "service_tier": "default",
  "temperature": 1.0,
  "top_p": 1.0,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.0,
  "max_output_tokens": 5000,
  "max_tool_calls": null,
  "parallel_tool_calls": true,
  "tool_choice": "auto",
  "truncation": "disabled",
  "store": true,
  "previous_response_id": null,
  "prompt_cache_key": null,
  "prompt_cache_retention": null,
  "instructions": null,
  "safety_identifier": null,
  "user": null,
  "metadata": {},

  "reasoning": {
    "effort": "none",
    "summary": null
  },

  "content_filters": [
    {
      "blocked": false,
      "source_type": "completion",
      "content_filter_raw": [],
      "content_filter_results": {},
      "content_filter_offsets": {
        "start_offset": 0,
        "end_offset": 1289,
        "check_offset": 0
      }
    }
  ],

  "text": {
    "format": {
      "type": "text"
    },
    "verbosity": "medium"
  },

  "output": [
    {
      "id": "fc_09b8eb7c272559fc0069affbabb0288194b63aa879435c7cd0",
      "type": "function_call",
      "status": "completed",
      "name": "calculate",
      "call_id": "call_PFtWscQ3pAyfSaotwujhT0sn",
      "arguments": {
        "expression": "25*4"
      }
    }
  ],

  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "Get current weather information for a city",
      "strict": true,
      "parameters": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string",
            "description": "The name of the city"
          }
        },
        "required": ["city"],
        "additionalProperties": false
      }
    },
    {
      "type": "function",
      "name": "calculate",
      "description": "Perform mathematical calculations",
      "strict": true,
      "parameters": {
        "type": "object",
        "properties": {
          "expression": {
            "type": "string",
            "description": "The mathematical expression to evaluate"
          }
        },
        "required": ["expression"],
        "additionalProperties": false
      }
    }
  ],

  "usage": {
    "input_tokens": 86,
    "output_tokens": 25,
    "total_tokens": 111,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens_details": {
      "reasoning_tokens": 0
    }
  }
}

Recomendaciones de uso

  1. Descripciones claras: Proporciona descripciones detalladas de las funciones y explicaciones de los parámetros.
  2. Formato correcto: Los parámetros deben usar JSON válido.
  3. Manejo de errores: Gestiona las situaciones en las que las herramientas puedan no ser invocables.
  4. Ejecución paralela: Diseña las herramientas para que se ejecuten de forma independiente siempre que sea posible.
  5. Flujo conversacional: Incluye las respuestas de las herramientas en las solicitudes siguientes para aportar contexto.

Última actualización: 2026-06-01