Documentation
APIs
Function calling

Function calling

A function calling occurs when you interact with the Chat API to communicate with a Language Learning Model (LLM). Within the tool array, you have the flexibility to define custom functions. This capability enables the model to dynamically generate and provide function signatures in JSON format, facilitating seamless integration with external tools and applications.

Available models

ModelRelease dateContext LengthDescription
solar-1-mini-chat2024-06-01 beta32768A compact LLM offering superior performance to GPT-3.5, with robust multilingual capabilities for both English and Korean, delivering high efficiency in a smaller package.
solar-1-mini-chat is alias for our latest solar-1-mini-chat model. (Currently solar-1-mini-chat-240530)

Request

POST https://api.upstage.ai/v1/solar/chat/completions

Request body

messages[].tool_calls[].type string Required
The type of tool. Should be function.

messages[].tool_calls[].function string Required
The function generated by model.

messages[].tool_calls[].function.name string Required
The name of the function.

messages[].tool_calls[].function.arguments string Required
The arguments of the json generated by model. arguments parameter must be valid, escaped json string.

Example

Request

curl --location 'https://api.upstage.ai/v1/solar/chat/completions' \
  --header 'Authorization: Bearer UPSTAGE_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
          "model": "solar-1-mini-chat",
          "messages": [
            {
              "role": "user",
              "content": "What is the weather like in San Francisco, Seoul, and Paris?"
            }
          ],
          "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", "unit"]
                }
              }
            }
          ]
        }'

Response sample

Success - HTTP Status 200 OK

{
  "id": "68ca5a6b-7cfa-402d-bba3-4fd7710640df",
  "object": "chat.completion",
  "created": 1710715081,
  "model": "solar-1-mini-chat-240530",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "e7e01748-b53b-4f98-90a7-f330f5cba2af",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"location\":\"San Francisco\",\"unit\":\"fahrenheit\"}"
            }
          },
          {
            "id": "948f5e4c-09fc-402f-b703-e4ace12b7d48",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"location\":\"Seoul\",\"unit\":\"celsius\"}"
            }
          },
          {
            "id": "d25d38e0-6a7d-428e-8953-0cd2f5b81969",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"location\":\"Paris\",\"unit\":\"celsius\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 567,
    "completion_tokens": 177,
    "total_tokens": 744
  },
  "system_fingerprint": null
}