Skip to content
Docs
Start free

Answer visitors with AI

The AI answer task answers visitors' questions with your own AI service and key, following instructions you write. Visitors type a question on your page, and the answer comes back in a few seconds as plain text.

On this page

What it doesLink to this section

  • It answers /api/ai-reply on your site. A page sends it a question of up to 500 characters.
  • It sends your instructions and the question to your AI service, and gives the page the answer, cut to 2,000 characters.
  • Your instructions say what the AI may talk about. Visitors can't change them.
  • If the service takes longer than 25 seconds, the task stops waiting and the page gets No answer right now. Please try again soon.
Warning:

Anyone can ask a question, and your AI service bills you for each answer. Set a spending limit at your AI service before you go live.

Add the taskLink to this section

In Server tasks (top menu), choose Add a ready-made task, pick AI answer and choose Add task. The setup card lists the three keys below, each with Add key.

Keys to addLink to this section

Add AI service address first: the form for AI service key then fills in which service the key is for.

AI service address (AI_API_URL), a settingLink to this section

  1. Find the address

    In your AI service's API guide, open the page about chat or messages. Copy the full address it sends chat requests to, starting with https://.

  2. Add it

    Choose Add key next to AI service address, paste it and save.

AI service key (AI_KEY), a secretLink to this section

  1. Make a key

    In your AI service's dashboard, usually under API keys, make a new key just for your site. That way you can turn it off on its own.

  2. Add it

    Choose Add key next to AI service key and paste it. Under Which service is it for?, check it shows the host of AI_API_URL: the part after https://, up to the next slash.

AI model (AI_MODEL), a settingLink to this section

The name of the model to answer with, exactly as your AI service's list of models writes it. A small, fast model keeps answers quick and cheap.

Write your instructionsLink to this section

Open api/ai-reply.ts in Site code and change the text in INSTRUCTIONS. It starts with instructions for a business site: answer about what it offers, opening hours, prices and how to get in touch, in two or three sentences, in the visitor's language, and point to the contact page when unsure. Say what your AI may talk about, and what it should say when it doesn't know.

Connect your pageLink to this section

Your page sends the question as JSON and shows the answer as plain text, never as HTML. Connect it with AI in the setup card asks your AI to do it. Or tell it:

Ask your AI
Add a question box to the FAQ page that sends the question to /api/ai-reply as JSON with question, shows the answer as plain text, and shows the error words when there is no answer.

Try it in the previewLink to this section

  1. Turn on server tasks

    In the setup card, choose Turn on server tasks if they are off.

  2. Ask a question

    In the preview, ask something your instructions cover, then something they don't. The second should get a polite I don't know.

  3. Check the call

    In Project settings, Server tasks, Recent calls, pick Preview. A good call shows status 200 and the AI service among the services it reached.

Go liveLink to this section

Check your spending limit at the AI service, then publish your site. The live copy of the task starts answering on your live address.

Services it works with as writtenLink to this section

The task sends the key as a Bearer header and JSON with model, a length limit and a list of messages with a system and a user role. That is the chat completions shape many AI services take. Newer reasoning models get the length limit in the field they ask for, and if a service refuses the field it got, the task asks once more with the other one. We checked these services' API guides against it:

  • OpenAI: https://api.openai.com/v1/chat/completions, with any chat model, the newer reasoning models included.
  • Mistral AI: https://api.mistral.ai/v1/chat/completions.
  • Groq: https://api.groq.com/openai/v1/chat/completions.
  • OpenRouter: https://openrouter.ai/api/v1/chat/completions, with the model name from its list.

A service that takes the key in a header of its own, or the question in other fields, needs a small change: edit aiRequest() and readAnswer() in api/ai-reply.ts to match its guide, or ask your AI to. Pass the key as it is: Xodia puts the real key in on its way to the service.

Common problemsLink to this section

The page gets not_set_upLink to this section

One of AI_KEY, AI_API_URL and AI_MODEL isn't added. Check all three are in Keys and secrets, spelled exactly so.

No answer right nowLink to this section

Open the call in Recent calls: what the task wrote says what went wrong.

  • The AI service answered 401: the key is wrong, or Which service is it for? doesn't match the host in AI_API_URL.
  • The AI service answered 400 or 404 with a line about the model: check AI_MODEL against the service's list of models.
  • The AI service answered 429: you reached the service's rate or spending limit.
  • The AI service didn't answer in time or couldn't be reached: check AI_API_URL is the full chat address, starting with https://.
  • No line from the task at all: the service answered, but put its answer where the task doesn't look. Change readAnswer() to match its guide.

Ask a question of up to 500 charactersLink to this section

The question was empty or too long. Limit the question box on your page to 500 characters.

The AI talks about other thingsLink to this section

Make INSTRUCTIONS stricter: list what it may answer and say what to reply to anything else. Then save and try again in the preview.

The AI website builder for real code. Made by Zuzo Studio LLC.

Claude, Cursor, Lovable, Bolt, Replit, Webflow, Framer and other product names are trademarks of their owners. Xodia is not affiliated with them.