---
title: Tool calling
description: Execute structured function calls and JSON schema tools across supported models.
---

<ApiEndpoint method="POST" path="/v1/chat/completions" auth="api_key" />

Zorveus passes OpenAI-compatible tool definitions and returned tool-call arguments through supported model routes. Your application executes the tool and sends the tool result in a later request.

<KeyInserter type="api" label="API Key Tester" placeholder="zrv_your_api_key" />

---

## Code example

<CodeGroup titles={["Python (OpenAI SDK)", "TypeScript (OpenAI SDK)"]}>

```python
import json
from openai import OpenAI

client = OpenAI(
    base_url="https://api.zorveus.com/v1",
    api_key="zrv_your_api_key",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_stock_price",
            "description": "Fetch real-time stock ticker price",
            "parameters": {
                "type": "object",
                "properties": {
                    "symbol": {"type": "string", "description": "Ticker symbol, e.g. AAPL"},
                },
                "required": ["symbol"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="openai/gpt-4.1-mini",
    messages=[{"role": "user", "content": "What is the stock price of NVDA?"}],
    tools=tools,
    tool_choice="auto",
)

tool_calls = response.choices[0].message.tool_calls
if tool_calls:
    for tool_call in tool_calls:
        print(f"Tool to invoke: {tool_call.function.name}")
        print(f"Arguments: {tool_call.function.arguments}")
```

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.zorveus.com/v1",
  apiKey: "zrv_your_api_key",
});

async function main() {
  const response = await client.chat.completions.create({
    model: "openai/gpt-4.1-mini",
    messages: [{ role: "user", content: "What is the stock price of NVDA?" }],
    tools: [
      {
        type: "function",
        function: {
          name: "get_stock_price",
          description: "Fetch real-time stock ticker price",
          parameters: {
            type: "object",
            properties: {
              symbol: { type: "string", description: "Ticker symbol, e.g. NVDA" },
            },
            required: ["symbol"],
          },
        },
      },
    ],
  });

  console.log(response.choices[0].message.tool_calls);
}

main();
```

</CodeGroup>

## Complete the tool loop

1. Send the tool schema with the conversation.
2. Validate the returned function name and JSON arguments.
3. Execute only an allowlisted function with validated inputs.
4. Append the assistant tool call and your `tool` result to the messages.
5. Send another completion request to obtain the final answer.

Do not execute a function name or argument solely because a model returned it. Apply the same authorization checks that you use for any other application input.

Tool support varies by model. Check `GET /v1/models`, then run a small tool-call test before enabling a model in production.
