> ## Documentation Index
> Fetch the complete documentation index at: https://docs-vip.apigo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI tool calling example

> Tool calling example for OpenAI-style integrations.

## Recommended endpoints

* [OpenAI /v1/responses](/en/api-reference/endpoints/openai/responses)
* [OpenAI /v1/chat/completions](/en/api-reference/endpoints/openai/chat-completions)

## Minimal request

```json theme={null}
{
  "model": "gpt-4.1",
  "input": "Get today's Shanghai weather.",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "Fetch weather",
      "parameters": {
        "type": "object",
        "properties": {
          "city": { "type": "string" }
        },
        "required": ["city"]
      }
    }
  ]
}
```

## cURL example

```bash theme={null}
curl https://api-vip.apigo.ai/v1/responses \
  -H "Authorization: Bearer $YOUR API KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "input": "Get today's Shanghai weather.",
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Fetch weather",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    ]
  }'
```

## Python example

```python theme={null}
from openai import OpenAI

client = OpenAI(
    base_url="https://api-vip.apigo.ai/v1",
    api_key="<YOUR API KEY>",
)

response = client.responses.create(
    model="gpt-4.1",
    input="Get today's Shanghai weather.",
    tools=[
        {
            "type": "function",
            "name": "get_weather",
            "description": "Fetch weather",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"},
                },
                "required": ["city"],
            },
        }
    ],
)

print(response.output)
```

## Node.js example

```js theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api-vip.apigo.ai/v1",
  apiKey: process.env.YOUR API KEY,
});

const response = await client.responses.create({
  model: "gpt-4.1",
  input: "Get today's Shanghai weather.",
  tools: [
    {
      type: "function",
      name: "get_weather",
      description: "Fetch weather",
      parameters: {
        type: "object",
        properties: {
          city: { type: "string" }
        },
        required: ["city"]
      }
    }
  ]
});

console.log(response.output);
```

## Best practices

* Keep function schemas explicit and strict
* Do not assume there will be only one tool call
* Persist the raw tool calls and tool results for replay and debugging
