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

# Function Calling

> Prisma AIRS AI Gateway supports function calling across major foundational models. Define functions in your API call, and the model can output the function name with parameters.

## Functions Usage

The AI Gateway supports the OpenAI signature to define functions. Pass the `tools` parameter to models that support function/tool calling.

**OpenAI NodeJS**

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

const openai = new OpenAI({
  apiKey: "PORTKEY_API_KEY",
  baseURL: "https://aigw.portkey.ai/v1"
});

async function run() {
  const response = await openai.chat.completions.create({
    model: "MODEL_NAME",
    messages: [{ role: "user", content: "What's the weather like in Boston today?" }],
    tools: [{
        type: "function",
        function: {
          name: "get_current_weather",
          description: "Get the current weather in a given location",
          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",
  });

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

run();
```

**OpenAI Python**

```py theme={"system"}
from openai import OpenAI

openai = OpenAI(
    api_key="PORTKEY_API_KEY",
    base_url="https://aigw.portkey.ai/v1"
)

completion = openai.chat.completions.create(
  model="MODEL_NAME",
  messages=[{"role": "user", "content": "What's the weather like in Boston today?"}],
  tools=[{
    "type": "function",
    "function": {
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "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"
)

print(completion.choices[0].message.tool_calls)
```

**cURL**

```sh theme={"system"}
curl "https://aigw.portkey.ai/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $PORTKEY_API_KEY" \
  -d '{
  "model": "MODEL_NAME",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather like in Boston?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "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"
}'
```

### [API Reference](https://docs.portkey.ai/docs/provider-endpoints/chat.md)

On completion, the request logs in Strata Cloud Manager where tools and functions are visible. The AI Gateway automatically formats the JSON blocks in the input and output for easier debugging.

![](https://mintcdn.com/portkey-docs/VWP2Y8zxPP5N4jE6/images/product/ai-gateway/ai-15.webp?fit=max\&auto=format\&n=VWP2Y8zxPP5N4jE6\&q=85\&s=0b2b72327452d12a019999d086922d0b)

## Supported Providers and Models

The AI Gateway provides native function calling support across all major AI providers.

## Cookbook

[**See the detailed cookbook on function calling.**](https://docs.portkey.ai/docs/guides/getting-started/function-calling.md)


## Related topics

- [Fireworks](https://docs.portkey.ai/docs/aigw/integrations/llms/fireworks.md)
- [Google Gemini](https://docs.portkey.ai/docs/aigw/integrations/llms/gemini.md)
- [Google Vertex AI](https://docs.portkey.ai/docs/aigw/integrations/llms/vertex-ai.md)
- [Azure AI Foundry](https://docs.portkey.ai/docs/aigw/integrations/llms/azure-foundry.md)
- [Lambda Labs](https://docs.portkey.ai/docs/aigw/integrations/llms/lambda.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.