Kodwen docs
API referenceGateway

Tools

Verified web search and safe page fetching, the same tools every Kodwen agent uses.

Both endpoints go through the rules gate and the per-key rate limit. search returns only snippets verified against the fetched page, with domain (include_domains / exclude_domains), publish-date (published_after / published_before) and freshness filters; each result carries published_at (null when unknown, never the crawl date) and crawled_at. fetch enforces SSRF checks on every redirect hop and a 3 MB cap, and returns up to 40,000 characters (8,000 by default). Metered per call: $3 / 1,000 fast searches, $8 / 1,000 deep, $0.50 / 1,000 fetches; the first 1,000 calls a month are free and calls inside a Kodwen agent turn are not charged (same key, a model call finished in the last 3 minutes, up to 30 calls in 10 minutes). Per-user limits (429) and the 402 insufficient_balance refusal are described in the tools guide. Google results are returned only to accounts Google mode is enabled for. For multi-step questions use deep research. Details: tools guide.

POST
/v1/tools/search

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A Kodwen API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128

Request Body

application/json
  1. body

Body of POST /v1/tools/search.

query*string

Search phrase (trimmed).

Length1 <= length <= 400
max_results?integer

Maximum number of results.

Range1 <= value <= 10
Default5
freshness?string

Only pages published within the window; pages without a known publish date are dropped.

Value in"day""week""month""year"
include_domains?array<>

Only return pages from these hosts (subdomains included, optional path prefix such as github.com/vercel). Scheme and www. are stripped.

Itemsitems <= 10
exclude_domains?array<>

Never return pages from these hosts (same matching as include_domains).

Itemsitems <= 10
published_after?string

Only pages published on or after this date (YYYY-MM-DD or YYYY-MM); undated pages are dropped.

Match^\d{4}-\d{2}(-\d{2})?$
published_before?string

Only pages published before this date (YYYY-MM-DD or YYYY-MM); undated pages are dropped.

Match^\d{4}-\d{2}(-\d{2})?$
content_chars?integer

Also return a verified excerpt of up to this many characters per result in content (omitted or 0 = snippet only).

Range0 <= value <= 2000
country?string

Two-letter market code. Omit it to let the gateway infer it from the query (ro for Romanian queries, us otherwise).

Match^[a-zA-Z]{2}$
lang?string

Language code, optionally with region (en-US). Omit it to infer it from the query; a lang:xx operator in the query wins.

Match^[a-zA-Z]{2}(-[a-zA-Z]{2})?$
mode?string

