SilkDock
API

Tool Use

Let the model call your functions.

Pass a tools array and set "tool_choice": "auto". When the model decides to call a tool, finish_reason will be "tool_calls".


Tool definition

FieldTypeDescription
typestringAlways "function".
function.namestringFunction name (no spaces).
function.descriptionstringWhat the function does.
function.parametersobjectJSON Schema describing the parameters.

Examples

curl -X POST https://silkdock.ai/v1/responses \-H "Authorization: Bearer $SILKDOCK_API_KEY" \-H "Content-Type: application/json" \-d '{  "model": "gpt-4o",  "action": "chat",  "tool_choice": "auto",  "messages": [{"role": "user", "content": "What is the weather in Tokyo?"}],  "tools": [{    "type": "function",    "function": {      "name": "get_weather",      "description": "Get current weather for a city",      "parameters": {        "type": "object",        "properties": {"city": {"type": "string"}},        "required": ["city"]      }    }  }]}'
curl -X POST https://silkdock.ai/v1/responses ^-H "Authorization: Bearer %SILKDOCK_API_KEY%" ^-H "Content-Type: application/json" ^-d "{"model":"gpt-4o","action":"chat","tool_choice":"auto","messages":[{"role":"user","content":"What is the weather in Tokyo?"}],"tools":[{"type":"function","function":{"name":"get_weather","description":"Get current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]}"
http POST https://silkdock.ai/v1/responses \Authorization:"Bearer $SILKDOCK_API_KEY" \Content-Type:application/json \model=gpt-4o \action=chat \tool_choice=auto \messages:='[{"role":"user","content":"What is the weather in Tokyo?"}]' \tools:='[{"type":"function","function":{"name":"get_weather","description":"Get current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]'
wget --quiet --output-document=- \--method=POST \--header="Authorization: Bearer $SILKDOCK_API_KEY" \--header="Content-Type: application/json" \--body-data='{  "model": "gpt-4o",  "action": "chat",  "tool_choice": "auto",  "messages": [{"role": "user", "content": "What is the weather in Tokyo?"}],  "tools": [{    "type": "function",    "function": {      "name": "get_weather",      "description": "Get current weather for a city",      "parameters": {        "type": "object",        "properties": {"city": {"type": "string"}},        "required": ["city"]      }    }  }]}' \https://silkdock.ai/v1/responses
$body = @{model       = "gpt-4o"action      = "chat"tool_choice = "auto"messages    = @(@{ role = "user"; content = "What is the weather in Tokyo?" })tools       = @(@{  type     = "function"  function = @{    name        = "get_weather"    description = "Get current weather for a city"    parameters  = @{      type       = "object"      properties = @{ city = @{ type = "string" } }      required   = @("city")    }  }})} | ConvertTo-Json -Depth 10Invoke-RestMethod -Method Post `-Uri "https://silkdock.ai/v1/responses" `-Headers @{ Authorization = "Bearer $env:SILKDOCK_API_KEY" } `-ContentType "application/json" `-Body $body
const res = await fetch("https://silkdock.ai/v1/responses", {method: "POST",headers: {  "Authorization": `Bearer ${process.env.SILKDOCK_API_KEY}`,  "Content-Type": "application/json",},body: JSON.stringify({  model: "gpt-4o",  action: "chat",  tool_choice: "auto",  messages: [{ role: "user", content: "What is the weather in Tokyo?" }],  tools: [{    type: "function",    function: {      name: "get_weather",      description: "Get current weather for a city",      parameters: {        type: "object",        properties: { city: { type: "string" } },        required: ["city"],      },    },  }],}),});const data = await res.json();const toolCall = data.choices[0].message.tool_calls?.[0];if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);
import axios from "axios";const { data } = await axios.post("https://silkdock.ai/v1/responses",{  model: "gpt-4o",  action: "chat",  tool_choice: "auto",  messages: [{ role: "user", content: "What is the weather in Tokyo?" }],  tools: [{    type: "function",    function: {      name: "get_weather",      description: "Get current weather for a city",      parameters: {        type: "object",        properties: { city: { type: "string" } },        required: ["city"],      },    },  }],},{  headers: {    Authorization: `Bearer ${process.env.SILKDOCK_API_KEY}`,    "Content-Type": "application/json",  },});const toolCall = data.choices[0].message.tool_calls?.[0];if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);
$.ajax({url: "https://silkdock.ai/v1/responses",method: "POST",contentType: "application/json",headers: {  Authorization: `Bearer ${SILKDOCK_API_KEY}`,},data: JSON.stringify({  model: "gpt-4o",  action: "chat",  tool_choice: "auto",  messages: [{ role: "user", content: "What is the weather in Tokyo?" }],  tools: [{    type: "function",    function: {      name: "get_weather",      description: "Get current weather for a city",      parameters: {        type: "object",        properties: { city: { type: "string" } },        required: ["city"],      },    },  }],}),success(data) {  const toolCall = data.choices[0].message.tool_calls?.[0];  if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);},});
const xhr = new XMLHttpRequest();xhr.open("POST", "https://silkdock.ai/v1/responses");xhr.setRequestHeader("Authorization", `Bearer ${SILKDOCK_API_KEY}`);xhr.setRequestHeader("Content-Type", "application/json");xhr.onload = () => {const data = JSON.parse(xhr.responseText);const toolCall = data.choices[0].message.tool_calls?.[0];if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);};xhr.send(JSON.stringify({model: "gpt-4o",action: "chat",tool_choice: "auto",messages: [{ role: "user", content: "What is the weather in Tokyo?" }],tools: [{  type: "function",  function: {    name: "get_weather",    description: "Get current weather for a city",    parameters: {      type: "object",      properties: { city: { type: "string" } },      required: ["city"],    },  },}],}));
const request = require("request");request.post({  url: "https://silkdock.ai/v1/responses",  headers: {    Authorization: `Bearer ${process.env.SILKDOCK_API_KEY}`,    "Content-Type": "application/json",  },  json: {    model: "gpt-4o",    action: "chat",    tool_choice: "auto",    messages: [{ role: "user", content: "What is the weather in Tokyo?" }],    tools: [{      type: "function",      function: {        name: "get_weather",        description: "Get current weather for a city",        parameters: {          type: "object",          properties: { city: { type: "string" } },          required: ["city"],        },      },    }],  },},(err, res, body) => {  const toolCall = body.choices[0].message.tool_calls?.[0];  if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);});
const unirest = require("unirest");unirest.post("https://silkdock.ai/v1/responses").headers({  Authorization: `Bearer ${process.env.SILKDOCK_API_KEY}`,  "Content-Type": "application/json",}).send({  model: "gpt-4o",  action: "chat",  tool_choice: "auto",  messages: [{ role: "user", content: "What is the weather in Tokyo?" }],  tools: [{    type: "function",    function: {      name: "get_weather",      description: "Get current weather for a city",      parameters: {        type: "object",        properties: { city: { type: "string" } },        required: ["city"],      },    },  }],}).then((res) => {  const toolCall = res.body.choices[0].message.tool_calls?.[0];  if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);});
const res = await fetch("https://silkdock.ai/v1/responses", {method: "POST",headers: {  "Authorization": `Bearer ${process.env.SILKDOCK_API_KEY}`,  "Content-Type": "application/json",},body: JSON.stringify({  model: "gpt-4o",  action: "chat",  messages: [{ role: "user", content: "What is the weather in Beijing?" }],  tools: [{    type: "function",    function: {      name: "get_weather",      description: "Get current weather for a city",      parameters: {        type: "object",        properties: { city: { type: "string", description: "City name" } },        required: ["city"],      },    },  }],  tool_choice: "auto",}),});const data = await res.json();const toolCall = data.choices[0].message.tool_calls?.[0];if (toolCall) console.log(toolCall.function.name, toolCall.function.arguments);
import requests, osres = requests.post(  "https://silkdock.ai/v1/responses",  headers={"Authorization": f"Bearer {os.getenv('SILKDOCK_API_KEY')}"},  json={      "model": "gpt-4o",      "action": "chat",      "messages": [{"role": "user", "content": "What is the weather in Beijing?"}],      "tools": [{          "type": "function",          "function": {              "name": "get_weather",              "description": "Get current weather for a city",              "parameters": {                  "type": "object",                  "properties": {"city": {"type": "string", "description": "City name"}},                  "required": ["city"],              },          },      }],      "tool_choice": "auto",  },)tool_call = res.json()["choices"][0]["message"].get("tool_calls", [])[0]print(tool_call["function"]["name"], tool_call["function"]["arguments"])
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <curl/curl.h>static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) {  fwrite(ptr, size, nmemb, (FILE *)stream);  return size * nmemb;}int main(void) {  const char *api_key = getenv("SILKDOCK_API_KEY");  char auth_header[256];  snprintf(auth_header, sizeof(auth_header), "Authorization: Bearer %s", api_key);  const char *body =      "{"      ""model":"gpt-4o","      ""action":"chat","      ""tool_choice":"auto","      ""messages":[{"role":"user","content":"What is the weather in Tokyo?"}],"      ""tools":[{"type":"function","function":{"          ""name":"get_weather","          ""description":"Get current weather for a city","          ""parameters":{"type":"object","              ""properties":{"city":{"type":"string"}},"              ""required":["city"]}}}]"      "}";  CURL *curl = curl_easy_init();  if (!curl) return 1;  struct curl_slist *headers = NULL;  headers = curl_slist_append(headers, auth_header);  headers = curl_slist_append(headers, "Content-Type: application/json");  curl_easy_setopt(curl, CURLOPT_URL, "https://silkdock.ai/v1/responses");  curl_easy_setopt(curl, CURLOPT_POST, 1L);  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);  curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);  curl_easy_perform(curl);  curl_slist_free_all(headers);  curl_easy_cleanup(curl);  return 0;}
#import <Foundation/Foundation.h>int main(int argc, const char *argv[]) {  @autoreleasepool {      NSString *apiKey = [NSProcessInfo processInfo].environment[@"SILKDOCK_API_KEY"];      NSDictionary *payload = @{          @"model": @"gpt-4o",          @"action": @"chat",          @"tool_choice": @"auto",          @"messages": @[@{@"role": @"user", @"content": @"What is the weather in Tokyo?"}],          @"tools": @[@{              @"type": @"function",              @"function": @{                  @"name": @"get_weather",                  @"description": @"Get current weather for a city",                  @"parameters": @{                      @"type": @"object",                      @"properties": @{@"city": @{@"type": @"string"}},                      @"required": @[@"city"]                  }              }          }]      };      NSData *body = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];      NSMutableURLRequest *req = [NSMutableURLRequest          requestWithURL:[NSURL URLWithString:@"https://silkdock.ai/v1/responses"]];      req.HTTPMethod = @"POST";      [req setValue:[NSString stringWithFormat:@"Bearer %@", apiKey]          forHTTPHeaderField:@"Authorization"];      [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];      req.HTTPBody = body;      dispatch_semaphore_t sema = dispatch_semaphore_create(0);      [[[NSURLSession sharedSession] dataTaskWithRequest:req          completionHandler:^(NSData *data, NSURLResponse *resp, NSError *err) {              if (data) NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);              dispatch_semaphore_signal(sema);          }] resume];      dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);  }  return 0;}
import java.net.http.*;import java.net.URI;var body = """  {"model":"gpt-4o","action":"chat",   "messages":[{"role":"user","content":"What is the weather in Beijing?"}],   "tools":[{"type":"function","function":{"name":"get_weather",     "description":"Get current weather for a city",     "parameters":{"type":"object","properties":{"city":{"type":"string"}},     "required":["city"]}}}],   "tool_choice":"auto"}""";var req = HttpRequest.newBuilder()  .uri(URI.create("https://silkdock.ai/v1/responses"))  .header("Authorization", "Bearer " + System.getenv("SILKDOCK_API_KEY"))  .header("Content-Type", "application/json")  .POST(HttpRequest.BodyPublishers.ofString(body))  .build();System.out.println(HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString()).body());
import okhttp3.*;var client = new OkHttpClient();var body = RequestBody.create(  "{"model":"gpt-4o","action":"chat","tool_choice":"auto"," +  ""messages":[{"role":"user","content":"What is the weather in Tokyo?"}]," +  ""tools":[{"type":"function","function":{"name":"get_weather"," +  ""description":"Get current weather for a city"," +  ""parameters":{"type":"object","properties":{"city":{"type":"string"}}," +  ""required":["city"]}}}]}",  MediaType.get("application/json"));var req = new Request.Builder()  .url("https://silkdock.ai/v1/responses")  .addHeader("Authorization", "Bearer " + System.getenv("SILKDOCK_API_KEY"))  .post(body)  .build();try (var res = client.newCall(req).execute()) {  System.out.println(res.body().string());}
import kong.unirest.Unirest;import org.json.*;var response = Unirest.post("https://silkdock.ai/v1/responses")  .header("Authorization", "Bearer " + System.getenv("SILKDOCK_API_KEY"))  .header("Content-Type", "application/json")  .body(new JSONObject()      .put("model", "gpt-4o")      .put("action", "chat")      .put("tool_choice", "auto")      .put("messages", new JSONArray()          .put(new JSONObject().put("role", "user").put("content", "What is the weather in Tokyo?")))      .put("tools", new JSONArray()          .put(new JSONObject()              .put("type", "function")              .put("function", new JSONObject()                  .put("name", "get_weather")                  .put("description", "Get current weather for a city")                  .put("parameters", new JSONObject()                      .put("type", "object")                      .put("properties", new JSONObject()                          .put("city", new JSONObject().put("type", "string")))                      .put("required", new JSONArray().put("city"))))))      .toString())  .asString();System.out.println(response.getBody());
package mainimport (  "bytes"  "encoding/json"  "fmt"  "io"  "net/http"  "os")func main() {  body, _ := json.Marshal(map[string]any{      "model": "gpt-4o", "action": "chat",      "messages": []map[string]string{{"role": "user", "content": "What is the weather in Beijing?"}},      "tools": []map[string]any{{          "type": "function",          "function": map[string]any{              "name": "get_weather", "description": "Get current weather for a city",              "parameters": map[string]any{                  "type": "object",                  "properties": map[string]any{"city": map[string]string{"type": "string"}},                  "required": []string{"city"},              },          },      }},      "tool_choice": "auto",  })  req, _ := http.NewRequest("POST", "https://silkdock.ai/v1/responses", bytes.NewReader(body))  req.Header.Set("Authorization", "Bearer "+os.Getenv("SILKDOCK_API_KEY"))  req.Header.Set("Content-Type", "application/json")  resp, _ := http.DefaultClient.Do(req)  defer resp.Body.Close()  data, _ := io.ReadAll(resp.Body)  fmt.Println(string(data))}
<?php$ch = curl_init("https://silkdock.ai/v1/responses");curl_setopt_array($ch, [  CURLOPT_POST           => true,  CURLOPT_RETURNTRANSFER => true,  CURLOPT_HTTPHEADER     => [      "Authorization: Bearer " . getenv("SILKDOCK_API_KEY"),      "Content-Type: application/json",  ],  CURLOPT_POSTFIELDS => json_encode([      "model" => "gpt-4o", "action" => "chat",      "messages" => [["role" => "user", "content" => "What is the weather in Beijing?"]],      "tools" => [[          "type" => "function",          "function" => [              "name" => "get_weather",              "description" => "Get current weather for a city",              "parameters" => [                  "type" => "object",                  "properties" => ["city" => ["type" => "string"]],                  "required" => ["city"],              ],          ],      ]],      "tool_choice" => "auto",  ]),]);echo curl_exec($ch);
<?phprequire_once "HTTP/Request2.php";$request = new HTTP_Request2("https://silkdock.ai/v1/responses", HTTP_Request2::METHOD_POST);$request->setHeader([  "Authorization" => "Bearer " . getenv("SILKDOCK_API_KEY"),  "Content-Type"  => "application/json",]);$request->setBody(json_encode([  "model" => "gpt-4o", "action" => "chat",  "tool_choice" => "auto",  "messages" => [["role" => "user", "content" => "What is the weather in Tokyo?"]],  "tools" => [[      "type" => "function",      "function" => [          "name" => "get_weather",          "description" => "Get current weather for a city",          "parameters" => [              "type" => "object",              "properties" => ["city" => ["type" => "string"]],              "required" => ["city"],          ],      ],  ]],]));$response = $request->send();echo $response->getBody();
<?phprequire_once "vendor/autoload.php";use GuzzleHttpClient;$client = new Client();$response = $client->post("https://silkdock.ai/v1/responses", [  "headers" => [      "Authorization" => "Bearer " . getenv("SILKDOCK_API_KEY"),      "Content-Type"  => "application/json",  ],  "json" => [      "model" => "gpt-4o", "action" => "chat",      "tool_choice" => "auto",      "messages" => [["role" => "user", "content" => "What is the weather in Tokyo?"]],      "tools" => [[          "type" => "function",          "function" => [              "name" => "get_weather",              "description" => "Get current weather for a city",              "parameters" => [                  "type" => "object",                  "properties" => ["city" => ["type" => "string"]],                  "required" => ["city"],              ],          ],      ]],  ],]);echo $response->getBody();
<?php$client = new httpClient;$request = new httpClientRequest;$request->setRequestUrl("https://silkdock.ai/v1/responses");$request->setRequestMethod("POST");$request->setHeaders([  "Authorization" => "Bearer " . getenv("SILKDOCK_API_KEY"),  "Content-Type"  => "application/json",]);$body = new httpMessageBody;$body->append(json_encode([  "model" => "gpt-4o", "action" => "chat",  "tool_choice" => "auto",  "messages" => [["role" => "user", "content" => "What is the weather in Tokyo?"]],  "tools" => [[      "type" => "function",      "function" => [          "name" => "get_weather",          "description" => "Get current weather for a city",          "parameters" => [              "type" => "object",              "properties" => ["city" => ["type" => "string"]],              "required" => ["city"],          ],      ],  ]],]));$request->setBody($body);$client->enqueue($request)->send();$response = $client->getResponse();echo $response->getBody();
import Foundationvar req = URLRequest(url: URL(string: "https://silkdock.ai/v1/responses")!)req.httpMethod = "POST"req.setValue("Bearer \(ProcessInfo.processInfo.environment["SILKDOCK_API_KEY"]!)",           forHTTPHeaderField: "Authorization")req.setValue("application/json", forHTTPHeaderField: "Content-Type")req.httpBody = try! JSONSerialization.data(withJSONObject: [  "model": "gpt-4o", "action": "chat",  "messages": [["role": "user", "content": "What is the weather in Beijing?"]],  "tools": [[      "type": "function",      "function": [          "name": "get_weather", "description": "Get current weather for a city",          "parameters": ["type": "object",              "properties": ["city": ["type": "string"]],              "required": ["city"]],      ],  ]],  "tool_choice": "auto",])let (data, _) = try! await URLSession.shared.data(for: req)print(String(data: data, encoding: .utf8)!)
using System.Net.Http;using System.Net.Http.Json;var client = new HttpClient();client.DefaultRequestHeaders.Add("Authorization",  $"Bearer {Environment.GetEnvironmentVariable("SILKDOCK_API_KEY")}");var res = await client.PostAsJsonAsync("https://silkdock.ai/v1/responses", new {  model = "gpt-4o", action = "chat",  messages = new[] { new { role = "user", content = "What is the weather in Beijing?" } },  tools = new[] { new {      type = "function",      function = new {          name = "get_weather",          description = "Get current weather for a city",          parameters = new {              type = "object",              properties = new { city = new { type = "string" } },              required = new[] { "city" },          },      },  }},  tool_choice = "auto",});Console.WriteLine(await res.Content.ReadAsStringAsync());
require "net/http"require "json"uri = URI("https://silkdock.ai/v1/responses")req = Net::HTTP::Post.new(uri)req["Authorization"] = "Bearer #{ENV['SILKDOCK_API_KEY']}"req["Content-Type"]  = "application/json"req.body = {model: "gpt-4o", action: "chat",messages: [{ role: "user", content: "What is the weather in Beijing?" }],tools: [{  type: "function",  function: {    name: "get_weather", description: "Get current weather for a city",    parameters: {      type: "object",      properties: { city: { type: "string" } },      required: ["city"],    },  },}],tool_choice: "auto",}.to_jsonres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }puts res.body
import java.net.http.*import java.net.URIval body = """{"model":"gpt-4o","action":"chat","messages":[{"role":"user","content":"What is the weather in Beijing?"}],"tools":[{"type":"function","function":{"name":"get_weather",  "description":"Get current weather for a city",  "parameters":{"type":"object","properties":{"city":{"type":"string"}},  "required":["city"]}}}],"tool_choice":"auto"}"""val req = HttpRequest.newBuilder()  .uri(URI.create("https://silkdock.ai/v1/responses"))  .header("Authorization", "Bearer ${System.getenv("SILKDOCK_API_KEY")}")  .header("Content-Type", "application/json")  .POST(HttpRequest.BodyPublishers.ofString(body))  .build()println(HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString()).body())
use reqwest::blocking::Client;use serde_json::json;fn main() -> Result<(), Box<dyn std::error::Error>> {  let res = Client::new()      .post("https://silkdock.ai/v1/responses")      .header("Authorization", format!("Bearer {}", std::env::var("SILKDOCK_API_KEY")?))      .json(&json!({          "model": "gpt-4o", "action": "chat",          "messages": [{"role": "user", "content": "What is the weather in Beijing?"}],          "tools": [{"type": "function", "function": {              "name": "get_weather",              "description": "Get current weather for a city",              "parameters": {"type": "object",                  "properties": {"city": {"type": "string"}},                  "required": ["city"]}          }}],          "tool_choice": "auto"      }))      .send()?;  println!("{}", res.text()?);  Ok(())}
POST /v1/responses HTTP/1.1Host: silkdock.aiAuthorization: Bearer <YOUR_API_KEY>Content-Type: application/json{"model": "gpt-4o","action": "chat","messages": [{"role": "user", "content": "What is the weather in Beijing?"}],"tools": [{  "type": "function",  "function": {    "name": "get_weather",    "description": "Get current weather for a city",    "parameters": {      "type": "object",      "properties": {"city": {"type": "string"}},      "required": ["city"]    }  }}],"tool_choice": "auto"}
import 'dart:convert';import 'package:http/http.dart' as http;void main() async {final res = await http.post(  Uri.parse('https://silkdock.ai/v1/responses'),  headers: {    'Authorization': 'Bearer ${const String.fromEnvironment("SILKDOCK_API_KEY")}',    'Content-Type': 'application/json',  },  body: jsonEncode({    'model': 'gpt-4o', 'action': 'chat',    'messages': [{'role': 'user', 'content': 'What is the weather in Beijing?'}],    'tools': [{      'type': 'function',      'function': {        'name': 'get_weather',        'description': 'Get current weather for a city',        'parameters': {          'type': 'object',          'properties': {'city': {'type': 'string'}},          'required': ['city'],        },      },    }],    'tool_choice': 'auto',  }),);print(res.body);}
library(httr2)req <- request("https://silkdock.ai/v1/responses") |>req_headers(  Authorization = paste("Bearer", Sys.getenv("SILKDOCK_API_KEY")),  "Content-Type" = "application/json") |>req_body_json(list(  model    = "gpt-4o",  action   = "chat",  messages = list(list(role = "user", content = "What is the weather in Beijing?")),  tools = list(list(    type = "function",    `function` = list(      name = "get_weather",      description = "Get current weather for a city",      parameters = list(        type = "object",        properties = list(city = list(type = "string")),        required = list("city")      )    )  )),  tool_choice = "auto"))resp <- req_perform(req)cat(resp_body_string(resp))
(* requires cohttp-lwt-unix *)open Cohttp_lwt_unixopen Cohttpopen Lwtlet () =let body = {|{  "model":"gpt-4o","action":"chat","tool_choice":"auto",  "messages":[{"role":"user","content":"What is the weather in Tokyo?"}],  "tools":[{"type":"function","function":{"name":"get_weather",    "description":"Get current weather for a city",    "parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]}|} inlet headers = Header.of_list [  "Authorization", "Bearer " ^ Sys.getenv "SILKDOCK_API_KEY";  "Content-Type", "application/json";] inLwt_main.run (  Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body)    (Uri.of_string "https://silkdock.ai/v1/responses")  >>= fun (_, body) -> Cohttp_lwt.Body.to_string body  >>= fun s -> print_string s; return_unit)

Response

When the model calls a tool, finish_reason is "tool_calls":

{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": null,
      "tool_calls": [{
        "id": "call_abc123",
        "type": "function",
        "function": {
          "name": "get_weather",
          "arguments": "{\"city\": \"Beijing\"}"
        }
      }]
    },
    "finish_reason": "tool_calls"
  }]
}

Last updated on

On this page