Tutorial: Getting Started with Platform APIs

Welcome to the tutorial for using our platform's APIs to build LLM/AI agents and applications! This guide will help you understand how to interact with our platform to perform tasks such as generating responses using AI agents. We'll cover key API endpoints for creating sessions, handling single-turn and multi-turn conversations, and fetching session data.


1. Introduction to the Platform APIs

Our platform provides several APIs to help you interact with AI agents and manage sessions effectively. Here are the key endpoints we'll cover:

Let's dive into each of these endpoints in detail.


2. Using the /run API

The /run API is designed for single-run chat completions. This is useful when you want the AI to perform a specific task with each call. You can customize the response format using json_mode and json_format.

Example Use Case: Asking the AI to tell a joke.

Simplified Function Call:

async function singleRunChat(agentId, inputData, apiKey, jsonMode = true, jsonFormat = '{"content": "<The content goes here>"}') {
  const response = await fetch('<https://www.trytruffle.ai/api/v0/run>', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': apiKey
    },
    body: JSON.stringify({
      agent_id: agentId,
      input_data: inputData,
      json_mode: jsonMode,
      json_format: jsonFormat,
      store_session: true
    })
  });

  const result = await response.json();
  console.log(result);
  return result;
}

// Usage
singleRunChat('<your-agent-id>', 'Tell me a very sad joke', '<your-api-key>');

Response Example with json_mode: true:

{
	"data": "{\"content\":\"Why don't scientists trust atoms? Because they make up everything!\"}"
}

Response Example with json_mode: false:

{
  "data": "Why don't scientists trust atoms? Because they make up everything!"
}