# Call a service with your key

URL: https://docs.xodia.ai/server-tasks/call-a-service
Last updated: 2026-11-25

The Call a service task calls another service's API with your secret key and gives your page a short answer. Use it for a search, a stock or price lookup, a listing or anything a service answers, without the key ever reaching the browser.

## What it does

- It answers `/api/call-service` on your site. A page calls it with search words, like `/api/call-service?q=blue shoes`, up to 200 characters.
- It calls the service's address with your key, and puts the words in that address's `q` part.
- It gives the page a short copy of the answer: up to 20 items, each text cut to 500 characters. You can choose which fields the page sees.
- Browsers keep the answer for a minute, so the same search doesn't call the service again at once.

> **Warning:** Anyone can call the address, and each call may cost you at the service. Set a limit at the service if it bills you per call.

## Add the task

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

## Keys to add

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

### Service address (SERVICE_URL), a setting

1. Find the address

   In the service's API guide, find the address that answers your question, starting with `https://`. Leave out the `q` part: the task adds it.
2. Add it

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

### Service key (SERVICE_KEY), a secret

1. Make a key

   In the service's dashboard, usually under API keys or developer settings, make a key with read access only, if the service offers that.
2. Add it

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

## Fit it to your service

Most services take the key as a Bearer header and search words in q, which is what the task sends. Open `api/call-service.ts` in Site code, or ask your AI, to change:

- **Where the key goes.** If the guide puts the key in another header or in the address, change `serviceRequest()`. Pass the key as it is: Xodia puts the real key in on its way to the service.
- **What the search is called.** If the service names it something other than q, change it in `serviceRequest()` too.
- **What the page sees.** List the fields in `KEEP`, like `["name", "price"]`. Everything else in the service's answer stays on Xodia.

## Connect your page

Ask your AI:

```
On the Shop page, add a search box that fetches /api/call-service?q= with the words, and shows each result's name and price. Show the error words when there is no result.
```

## Try it in the preview

1. Turn on server tasks

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

   Use the search box in the preview with a few words you know the service has.
3. Check the call

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

## Go live

Publish your site. The live copy of the task starts answering on your live address.

## Services it works with

Any service with an HTTP API that answers JSON and takes an API key works, as written when it takes a Bearer key and q, or after the small change above. We haven't listed services by name here: check the service's API guide for where the key and the search words go.

## Common problems

### The page gets not_set_up

SERVICE_KEY or SERVICE_URL isn't added, or SERVICE_URL isn't a full web address. Check both in Keys and secrets.

### No result right now

The service said no. Recent calls shows the service's status and its own reason:

- 401 or 403: the key is wrong, goes in another place, or Which service is it for? doesn't match the host in SERVICE_URL.
- 404: the address is wrong. Check SERVICE_URL against the guide.
- 429: you reached the service's limit. Wait, or let your page keep answers longer.

### The service didn't answer

It took longer than 10 seconds. Try again; if it keeps happening, check the service's status page.

### The service's answer was too big

The answer was over about 200,000 characters. Ask the service for fewer results, often with a limit or page size in the address.
