We’ll start by defining a server-side route for our future voice client to target.

Can I launch a bot without a server-side route?

Yes. RTVI provides properties on the voice client that allow you to pass parameters and headers required to query the Daily Bots REST API.

We strongly suggest using a server-side route to keep your API keys (and other sensitive information) secure.

You can define the entirety of your bot config in the route if preferable, but we’ll set it up to receive a config option from the client.

Setup your local .env file

Create a new file in the root of your project called .env.local.

You’ll need to define one environment variable for your Daily Bots API key, which you can get here.

Copy this key into a DAILY_BOTS_KEY variable in your .env.local file:

.env.local
DAILY_BOTS_KEY=your-daily-api-key

Create the route

Make a new directory in your app folder called api, and within that a folder called connect:

mkdir app/api/connect

Create a new file in this directory called route.ts:

What’s happening here?

This route receives a POST request with a JSON body containing services and config properties. It then sends a request to the Daily Bots API to start a new bot with the provided configuration.

The bot_profile property is a string that identifies the bot you want to launch. You can read more about bot profiles here.

We also set a max_duration property to 600 seconds (10 minutes) to limit the bot’s runtime. You must set a max_duration to prevent bots running indefinitely.

We’re authenticating with the Daily Bots API by passing our API key in the Authorization header.

Finally, we forward any errors from the API back to the client with the appropriate status code and message (in JSON format.)

Test everything is setup correctly

Let’s call this route from the terminal to check everything is setup correctly.

We’ll define a services and config object to send in the request (which we’ll cover in the next section).

Run the follow cURL command in your terminal:

Request
curl --location --request POST 'http://localhost:3000/api/connect' \
--header 'Content-Type: application/json' \
--data '{
    "services": {
        "llm": "together",
        "tts": "cartesia"
    },
    "config": []
}'

All being well, you should see a response that looks like so:

Response
{
  "room_url": "https://daily_room_url",
  "token": "abc-authentication-token"
}