YourGPT Helpdesk

Find answers to your questions

Setting Up Code Functions with Tool Params in YourGPT

Create dynamic Functions with Tool Params for API calls, variable mapping, and real-world use cases

YourGPT Functions enable powerful, modular logic to be executed within chat conversations. One of the most versatile types is the Code Function, which allows you to connect external APIs to natural language prompts — making your assistant dynamic, data-driven, and action-capable.

When users make requests, YourGPT automatically extracts key parameters from their input using AI. These are referred to as Tool Params, and they’re mapped into API endpoints to generate context-aware responses.

Whether you want to recommend products, create posts, update todos, delete photos and get users, Code Functions let you build reusable workflows that respond to real-world inputs instantly.


📘 Overview: Creating a Code Function with Tool Params

  1. Go to Function in Dashboard.

  2. Click on Code Function.

  3. Set the Function Name and Description.

  4. Define Tool Params by creating Parameter Variables.

  5. Open the codeblock to access your variable with Tool Params.

  6. Access Variable name with Tool Params - TOOL_PARAMS.Variable_Name.

  7. Mandatory to return the result from codeblock.

  8. Click on Add Function to Save to function.

Let’s look at several real-world use cases demonstrating how Tool Params can be applied to dynamic Functions.


Use Case 1: Create Posts

Description

When a user is asked to create a post with its title and body.

User Input: "Create a post titled "My Journey" with the body "This is the story of my journey""

API Configuration

  • Endpoint: https://jsonplaceholder.typicode.com/posts

  • Method: POST

  • Function Name: createPosts

URL Structure

https://jsonplaceholder.typicode.com/posts

Tool Params Mapping

Variable

Value

Description

title

My Journey

Title of the post

body

This is the story of my journey

Description of the post

Code Block

//Fetch post title & post body from Tool Params
const post_title = TOOL_PARAMS.title;
const post_body = TOOL_PARAMS.body;

const url = 'https://jsonplaceholder.typicode.com/posts';
  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
       body: JSON.stringify({ title: post_title , body: post_body })
    });

    if (!response.ok) {
      throw new Error('Network response was not ok: ' + response.statusText);
    }
    const result = await response.json();
    return result;
  } catch (error) {
    console.error('Fetch error:', error);
    return null;
  }

Use Case 2: Update Todos

Description

When a user is asked to update a todo with todoId, its title, and status.

User Input: "Update todo: todoId is 101, title will be Meeting, and status will be true"

API Configuration

  • Endpoint: https://jsonplaceholder.typicode.com/todos

  • Method: POST

  • Function Name: updateTodo

URL Structure

https://jsonplaceholder.typicode.com/todos/${todoId}

Tool Params Mapping

Variable

Value

Description

title

My Journey

Title of the post

todoId

101

Unique id of a todo

status

true

Showing todo completed or not

Code Block

//Fetch todoId, title and status from Tool Params
const todoId = TOOL_PARAMS.todoId;
const title = TOOL_PARAMS.title;
const status = TOOL_PARAMS.status

const url = `https://jsonplaceholder.typicode.com/todos/${todoId}`;
  try {
    const response = await fetch(url, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify( { title: title, completed: status } )
    });
    if (!response.ok) {
      throw new Error('Network response was not ok: ' + response.statusText);
    }
    const updatedTodo = await response.json();
    return updatedTodo;
  } catch (error) {
    console.error('Fetch error:', error);
    return null;
  }

Use Case 3: Delete photo

Description

When a user is asked to delete the photo with photoId.

User Input: "Delete the photo with photoId 54."

API Configuration

  • Endpoint: https://jsonplaceholder.typicode.com/photos

  • Method: DELETE

  • Function Name: deletePhoto

URL Structure

https://jsonplaceholder.typicode.com/photos/${photoId}

Tool Params Mapping

Variable

Value

Description

photoId

54

Unique id of photo

Code Block

//Fetch photoId from Tool Params
const photoId = TOOL_PARAMS.photoId;

const url = `https://jsonplaceholder.typicode.com/photos/${photoId}`;
  try {
    const response = await fetch(url, {
      method: 'DELETE'
    });
    if (response.ok) {
      return 'Photo deleted successfully!';
    } else {
      throw new Error('Delete failed: ' + response.statusText);
    }
  } catch (error) {
    console.error('Fetch error:', error);
    return null;
  }

Use Case 4: User Fetching

Description

When a user is asked to fetch a user with a user ID.

User Input: "Get the user with user ID 1"

API Configuration

  • Endpoint: https://jsonplaceholder.typicode.com/users

  • Method: GET

  • Function Name: getUserWithUserID

URL Structure

https://jsonplaceholder.typicode.com/users/${user_id}

Tool Params Mapping

Variable

Value

Description

user_id

1

The unique id of user

Code Block

//Fetch user id from Tool Params
const user_id = TOOL_PARAMS.user_id;

const url = `https://jsonplaceholder.typicode.com/users/${user_id}`;
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error('Network response was not ok: ' + response.statusText);
    }
    const user = await response.json();
    return user;
  } catch (error) {
    console.error('Fetch error:', error);
    return null;
  }


Response Results

Code Functions example

This documentation provides a comprehensive guide for implementing Code Functions with Tool Params across various business use cases. Each example follows industry best practices for API design and includes practical implementation details.

Was this article helpful?
©2025
Powered by YourGPT