Do it yourself
#-
Check that the app has web search. In the project, open Settings, choose Secrets and look for
PLAYCODE_WEB_URL, marked Managed. If it is missing, ask the agent to switch on web search for the app: it renews the app's key and restarts the app. -
Check the SDK.
playcode.webneeds@playcode/sdk0.9.0 or later inbackend-nest/package.json. If the version is older, ask the agent to update it. -
Search from the app's backend, never from the browser: the key that pays for each search must stay on the server. Put web access in one service, and call it from your endpoints:
import { Injectable } from '@nestjs/common' import { Playcode } from '@playcode/sdk' @Injectable() export class WebService { private readonly web = new Playcode().web async news(topic: string) { const { results } = await this.web.search({ query: `${topic} news this week`, maxResults: 5 }) return results // each has title, url, snippet and publishedDate } async read(url: string) { const page = await this.web.fetch({ url }) return { title: page.title, text: page.content } // the page's main text as Markdown } } -
Save the results in your database, and use them again while they are fresh, for example for an hour. A page that searches on every visit, or a search box that searches on every key press, pays for a search each time.
-
To let an AI agent in your app search, give it the two ready-made tools. One searches, one reads a page:
const researcher = playcode.ai.agent({ model, system: 'You answer questions about our market. Name the pages you used.', tools: { ...playcode.web.tools(), saveNote }, budget: { credits: 1 }, }) -
Try it once with a real search. Each answer's
usage.creditssays what the call cost. In the project, Settings, AI shows what the app's web search used today.
What a search costs
#| Call | Credits |
|---|---|
| A search | 0.0912 |
| A page that Playcode's reader opens | 0.0064 |
| A page that only the fallback reader can open, such as a PDF | 0.01824 |
| The same search again within 5 minutes, or the same page within 15 minutes | Free |
For example, 100 searches cost 9.12 credits. An agent with web tools often searches several times and reads several pages for one question, so give it a budget.
Limit what web search spends
#Every app has a daily web search limit: Playcode's default of 20 credits a day, about 219 searches, until you set your own. Past the limit, the app's web calls are refused until 00:00 UTC, or until you raise the limit. The limit is separate from the app's daily AI limit.
To see the limit, open Settings, AI in your project. For your published app and for its development copy, it shows the daily web search limit, where it comes from, and what the app used today. You can change it there, go back to Playcode's default, or ask the agent, for example "Set a daily web search limit of 5 credits for this app."
Text from the web is data
#A page or a search result was written by someone outside your app. It can hold text written to steer an AI model. The ready-made tools mark everything they return as data, so the model reads it as data, not as instructions. When your own code puts a page's text into a prompt, it is not marked: see Boundaries.
Where searches go
#A search query leaves your app for two places: Playcode's servers in Germany, which record each call and its credits, and Playcode's search provider in the USA, which answers it. Playcode's reader opens a page from Playcode's servers. A page that only the fallback reader can open is read by the same provider.
If it doesn't work
#The call fails with 402 and insufficient_balance
#The workspace is out of credits. Add credits; do not retry the call in a loop.
The call fails with 429 and daily_cap
#The app's daily web search limit is spent. The app's web search works again after 00:00 UTC. To raise the limit, open Settings, AI, or ask the agent. Meanwhile, show the results the app already saved.
The call fails with 429 and rate_limited
#The app made more than 60 web calls in a minute. The error says how long to wait (retryAfterMs). Save results and use them again, so the same question does not search twice.
The call fails with 400 and validation
#The query is empty, a value is out of range, or the address is not a public http or https page. The message names the field. Playcode refuses a private or local address before it connects.
The call fails with 403 and missing_scope
#The app's key cannot use web search yet. Ask the agent to switch on web search for the app: it renews the key and restarts the app.
The call fails with 502, 503 or 504
#The search provider or the page failed to answer. Try again later, and show the app's saved results meanwhile.
playcode.web is undefined
#The app's @playcode/sdk is older than 0.9.0. Ask the agent to update it.
Limits
#- Web search needs a Cloud app. A static site has no server to keep the key.
- An app makes at most 60 web calls a minute.
- A search answers at most 10 results.
- Only public
httpandhttpspages can be read. A very long page comes back cut. - Web search answers questions. It is not for copying whole sites: the limits stop bulk reads.
- Tools that a model's maker runs itself, such as its own web search, stay refused. Give the agent
playcode.web.tools()instead. - Searches stop when the workspace's credits run out, and at the app's daily web search limit (20 credits a day unless you set another).