POST
/
chat
/
completions
curl --location --request POST 'https://api.llama-api.com/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data-raw '{
    "messages": [
        {"role": "user", "content": "What is the weather like in Boston?"},
    ],
    "functions": [
        {
            "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",
                    },
                    "days": {
                        "type": "number",
                        "description": "for how many days ahead you wants the forecast",
                    },
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                },
            },
            "required": ["location", "days"],
        }
    ],
    "stream": False,
    "function_call": "get_current_weather",
}'
{
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "function_call": {
          "name": "get_current_weather",
          "arguments": {
            "location": "Boston",
            "days": 5,
            "unit": "celsius"
          }
        }
      },
      "finish_reason": "function_call"
    }
  ]
}

Request Body

messages
object

This parameter represents a collection of messages that form the ongoing conversation.

functions
object

This parameter contains a list of functions for which the model can generate JSON inputs.

stream
boolean

When this option is enabled, the model will send partial message updates, similar to ChatGPT. Tokens will be transmitted as data-only server-sent events as they become available, and the streaming will conclude with a data: [DONE] marker.

function_call
string

This parameter governs the model’s response to function calls. Choosing “none” indicates that the model will not invoke any functions and will respond directly to the end-user.

Response

choices
array