Skip to content
WORKSI AI Control

See inside every RAG answer.

A RAG answer is an embedding, a search and a generation. Worksi traces each part, prices the embeddings and the prompt it built, and flags context that keeps growing.

docs-qa · one question, traced
  • workflow_rundocs-qa

    one question

    • agent_stepretrieve
      • llm_callembeddings

        text-embedding-3-small · tokens, cost

      • tool_callsearch_docs

        docs-index · top 5

    • agent_stepgenerate
      • llm_callchat.completions

        gpt-5-mini · prompt size, cost

An answer that outgrew its context.

A change retrieves more chunks for every question, and every prompt carries them all. The answers read the same; the bill does not.

Example values. Detector rules are the product defaults, and the response is in the gateway’s format.

  1. 01

    40 chunks in one prompt

    Retrieval is a tool span with its data source, generation a model call with its prompt size, so the trace shows what one question pulled in.
    docs-qa · the answer that was flagged
    • workflow_rundocs-qa

      one question

      • agent_stepretrieve
        • llm_callembeddings

          text-embedding-3-small · 12 tokens

        • tool_callsearch_docs · top 40

          docs-index

      • agent_stepgenerate
        • llm_call64,800 input tokens

          chat.completions gpt-5-mini

  2. 02

    Past both thresholds

    token_anomaly fires when a call passes 60,000 tokens, or 4× the agent’s p95. This prompt passed both.
    Incident · detector
    detector
    token_anomaly
    rule
    > 60,000 tokens or > 4× agent p95
    this call
    65,230 tokens
    agent p95, 7 days
    12,100 tokens
  3. 03

    Input grows, output doesn’t

    Answer by answer, the input grows with the number of chunks while the output stays the same length.
    Evidence · input tokens per answer
    answer 1
    5 chunks · 9,640 tokens
    answer 2
    12 chunks · 21,300 tokens
    answer 3
    25 chunks · 43,900 tokens
    answer 4
    40 chunks · 64,800 tokens
  4. 04

    A daily token cap

    Put a ceiling on it. A token_limit policy’s daily cap stops the agent once its tokens for the day are spent, before the call reaches your provider; its per‑request cap limits the max_tokens a call may ask for.
    Response
    HTTP/1.1 403 Forbidden{  "error": {    "message": "daily token limit of … for agent reached (used …, policy \"…\")",    "type": "permission_error",    "code": "token_limit_exceeded",    "param": null,    "aiw_request_id": "req_…"  }}

    Example response. The body format is the gateway’s.

What else watches retrieval.

Five of the eleven built‑in detectors, with the conditions they fire on.

What else watches retrieval
DetectorFires when
Token anomalytoken_anomalyA call uses far more tokens than the agent normally does
Tool failuretool_failureA tool keeps failing, or a run ends in error at a tool call
Repeated tool callrepeated_tool_callThe same tool is called with the same arguments again and again in one run
TimeouttimeoutModel or tool calls time out or run past their thresholds
Cost anomalycost_anomalyCost per request jumps versus the agent’s 7-day baseline, or a run exceeds its cost limit

Trace retrieval and generation.

Embeddings and chat go through the gateway. With the SDK, the vector search becomes a tool span with its data source, so the AI Graph shows which agents read which index.

Pro fits most RAG products: 1M gateway requests and 10M spans a month, 30‑day retention, the AI Graph. $49 / month.

Compare plans

SDK packages are distributed by Worksi. Request access. Any OpenAI or Anthropic SDK works with the gateway without them.

rag.py
import osfrom openai import OpenAI client = OpenAI(    base_url="https://gateway.worksi.ai/v1",    api_key=os.environ["AIW_API_KEY"],    default_headers={"X-AIW-Agent": "docs-assistant"},) def answer(question: str) -> str:    # embeddings are priced and traced like chat calls    query = client.embeddings.create(        model="text-embedding-3-small",        input=question,    )    chunks = search_docs(query.data[0].embedding, top_k=5)    reply = client.chat.completions.create(        model="gpt-5-mini",        messages=build_prompt(question, chunks),    )    return reply.choices[0].message.content or ""

Trace one question end to end.

Start with the embedding call: through the gateway it is priced and traced like a chat call.

  • 3‑day trial with Pro features, no card.

Keep readingObservabilityAI agentsCapture modes

Terminal
curl -s https://gateway.worksi.ai/v1/embeddings \  -H "Authorization: Bearer $AIW_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model": "text-embedding-3-small",       "input": "refund policy"}'