Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions fern/tools/code-tool.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ Code tools are ideal when you need to:

## Creating a Code Tool

### Step 1: Navigate to the Tools Section
Create code tools using the [Vapi API](/api-reference/tools/create). Each code tool requires:

1. Open your [Vapi Dashboard](https://dashboard.vapi.ai)
2. Click **Tools** in the left sidebar
3. Click **Create Tool** and select **Code**
- **Tool Name**: A descriptive identifier (e.g., `get_customer_data`)
- **Description**: Explain what your tool does - this helps the AI understand when to use it
- **TypeScript Code**: Write the code that will execute when the tool is called
- **Parameters**: Define the input parameters your code expects
- **Environment Variables**: Store sensitive values like API keys securely

### Step 2: Configure Your Code Tool

The dashboard provides a visual interface to configure your code tool:

1. **Tool Name**: A descriptive identifier (e.g., `get_customer_data`)
2. **Description**: Explain what your tool does - this helps the AI understand when to use it
3. **TypeScript Code**: Write the code that will execute when the tool is called
4. **Parameters**: Define the input parameters your code expects
5. **Environment Variables**: Store sensitive values like API keys securely

### Step 3: Write Your Code
### Writing Your Code

Your code has access to two objects:
- **`args`**: Contains the parameters passed by the assistant
Expand Down Expand Up @@ -181,16 +173,7 @@ return {

## Using Code Tools in Assistants

Once created, add your code tool to any assistant:

### In the Dashboard

1. Go to **Assistants** → Select your assistant
2. Navigate to the **Tools** tab
3. Click **Add Tool** and select your code tool
4. Save your assistant configuration

### Via API
Once created, add your code tool to any assistant by updating the assistant configuration via API:

```bash
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
Expand All @@ -205,7 +188,7 @@ curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \

## Creating Code Tools via API

You can also create code tools programmatically:
Create code tools programmatically with the following request:

```bash
curl --location 'https://api.vapi.ai/tool' \
Expand Down
Loading