Triton AI Docs
Developer API

Tool calling

Let a model request functions that your application controls.

A tool definition tells the model which function it can request. Your application checks the request, runs the function, and returns the result.

The model does not authorize an action

Check every argument and the user's permission before you run a function. Require user approval before an action changes data or sends information.

Complete a tool loop

This example uses local sample data. Replace get_course_status with code that reads an approved source.

tool_call.py
import json
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TRITONAI_API_KEY"],
    base_url="https://tritonai-api.ucsd.edu/v1",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_course_status",
            "description": "Get the enrollment status for one course.",
            "parameters": {
                "type": "object",
                "properties": {
                    "course": {"type": "string"},
                },
                "required": ["course"],
                "additionalProperties": False,
            },
            "strict": True,
        },
    }
]

messages = [
    {"role": "user", "content": "Is CSE 100 open?"},
]

first = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=messages,
    tools=tools,
)

assistant_message = first.choices[0].message
messages.append(assistant_message)

for tool_call in assistant_message.tool_calls or []:
    if tool_call.function.name != "get_course_status":
        raise ValueError("The model requested an unknown tool.")

    arguments = json.loads(tool_call.function.arguments)
    course = arguments["course"]

    # Check the user and arguments before you call a real service.
    tool_result = {"course": course, "status": "open"}

    messages.append(
        {
            "role": "tool",
            "tool_call_id": tool_call.id,
            "content": json.dumps(tool_result),
        }
    )

final = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=messages,
    tools=tools,
)

print(final.choices[0].message.content)

The first response contains an assistant message with tool_calls. Run the approved function, then send its result in a tool message.

Second request template
curl https://tritonai-api.ucsd.edu/v1/chat/completions \
  --header "Authorization: Bearer $TRITONAI_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "gpt-5.6-luna",
    "messages": [
      {"role": "user", "content": "Is CSE 100 open?"},
      {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "<TOOL_CALL_ID>",
            "type": "function",
            "function": {
              "name": "get_course_status",
              "arguments": "{\"course\":\"CSE 100\"}"
            }
          }
        ]
      },
      {
        "role": "tool",
        "tool_call_id": "<TOOL_CALL_ID>",
        "content": "{\"course\":\"CSE 100\",\"status\":\"open\"}"
      }
    ]
  }'

Process parallel calls

Some models can return more than one tool call. Process every call, then send one tool message for each tool_call_id.

Only send parallel_tool_calls when the model catalog reports support. Your application must still limit concurrency and side effects.

Request structured JSON

Use response_format when the model lists this parameter. A schema helps the model return data that your application can parse.

structured_output.py
completion = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[
        {"role": "user", "content": "Classify this request: Reset my password."},
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "request_classification",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "category": {"type": "string"},
                    "needs_human_review": {"type": "boolean"},
                },
                "required": ["category", "needs_human_review"],
                "additionalProperties": False,
            },
        },
    },
)

Your application must parse and check the returned JSON. A schema does not make the content correct or safe.

OpenAI documents the upstream function-calling flow. Triton AI support depends on the selected model route.

On this page