#Working with the api I want to create an agent and add their name and prompt

1 messages · Page 1 of 1 (latest)

arctic orioleBOT
#
AI-generated Answer for sack5539

To create an agent and set their name and prompt using the API, you can follow this example:

const createAgentBody = {
  "conversation_config": {
    "agent": {
      "prompt": {
        "prompt": "Your desired prompt here",
        "llm": "gpt-4o", // Choose the appropriate language model
        "temperature": 0.5,
        "max_tokens": -1
      },
      "first_message": "Hi there! How can I assist you today?",
      "language": "en"
    },
    "asr": {
      "quality": "high",
      "provider": "elevenlabs",
      "user_input_audio_format": "ulaw_8000"
    },
    "turn": {
      "turn_timeout": 7
    },
    "tts": {
      "model_id": "eleven_turbo_v2",
      "voice_id": "tnSpp4vdxKPjI9w0GnoV",
      "agent_output_audio_format": "ulaw_8000",
      "optimize_streaming_latency": 3,
      "stability": 0.5,
      "similarity_boost": 0.8
    },
    "conversation": {
      "max_duration_seconds": 300,
      "client_events": ["audio", "interruption"]
    }
  },
  "name": "Your Agent Name"
};

const response = await fetch('https://api.elevenlabs.io/v1/convai/agents/create', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Xi-Api-Key': process.env.ELEVENLABS_API_KEY || ''
  },
  body: JSON.stringify(createAgentBody)
});

if (!response.ok) {
  const errorText = await response.text();
  throw new Error(`ElevenLabs API error: ${response.status} - ${errorText}`);
}

const agent = await response.json();
console.log('Created agent:', agent);

Make sure to replace "Your desired prompt here" and "Your Agent Name" with the actual prompt and name you want for your agent. Also, ensure that you have set your API key correctly in the headers.

opaque maple
#

Give me it in curl

arctic orioleBOT
#
AI-generated Answer for sack5539

To create an agent and add their name and prompt using cURL, you can use the following command:

curl -X POST "https://api.elevenlabs.io/v1/convai/agents/create" \
     -H "Content-Type: application/json" \
     -H "xi-api-key: YOUR_API_KEY" \
     -d '{
           "conversation_config": {
             "agent": {
               "name": "Your Agent Name",
               "prompt": {
                 "prompt": "Your agent prompt here"
               }
             }
           }
         }'

Replace YOUR_API_KEY with your actual API key, Your Agent Name with the desired name for your agent, and Your agent prompt here with the prompt you want to set for the agent.

opaque maple
#

Why did I get this error: There was an issue setting up your call.

Raw response for the API
Status code 422
{"detail":[{"loc":["body","conversation_config"],"msg":"field required","type":"value_error.missing"},{"loc":["body","platform_settings"],"msg":"field required","type":"value_error.missing"},{"loc":["body","name"],"msg":"field required","type":"value_error.missing"}]}

arctic orioleBOT
#
AI-generated Answer for sack5539

The error code 422 indicates that some required fields are missing or not provided in the correct format in your API request. Specifically, the error message shows that the fields conversation_config, platform_settings, and name are required but missing from the request body.

To resolve this, ensure that your API request includes these fields with the appropriate values. Here's an example of how you might structure your curl request to include these fields:

curl -X POST "https://api.elevenlabs.io/your-endpoint" \
-H "Content-Type: application/json" \
-H "xi-api-key: YOUR_API_KEY" \
-d '{
  "conversation_config": {
    // your conversation configuration here
  },
  "platform_settings": {
    // your platform settings here
  },
  "name": "Your Agent Name"
}'

Make sure to replace YOUR_API_KEY, your-endpoint, and the placeholder comments with your actual API key, endpoint, and the necessary configuration details.

opaque maple
#

What is your endpoint?

arctic orioleBOT
#
AI-generated Answer for sack5539

To create an agent using the API, you can use the following cURL command. Make sure to replace YOUR_API_KEY with your actual API key and provide the necessary details for conversation_config, platform_settings, and name in the JSON body:

curl --request POST \
  --url https://api.elevenlabs.io/v1/convai/agents/create \
  --header 'Content-Type: application/json' \
  --header 'xi-api-key: YOUR_API_KEY' \
  --data '{
    "conversation_config": {
      "agent": {
        "prompt": {
          "prompt": "Your prompt here"
        }
      }
    },
    "platform_settings": {
      // Your platform settings here
    },
    "name": "Your agent name"
  }'

