쿠키를 사용합니다. 쿠키와 브라우저 저장소는 로그인 상태를 유지하고 환경설정을 기억합니다. 동의하시면 사이트 이용 방식도 측정합니다. 언제든지 할 수 있습니다. 자세한 내용은 쿠키 정책을 참고하세요.

도구 호출

엔드포인트

도구 호출

OpenAI tools 형식으로 모델이 내 함수를 호출하게 하는 방법입니다. tool_choice 옵션, 도구 호출 결과를 돌려주는 루프 구현, 스트리밍 시 주의점, 오류 처리 요령을 다룹니다. 요청 파라미터 표와 활용 팁도 있습니다.

플레이그라운드에서 사용해 보기

도구 호출(함수 호출)은 모델이 코드에 함수를 실행해 달라고 요청하고, 그 결과를 답변에 사용하게 해 줍니다. api14는 도구를 지원하는 모든 모델(OpenAI, Anthropic, Google, Mistral, Qwen, DeepSeek 등)에 OpenAI tools 형식을 사용합니다. 도구를 지원하는 모델을 찾으려면 모델 목록에서 지원 파라미터로 필터링하세요(supported_parameters에 tools가 포함됨).

요청 파라미터

파라미터타입설명
toolsarray[{ "type": "function", "function": { "name", "description", "parameters" } }]. parameters는 JSON Schema입니다.
tool_choicestring | object"auto"(기본값), "none", "required", 또는 { "type": "function", "function": { "name": "get_weather" } }.
parallel_tool_callsboolean한 턴에 여러 도구 호출을 허용합니다(지원되는 경우 기본값 true).
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.chat.completions.create({
  "model": "openai/gpt-5-mini",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Istanbul?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ]
});
console.log(result.choices[0].message.tool_calls);

루프

  1. messages와 tools를 보냅니다.
  2. 응답에 finish_reason: "tool_calls"가 있으면 message.tool_calls의 각 항목을 실행합니다.
  3. 어시스턴트 메시지를 추가하고, 호출마다 { "role": "tool", "tool_call_id", "content" } 메시지를 하나씩 추가한 뒤 요청을 다시 보냅니다.
  4. 모델이 일반 content로 답할 때까지 반복합니다.

도구 호출이 포함된 응답:

{
  "id": "gen-1760000000-tool1",
  "model": "anthropic/claude-sonnet-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "tool_calls",
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_01",
            "type": "function",
            "function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" }
          }
        ]
      }
    }
  ],
  "usage": { "prompt_tokens": 182, "completion_tokens": 21, "total_tokens": 203, "cost": 0.000861 }
}

후속 요청에는 도구 결과가 포함됩니다.

{
  "model": "anthropic/claude-sonnet-4.5",
  "tools": [ ... same tools ... ],
  "messages": [
    { "role": "user", "content": "What's the weather in Istanbul?" },
    { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_01", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" } } ] },
    { "role": "tool", "tool_call_id": "call_01", "content": "{\"temp_c\": 21, \"sky\": \"clear\"}" }
  ]
}

루프의 모든 요청에 tools를 계속 보내세요. 요청에 tools 정의가 없으면 많은 제공자가 tool 메시지를 거부합니다.

팁

  • arguments는 JSON 문자열입니다. 모델이 잘못된 JSON을 만들 수 있으므로 파싱한 뒤 검증하세요.
  • 스트리밍 시 도구 호출은 index를 키로 하는 delta.tool_calls 조각으로 도착합니다. 파싱하기 전에 arguments 문자열을 이어 붙이세요.
  • 도구를 지원하는 제공자로만 라우팅하려면 provider: { "require_parameters": true }를 설정하세요. 제공자 라우팅을 참고하세요.
  • 루프의 각 반복은 별도로 과금되는 요청입니다.

오류

도구를 지원하지 않는 모델은 업스트림 400 또는 404("No endpoints found that support tool use")를 반환할 수 있습니다. 그 밖의 오류는 Chat completions와 같습니다. 오류를 참고하세요.