Skip to content

$(ai)

Syntax
$(ai <prompt>)
Arguments
Required

The $(ai) variable allows you to integrate AI into your StreamElements chat commands, generating dynamic responses based on user input.

!command add !askai $(ai $(1:))
Example chat
ViewerName:!askai what snack should I grab for the next boss fight?
partner badgemoderator badgeStreamElements:Something one-handed, ViewerName — grab some pretzels so you can snack and dodge at the same time. Good luck with the boss!

To use the AI variable, include it in your commands with the following syntax:

$(ai <prompt>)

Replace <prompt> with the text you want the AI to respond to. Everything you pass to the variable is joined together with spaces and sent as a single prompt.

  1. Contextual response:

    !command add !aifact ${ai You are a knowledgeable historian. Tell me an interesting fact about ${1:}}
  2. Roleplaying:

    !command add !aipirate ${ai You are a friendly pirate. Greet ${user} and tell them about your latest adventure.}
  3. Combining with other variables:

    !command add !aiwelcome ${ai Create a warm welcome message for ${1} who was last seen $(user.lastseen ${1}) ago. Their last message was $(user.lastmessage ${1}).}

In these examples, ${1} inserts only the first word the viewer types after the command, while ${1:} inserts everything from the first word onward — see Argument tokens for details.

The $(ai) variable accepts a single parameter:

  • prompt: The input text for the AI to generate a response. This parameter is required and must be less than 512 characters.
  • $(chatgpt): Identical to $(ai) in every way.

The AI variable comes with some default context that it’s always aware of:

  1. Channel Emotes: The AI knows about the custom emotes available in your channel. It can reference and use these emotes in its responses when appropriate.

  2. Sender’s Name: The AI is aware of the name of the user who triggered the command. This allows for personalized responses without explicitly including the user’s name in the query.

  3. Current Date: The AI knows the current date, allowing it to provide timely responses or reference current events when relevant.

This default context enables the AI to generate more relevant and personalized responses without requiring you to explicitly include this information in every query.

To prevent abuse, the $(ai) variable is rate limited per channel:

Channel Requests per minute
Regular 10
Affiliate 20
Partner 30

When the limit is exceeded, the bot replies rate limit exceeded.

Bot reply Cause
rate limit exceeded The channel’s per-minute request limit was hit
input should be less than 512 characters The prompt is 512 characters or longer
Something went wrong during prompt execution The AI service request failed
Failed to execute prompt The AI response could not be read

Q: Can I customize the AI’s personality?

A: Yes, you can provide context or instructions in your query to shape the AI’s response. For example:

$(ai You are a friendly pirate. Greet ${user} and share a sea shanty.)

Q: Can I use the AI variable in combination with other variables?

A: Yes, you can combine the $(ai) variable with other StreamElements variables to create more dynamic and personalized responses. See example 3 in the Examples section.

Q: Are there any content restrictions for AI-generated responses?

A: Yes, the AI is programmed to avoid generating inappropriate, offensive, or harmful content. However, it’s always a good idea to monitor and moderate AI-generated responses during your stream.

Q: How long can my prompt be?

A: The prompt limit is 512 characters — anything longer makes the bot reply input should be less than 512 characters. For optimal performance, keep your prompts concise. If you need a more extensive response, consider breaking it down into multiple separate commands.

Q: How can I report issues or unexpected behavior with the AI variable?

A: If you encounter any problems or unexpected responses, you can report them to StreamElements support or post in the official StreamElements Discord for assistance.