codai (default): verified-only native search (ToolSearchResponse). google: Grounding with Google Search on Vertex AI, returned as a separate ToolSearchGoogleResponse and never mixed with Kodwen results; 404 when the gateway has not enabled it or it is not enabled for your account, 400 together with a domain or date filter, 503 search_unavailable when Google returns no grounding. fast / deep mean codai with that depth (alias kept for clients that send codai-search's own field).

Default"codai"
Value in"codai""google""fast""deep"
depth?string

codai-search depth. fast (default): ~4.5 s budget. deep: more sources and a ~12 s budget, for research, literature and comparison queries; with fallback: auto the whole request may take ~20 s.

Default"fast"
Value in"fast""deep"
fallback?string

With mode: codai: auto (default) attaches a separate google block (Grounding with Google Search) when Kodwen's own results are weak (none, fewer than 3, or low coverage for code/docs/general/academic/education) or the search service is down; never for currency/weather/fuel/inflation/local_poi and never with a domain or date filter. It runs only for accounts Google mode is enabled for; for every other account it has no effect. off disables it.

Default"auto"
Value in"auto""off"

Response Body

Verified results (or the provider-path shape on deployments without codai-search).

application/json
  1. response

The codai-search JSON, returned verbatim by the gateway.

results*array<>
Itemsitems <= 10
provider*"codai"
Value in"codai"
took_ms*integer

Search-service latency in milliseconds (not the gateway round trip).

Range0 <= value
cached*boolean

Served from the search service's 10-minute result cache.

coverage*number

results.length / max_results, rounded to two decimals.

Range0 <= value <= 1
sources_tried*array<string>
degraded*array<string>

Real source or stage failures and timeouts only (e.g. rerank:timeout, index:error); empty when everything ran.

notes?array<string>

Informational pipeline codes (filtered rows, pending verifies, cache hints); not failures. Omitted when empty.

intent*string

Rule-based query intent used to pick sources.

Value in"currency""weather""encyclopedic""code""docs""site""news""price""local""fuel""inflation""local_poi""academic""definition""education""general"
complete?boolean

The answer is whole even with fewer than 3 results (the reference article for a definition or fact question, a curated official page at rank 1, two news-feed articles, or strict operators such as site: / filetype: / intitle:). The automatic Google fallback does not run on it.

rerank?

Present when the cross-encoder reranker ran.

google?

Present only when the automatic fallback ran (see fallback). A separate result set from Grounding with Google Search — never merged into results; show answer with search_suggestions_html and keep the attribution (Google's terms).

fallback?

Whether the automatic Google fallback was used, and why.

Example Request
curl -X POST 'https://ai.codai.ro/v1/tools/search' \  -H 'Content-Type: application/json' \  -d '{  "query": "curs BNR euro azi"}'
Example Response
{  "results": [    {      "title": "string",      "url": "http://example.com",      "snippet": "string",      "page_age": "string",      "published_at": "2019-08-24T14:15:22Z",      "crawled_at": "2019-08-24T14:15:22Z",      "content": "string",      "license": "string",      "license_url": "http://example.com",      "attribution": "string",      "source": "index",      "verified": true    }  ],  "provider": "codai",  "took_ms": 0,  "cached": true,  "coverage": 0,  "sources_tried": [    "string"  ],  "degraded": [    "string"  ],  "notes": [    "string"  ],  "intent": "currency",  "complete": true,  "rerank": {    "model": "string",    "ms": 0,    "n": 0  },  "google": {    "answer": "string",    "sources": [      {        "title": "string",        "url": "http://example.com"      }    ],    "queries": [      "string"    ],    "search_suggestions_html": "string",    "attribution": "string",    "ai_generated": true,    "cached": true  },  "fallback": {    "used": true,    "reason": "few_results"  }}
POST
/v1/tools/fetch

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A Kodwen API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128

Request Body

application/json
  1. body

Body of POST /v1/tools/fetch.

url*string

Public http/https URL. A bare host is prefixed with https://.

Length1 <= length <= 2048
max_chars?integer

Cap on content length; longer documents are cut at a paragraph boundary and flagged truncated.

Range200 <= value <= 40000
Default8000
focus?string

Phrase to focus on — only the most relevant paragraphs are kept, joined with […].

Lengthlength <= 300
format?string
Default"markdown"
Value in"markdown""text"

Response Body

Extracted page.

application/json
  1. response

Extracted content plus metadata. Optional metadata keys are omitted when the page lacks them.

url*string

The URL as you sent it.

final_url*string

URL after redirects.

Formaturi
title?string
byline?string
description?string
canonical?string
Formaturi
lang?string

Document language as declared by the page.

content_type*string

Lower-cased media type without parameters.

content*string

Readable content in the requested format for a text-extractable resource; an empty string when the kind carries no text (a described resource — see kind). JSON documents are pretty-printed, CSV/TSV and subtitle files are turned into readable text, and a PDF is text-extracted.

chars*integer

Length of content.

Range0 <= value
truncated*boolean

True when max_chars, focus windowing or the 3 MB body cap dropped content, or when a body over the cap was fetched as a byte Range (the answer then holds only its first part).

took_ms*integer
Range0 <= value
cached*boolean

Served from the gateway's 15-minute LRU.

kind?string

What the resource is, decided from the leading bytes (magic bytes first, then an explicit text MIME type, then the MIME prefix, then the URL extension).

Value in"text""data""document""image""audio""video""archive""executable""script""unknown"
sniffed_type?string

MIME type inferred from the leading bytes when it disagrees with content_type (a mislabelled resource). Omitted when the header and the bytes agree.

sha256?string

Hex sha256 of the body — the artifact identity and dedupe key.

Match^[0-9a-f]{64}$
bytes_count?integer

Number of body bytes fetched (the held part when the body was cut).

Range0 <= value
requires_consent?boolean

True for an executable or a runnable script. Fetching a file never authorises running it — the user must approve first, and the sandbox is the safer place to run it.

warning?string

Human-readable note about a fetched file (a mislabelled type, an archive, an executable or a runnable script). Absent when there is nothing to warn about, which is the ordinary text page.

http_status?integer

Status the target answered with (206 when the cap forced a byte Range).

archive?

Entry listing for a zip/tar, present only when the resource is an archive. An entry with unsafe_path escapes the extraction root and must not be extracted.

Example Request
curl -X POST 'https://ai.codai.ro/v1/tools/fetch' \  -H 'Content-Type: application/json' \  -d '{  "url": "https://www.bnr.ro/Cursul-de-schimb-524.aspx"}'
Example Response
{  "url": "string",  "final_url": "http://example.com",  "title": "string",  "byline": "string",  "description": "string",  "canonical": "http://example.com",  "lang": "string",  "content_type": "text/html",  "content": "string",  "chars": 0,  "truncated": true,  "took_ms": 0,  "cached": true,  "kind": "text",  "sniffed_type": "application/zip",  "sha256": "string",  "bytes_count": 0,  "requires_consent": true,  "warning": "string",  "http_status": 0,  "archive": {    "format": "zip",    "truncated": true,    "entries": [      {        "path": "string",        "size": 0,        "dir": true,        "unsafe_path": true      }    ]  }}

Last updated: