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

# OpenAIツール呼び出し例

> OpenAI スタイルの統合のためのツール呼び出しの例。

## 推奨されるエンドポイント

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

## 最低限のお願い

```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の例

```bash theme={null}
curl https://maas.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 の例

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

client = OpenAI(
    base_url="https://maas.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 の例

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

const client = new OpenAI({
  baseURL: "https://maas.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);
```

## ベストプラクティス

* 関数スキーマを明示的かつ厳密に保つ
* ツール呼び出しが 1 つだけであるとは想定しないでください
* 再生およびデバッグのために生のツール呼び出しとツール結果を保持します。
