# Tool Calling

**Tool calls** (sometimes also called **function calls**) allow a language model to **suggest the use of external tools**. The model doesn't execute them directly, instead, it outputs a structured request indicating which tool to call and with what parameters. It's then up to the application or user to execute the tool and return the result back to the model, which incorporates it into a final, coherent response.&#x20;

We provide a **standardized tool calling interface** across supported models and providers, making it easier to integrate tool use consistently across different backends.

For a more advanced example of tool use, see [these OpenAI docs](https://platform.openai.com/docs/guides/function-calling?api-mode=chat).

{% tabs %}
{% tab title="Python" %}

```python
from openai import OpenAI
from pydantic import BaseModel

client = OpenAI(
  base_url="https://api.cortecs.ai/v1",
  api_key="<API_KEY>",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather in a given city",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "City and state, e.g. San Francisco, CA"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

completion = client.chat.completions.create(
    model="<MODEL_NAME>",
    messages=[
        {"role": "user", "content": "What’s the weather like in Paris?"}
    ],
    tools=tools,
    tool_choice="auto"
)

tool_call = completion.choices[0].message.tool_calls[0]
print("Tool name:", tool_call.function.name)
print("Arguments:", tool_call.function.arguments)
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.cortecs.ai/v1",
  apiKey: "<API_KEY>",
});

const tools = [
  {
    type: "function",
    function: {
      name: "get_weather",
      description: "Get the current weather in a given city",
      parameters: {
        type: "object",
        properties: {
          location: {
            type: "string",
            description: "City and state, e.g. San Francisco, CA",
          },
        },
        required: ["location"],
      },
    },
  },
];

const completion = await client.chat.completions.create({
  model: "<MODEL_NAME>",
  messages: [
    { role: "user", content: "What’s the weather like in Paris?" }
  ],
  tools: tools,
  tool_choice: "auto",
});

const toolCall = completion.choices[0].message.tool_calls[0];
console.log("Tool name:", toolCall.function.name);
console.log("Arguments:", toolCall.function.arguments);
```

{% endtab %}

{% tab title="Curl" %}

```bash
curl https://api.cortecs.ai/v1/chat/completions \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<MODEL_NAME>",
    "messages": [
      {
        "role": "user",
        "content": "What’s the weather like in Paris?"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the current weather in a given city",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "City and state, e.g. San Francisco, CA"
              }
            },
            "required": ["location"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cortecs.ai/usage/tool-calling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
