Chat Completions with Function Calling

POST https://api.openai.com/v1/chat/completions

Request Body

{"model"=>"{{model}}", "messages"=>[{"role"=>"user", "content"=>"What is the weather in San Francisco?"}], "tools"=>[{"type"=>"function", "function"=>{"name"=>"get_current_weather", "description"=>"Get the current weather", "parameters"=>{"type"=>"object", "properties"=>{"location"=>{"type"=>"string", "description"=>"The city and state, e.g. San Francisco, CA"}, "format"=>{"type"=>"string", "enum"=>["celsius", "fahrenheit"], "description"=>"The temperature unit to use. Infer this from the users location."}}, "required"=>["location"]}}}], "tool_choice"=>"required"}

HEADERS

KeyDatatypeRequiredDescription
Content-Typestring
Authorizationstring

RESPONSES

status: OK

{"id":"chatcmpl-9b03jdpTlePrfNUed4Oih8obtOuEC","object":"chat.completion","created":1718605391,"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"message":{"role":"assistant","content":null,"tool_calls":[{"id":"call_H5zLfaW6i3LWQRqUAxuSJ8qS","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco\"}"}}]},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":94,"completion_tokens":14,"total_tokens":108},"system_fingerprint":null}