> ## 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.

<Tabs>
  <Tab title="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();
    ```
  </Tab>

  <Tab title="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)
    ```
  </Tab>

  <Tab title="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"
    }'
    ```
  </Tab>
</Tabs>

### [API Reference](/docs/provider-endpoints/chat)

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.

## Managing Functions and Tools in Prompts

Create prompt templates with function/tool definitions in the AI Gateway's Prompt Library. Set the `tool_choice` parameter, and the AI Gateway validates your tool definition on the fly, eliminating syntax errors.

## Supported Providers and Models

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

If you discover a function-calling capable LLM that isn't working with the AI Gateway, please let us know at [support@portkey.ai](mailto:support@portkey.ai).

## Cookbook

[**See the detailed cookbook on function calling.**](/docs/guides/getting-started/function-calling)


## Related topics

- [Fireworks](/docs/aigw/integrations/llms/fireworks.md)
- [Google Gemini](/docs/aigw/integrations/llms/gemini.md)
- [Google Vertex AI](/docs/aigw/integrations/llms/vertex-ai.md)
- [Azure AI Foundry](/docs/aigw/integrations/llms/azure-foundry.md)
- [Upstage AI](/docs/aigw/integrations/llms/upstage.md)