The error you received indicates that the conversation_config, platform_settings, and name fields are required in the request body. Make sure these fields are included and properly formatted in your API request.

opaque maple
#

Fix this json: {
"{ "conversation_config": { // your conversation configuration here }, "platform_settings": { // your platform settings here }, "name": "Your Agent Name" }": ""
}

arctic orioleBOT
#
AI-generated Answer for sack5539

It looks like the JSON structure is incorrect. Here's a corrected version:

{
    "conversation_config": {
        // your conversation configuration here
    },
    "platform_settings": {
        // your platform settings here
    },
    "name": "Your Agent Name"
}

Make sure to replace the comments with the actual configuration details for conversation_config and platform_settings.

opaque maple
#

Do it again but add prompt too

arctic orioleBOT
#
AI-generated Answer for sack5539

Here's the corrected JSON with the prompt included:

{
    "conversation_config": {
        "agent": {
            "prompt": {
                "prompt": "Your prompt here"
            }
        }
    },
    "platform_settings": {
        // your platform settings here
    },
    "name": "Your Agent Name"
}

Make sure to replace "Your prompt here" and "Your Agent Name" with your desired values, and fill in the platform settings as needed.

opaque maple
#

Give me an example of how that json should be filled out

arctic orioleBOT
#
AI-generated Answer for sack5539

Here's an example of how the JSON should be structured, including the prompt:

{
    "conversation_config": {
        "agent": {
            "prompt": {
                "prompt": "You are a helpful AI assistant. You are cheerful and friendly."
            },
            "first_message": "Hi! How can I help you today?",
            "language": "en"
        },
        "tts": {
            "voice_id": "pNInz6obpgDQGcFmaJgB"
        }
    },
    "platform_settings": {
        // your platform settings here
    },
    "name": "Your Agent Name"
}

Make sure to replace the placeholder comments with your actual configuration details.

opaque maple
#

What is platform settings supposed to be set as?

arctic orioleBOT
#
AI-generated Answer for sack5539

The specific details for "platform_settings" are not provided in the content I have. You might need to refer to the API documentation or any relevant resources provided by ElevenLabs for detailed information on how to configure "platform_settings" for your agent. If you have access to the documentation or any examples, those would be the best resources to consult.

opaque maple
#

Give me a fully fledged way you would set up the json for this api call?

arctic orioleBOT
#
AI-generated Answer for sack5539

To create an agent using the API, you need to provide a properly structured JSON payload. Here's an example of how you might set up the JSON for this API call, including the conversation configuration, platform settings, name, and prompt:

{
    "conversation_config": {
        "agent": {
            "prompt": {
                "prompt": "You are a helpful assistant."
            },
            "first_message": "Hello! How can I assist you today?"
        },
        "asr": {
            "quality": "high",
            "provider": "elevenlabs",
            "user_input_audio_format": "pcm_16000"
        },
        "turn": {
            "turn_timeout": 7,
            "mode": "turn"
        },
        "tts": {
            "model_id": "eleven_turbo_v2",
            "voice_id": "cjVigY5qzO86Huf0OWal",
            "agent_output_audio_format": "pcm_16000",
            "optimize_streaming_latency": 3,
            "stability": 0.5,
            "similarity_boost": 0.8
        },
        "conversation": {
            "max_duration_seconds": 600
        }
    },
    "platform_settings": {
        "auth": {
            "enable_auth": false
        },
        "widget": {
            "variant": "full",
            "avatar": {
                "type": "orb",
                "color_1": "#2792dc",
                "color_2": "#9ce6e6"
            },
            "bg_color": "#ffffff",
            "text_color": "#000000",
            "btn_color": "#000000",
            "btn_text_color": "#ffffff",
            "border_color": "#e1e1e1",
            "focus_color": "#000000"
        }
    },
    "name": "Your Agent Name"
}

This JSON includes a basic setup for the agent's conversation configuration, platform settings, and name. Adjust the values as needed to fit your specific requirements.

opaque maple
#

I just used everything you gave me and it gave me this error: There was an issue setting up your call.

Raw response for the API
Status code 404
{"detail":"Not Found"}

arctic orioleBOT
#
AI-generated Answer for sack5539

A 404 error indicates that the endpoint you are trying to reach is not found. This could be due to an incorrect URL or endpoint path. Please double-check the URL you are using for the API call to ensure it is correct. If you continue to experience issues, please provide more details about the endpoint you are trying to access.

opaque maple
#

Can you get audio recordings from calls to an eleven labs agent?