Connect with a coding agent
Instead of adding Zyonix to your application by hand, you can let the coding agent you already use do it: Claude Code, Cursor, Codex, GitHub Copilot, Windsurf or any other agent that can read your repository, edit files and run commands.
You paste one prompt. The agent:
- surveys your repository and writes down what it found, before it changes anything;
- adds the Zyonix SDK as a dependency;
- starts Zyonix once at start-up, marks the function that handles one document as a run, marks two to six stages inside it as steps, and records the final result;
- checks its own work without needing a Zyonix server (it runs your tests and one or two documents in local mode);
- reports what it changed.
You stay in charge of the two things that matter: the API key, and the decision to send document content. The agent never sees the key and never turns on full capture.
If you prefer to do it yourself, follow Install the SDK and then Integrate by hand. The result is the same.
Before you start
You need:
- An application written in Python 3.10 or newer. At least the part that calls the AI model must be Python: the SDK is Python only.
- A Zyonix account and the address of your Zyonix website, for example
https://zyonix.example.com. - The administrator role on the agent (the application in Zyonix) you want to connect, or someone who has it. Only administrators can create API keys (step 4).
- A coding agent that can edit files and run commands in your repository (an "agent" or "write" mode, not a read-only chat).
- A way to set environment variables or secrets for the place where your application runs (your shell, Docker Compose, Kubernetes, your CI system or hosting platform).
The agent will want to install a package and run your tests. Allow it to run commands when it asks, or run them yourself when it tells you to.
Step 1: open your repository on a new branch
Work on a separate git branch so that the change is easy to review and easy to throw away.
In a terminal, in the root folder of your application's repository:
git checkout -b add-zyonix
Then open that folder in your coding agent:
| Agent | How to open the repository |
|---|---|
| Claude Code | cd into the repository folder and run claude |
| Cursor | File → Open Folder and choose the repository folder |
| Codex | cd into the repository folder and run codex (or connect the repository in Codex on the web) |
| GitHub Copilot | Open the folder in VS Code (or your JetBrains IDE) with Copilot Chat installed |
| Windsurf | File → Open Folder and choose the repository folder |
If your agent has a mode setting, choose the one that lets it edit files and run commands (for example Agent mode in Cursor and Copilot Chat).
Step 2: copy the prompt, fill in its settings, paste it
The prompt
Copy the whole block below. Use the copy button at the top right of the block so you get every line.
Add Zyonix to this repository. Zyonix monitors AI pipelines: its Python SDK records one "run" per
item the application processes (a document, a message, a request), one "step" per stage inside
it, and the item's final structured result. A Zyonix server then checks results and explains
failures.
Settings (filled in by the person who gave you this prompt):
- Zyonix address: https://zyonix.example.com
- Service name: my-ai-service
- Capture: hash_only
Rules, all of them:
- Never ask for, write, print or commit an API key. The key reaches the application only through
the environment variable ZYONIX_API_KEY, which the person sets later.
- The application must behave exactly as before: same results, same errors, same output. Zyonix
never raises into the application, so do not wrap its calls in try/except.
- Never write `capture: full` or `init(capture="full")`, and do not create a zyonix.yaml file.
- Keep the change small: a dependency, an import, decorators and a few calls. Do not refactor,
rename or move code. If something below does not fit this repository, stop and explain.
1. Survey first, edit nothing yet. Find and write down in a few lines:
a. Is the AI part written in Python 3.10 or newer? The SDK is Python only. If not, stop and say so.
b. How dependencies are declared (requirements*.txt, pyproject.toml with uv/poetry/pdm, Pipfile)
and how the environment is installed.
c. The entry point(s) of the process: script, web app, worker, CLI.
d. The unit of work: the function that handles ONE item from start to end. It becomes the run.
e. The stages that function calls (parsing, retrieval, the model call, post-processing,
validation, saving) and the LLM library used: openai, anthropic, langchain, llama-index,
litellm, bedrock (boto3), or another.
f. The final structured result of one item.
g. Conflicts: the SDK needs pydantic>=2.7, httpx>=0.27 and opentelemetry>=1.45. If the project
pins an older major version of one of them (pydantic 1 is the usual one), stop and report.
2. Add the dependency `zyonix-sdk[EXTRA]>=0.1.13,<0.2` with the project's own tool (for example
`uv add`, `poetry add`, or a line in requirements.txt), where EXTRA is the LLM library from 1e
(openai, anthropic, langchain, llama-index, litellm or bedrock). For another library use
`zyonix-sdk>=0.1.13,<0.2` without an extra. Install it into the project's environment.
3. Start Zyonix once per process, at start-up, before the first item is handled:
import os
import zyonix
zyonix.init(service="<service name>", release=os.getenv("GIT_SHA"))
Use the variable the project already has for its build or version if there is one. In a web
application put it in the start-up code (app factory, lifespan, settings module), never in a
request handler. Address and key come from the environment (step 8), not from arguments.
4. Mark the unit of work from 1d:
@zyonix.run(doc_id=lambda item: item["id"], source="<where items come from>")
def handle(item): ...
The doc_id function receives the same arguments as the decorated function and returns a stable
id of the item (an id, a file name, a message id), never a random value. It works on `async def`
too. When there is no single function for one item, wrap the per-item code instead:
with zyonix.run(doc_id=item_id, source="..."):
One run per item: never put the run around a loop over many items.
5. Mark the stages from 1e that the unit of work calls, two to six of them, with
`@zyonix.step("<name>")`. Prefer these names where they fit: "parse" (or "ocr"), "retrieve",
"extract" (the model call), "postprocess", "validate", "deliver".
Add `replayable=True` to exactly ONE step, the model call that produces the result, and only if
it is a module-level function (not nested, not a lambda, not a method) whose result depends only
on its arguments: the document text and a configuration dict (model name, prompt version...).
If it reads its prompt, model or client settings from globals or `self`, do not change it:
leave `replayable` off and say so in your report.
A function that acts on the outside world (sends a message, writes a database, calls an external
API) gets `@zyonix.tool("<name>")` instead of a step.
6. Record the result: just before the unit of work returns the final structured result from 1f,
pass it through `zyonix.output(result, schema="<TypeName>")`. It returns the same object, so
`return zyonix.output(result, schema="Invoice")` is fine. Dicts, pydantic models and
dataclasses all work.
7. Only where the application already has them, and nowhere else:
- a place where a person corrects a result: `zyonix.feedback(item_id, corrected=fixed_result, verdict="wrong")`;
- its own validation of a result: `zyonix.check("<rule name>", passed, detail="...")`.
8. Configuration. In the project's example environment file or configuration docs (never a file
with real secrets), add:
ZYONIX_ENDPOINT=<Zyonix address>
ZYONIX_API_KEY= # an sdk key, from your secret store
ZYONIX_CA_FILE= # only if the Zyonix server uses a private certificate authority
If the address's host is a public name (not localhost, a private IP, or a .local/.internal
name), also add ZYONIX_EGRESS_ALLOW=<that host>: without it the SDK refuses to send.
A script or batch job that exits after its work must call `zyonix.flush(10)` before it exits;
a long-running server does not need it.
9. Verify, without a Zyonix server:
a. Run the project's tests. They must pass exactly as before.
b. Run the application on one or two items with the environment variables ZYONIX_MODE=local
and ZYONIX_LOCAL_PATH=zyonix-check.jsonl (no key needed; your output must be identical to a
run without them). Then read zyonix-check.jsonl: each line is a JSON object; spans are in
data.resourceSpans[].scopeSpans[].spans[]. Confirm one span with the attribute
zyonix.run.doc_id per item, carrying your id; spans with zyonix.step.name for your steps;
zyonix.step.replayable=true on at most one step; and zyonix.record.ref on the run span (the
recorded result). Delete zyonix-check.jsonl afterwards.
c. Only if ZYONIX_API_KEY is already set in your environment (do not ask for it): run
`zyonix doctor` and report its last line.
10. Report in this form:
- Files changed, one line each.
- Run: which function, which doc_id. Steps: names and functions. Replayable: which one, or
why none.
- Not instrumented, and why.
- Verification: test result, and what zyonix-check.jsonl contained (runs, steps).
- Next steps for the person: put an sdk key in the secret store as ZYONIX_API_KEY, set
ZYONIX_ENDPOINT, run `zyonix doctor`, process one item and find it in Zyonix under
Documents.
Fill in the three settings
Before you paste, change the three lines under Settings at the top of the prompt. Edit them in the agent's input box after pasting, or in a text editor before.
| Setting | What to write | Example |
|---|---|---|
| Zyonix address | The address of the Zyonix website your team signs in to, starting with https://. Copy it from your browser's address bar, without any page path after the host. | https://zyonix.example.com |
| Service name | A short, stable name for this application, in lower case with hyphens. It labels every document this application sends. Use the same name in every environment. | invoice-extractor |
| Capture | Leave it at hash_only. Do not change it. | hash_only |
Why leave capture at hash_only: in this mode Zyonix receives fingerprints (hashes) of your
documents and results, not the documents themselves. Turning on full capture is a decision about
your data that you make yourself, after the integration works. See
Turning on full capture below.
Where to paste it
Paste the prompt into the box where you normally type requests to the agent, and send it.
| Agent | Where to paste |
|---|---|
| Claude Code | The prompt in your terminal, where claude waits for input. Paste and press Enter. |
| Cursor | The chat panel on the right, set to Agent mode (older versions call it Composer). |
| Codex | The prompt of the codex command in your terminal, or the task box in Codex on the web. |
| GitHub Copilot | The Copilot Chat panel, switched to Agent mode. |
| Windsurf | The Cascade panel, in the mode that can write code. |
| Other agents | The chat or task box of the agent, in a mode that can edit files and run commands. |
The prompt tells the agent never to ask for a key. If an agent asks anyway, refuse. A key you paste into a chat may end up in the agent provider's logs, in a file in your repository, or in a commit. You add the key yourself in step 4.
Step 3: let it work, then review
The agent first writes a short survey of your repository and then makes the change. This usually takes a few minutes. It may ask permission to install the package and run your tests.
When it is finished it prints a report with these parts: files changed, the run and its
doc_id, the steps, which step is replayable (or why none is), what it did not instrument,
and how it verified the change.
Review the change like any pull request. See the full diff with:
git diff
Go through this checklist:
- The diff is small. It adds a dependency, an
import zyonix, onezyonix.init(...), one@zyonix.run(...)(orwith zyonix.run(...)), a few@zyonix.step(...), onezyonix.output(...), and nothing else changes. Your application must behave as before. - No key in any file, and no
capture: full. Keys belong in your secret store. Full capture is your decision. There is nozyonix.yamlfile in the diff. -
doc_idis your document's own id, for example a message id, a file name or a database id. It must not be random (nouuid4()): it is how you find a document in Zyonix and how corrections are matched to it. - At most one step has
replayable=True. It is the step thatzyonix testandzyonix replayrun again with a fix. If the agent said none fits, read When may a step be replayable. - The report says the tests passed and the check file had one run per document. That means the agent ran the application, not only edited it.
-
zyonix.initruns once per process, at start-up, not inside a request handler or a loop. - Scripts that exit after their work call
zyonix.flush(10)before they exit. - The example environment file (for example
.env.example) listsZYONIX_ENDPOINTand an emptyZYONIX_API_KEY, andZYONIX_EGRESS_ALLOWif your Zyonix address is a public name.
If something is wrong, tell the agent what to change in the same chat, or fix it yourself. When you are happy, commit the change on the branch:
git add -A
git commit -m "Add Zyonix monitoring"
Step 4: create the sdk key and put it where your application runs
Do this step yourself, not the agent.
Create the key
-
Sign in to the Zyonix website.
-
Make sure the agent switcher at the top left shows the application you are connecting.
-
Open Team and scroll to API keys.
-
In the kind selector next to Create key, choose sdk ("your application sends its runs with it").
-
Click Create key.
-
A window shows the new key, ready to copy as two lines:
ZYONIX_ENDPOINT=https://zyonix.example.comZYONIX_API_KEY=zx_sdk_xxxxxxxxClick Copy. The key is shown only this once. If you lose it, create a new one and revoke the old one.
Use an sdk key for the application. It can only send documents and corrections; it cannot read
anything back. A cli key is for a developer's or CI's zyonix commands, and an agent key is
for a coding agent that investigates problems later. An agent key cannot send documents at all.
Put it in your application's environment
The SDK reads its settings from environment variables of the process that runs your application:
| Variable | Value | When |
|---|---|---|
ZYONIX_API_KEY | the sdk key, zx_sdk_... | always |
ZYONIX_ENDPOINT | your Zyonix address, https://zyonix.example.com | always |
ZYONIX_EGRESS_ALLOW | the host of that address, zyonix.example.com | when the host is a public name (see below) |
ZYONIX_CA_FILE | path to a PEM file with the certificate authority | only if your Zyonix server uses a private certificate |
Put the key in the same place you keep your other secrets, such as your AI provider's key. Never commit it. Pick the example that matches how your application runs.
A shell, for a quick try (lasts until the terminal closes):
export ZYONIX_ENDPOINT=https://zyonix.example.com
export ZYONIX_EGRESS_ALLOW=zyonix.example.com
export ZYONIX_API_KEY=zx_sdk_xxxxxxxx
$env:ZYONIX_ENDPOINT = "https://zyonix.example.com"
$env:ZYONIX_EGRESS_ALLOW = "zyonix.example.com"
$env:ZYONIX_API_KEY = "zx_sdk_xxxxxxxx"
Docker Compose with an env_file. Add the lines to the .env file your service already
loads (keep that file out of git):
ZYONIX_ENDPOINT=https://zyonix.example.com
ZYONIX_EGRESS_ALLOW=zyonix.example.com
ZYONIX_API_KEY=zx_sdk_xxxxxxxx
services:
app:
image: my-app:latest
env_file:
- .env
Then recreate the container so it picks up the new variables: docker compose up -d app.
Kubernetes. Keep the key in a Secret and the address in the Deployment:
kubectl create secret generic zyonix --from-literal=ZYONIX_API_KEY=zx_sdk_xxxxxxxx
# in the Deployment's container spec
env:
- name: ZYONIX_ENDPOINT
value: https://zyonix.example.com
- name: ZYONIX_EGRESS_ALLOW
value: zyonix.example.com
- name: ZYONIX_API_KEY
valueFrom:
secretKeyRef:
name: zyonix
key: ZYONIX_API_KEY
A CI job or hosting platform. Add ZYONIX_API_KEY as a secret in the platform's settings and
expose it to the job or service as an environment variable. For example, in GitHub Actions:
env:
ZYONIX_ENDPOINT: https://zyonix.example.com
ZYONIX_EGRESS_ALLOW: zyonix.example.com
ZYONIX_API_KEY: ${{ secrets.ZYONIX_API_KEY }}
Only jobs that run your application on real documents need the sdk key. Your unit tests do not: without a key the SDK does nothing.
By default the SDK sends data only to addresses that are clearly local (localhost, a private IP
address, or a name such as zyonix, zyonix.internal or zyonix.local). A public name such as
zyonix.example.com is refused until you name it in ZYONIX_EGRESS_ALLOW (or egress_allow in
zyonix.yaml). This protects you from sending documents to a wrong address by mistake. Without it,
your application runs normally, but nothing arrives in Zyonix, and zyonix doctor says why.
Settings in a .env file
The SDK reads ZYONIX_ENDPOINT, ZYONIX_API_KEY and ZYONIX_CA_FILE from the process
environment. Docker Compose's env_file puts a .env file's lines there. But an application
that reads its .env file itself does not:
- pydantic-settings (
BaseSettingswithenv_file=".env") reads the file into your settings object only; - python-dotenv with
dotenv_values(), orload_dotenv()when the variable is already set to something else (withoutoverride=True), does not change what is already in the environment.
Run outside Docker, such an application then has its own settings but the SDK sees no key, and sends nothing. Fix it in one of these ways:
-
Export the variables in the shell or in the service definition (systemd unit, Compose
environment:, Kubernetesenv:), as shown above. -
Or load the file into the environment at start-up, before
zyonix.init:from dotenv import load_dotenvimport zyonixload_dotenv() # puts the .env lines into os.environzyonix.init(service="invoice-extractor")
zyonix doctor, run from the same shell, shows the endpoint and key it found.
Step 5: check the connection and send one document
-
In the environment where your application runs (the same shell, container or pod, so that it sees the same variables), run:
zyonix doctorIt checks the configuration, the data boundary, your LLM library, that the server is reachable and that the key is accepted, then sends one test document. It must end with:
all checks passedIn a container:
docker compose exec app zyonix doctor. Each line is explained in Testing locally. If a line says[FAIL], the line below it says how to fix it. -
Start your application the usual way and let it process one real document.
-
Open the Zyonix website and go to Documents. The document appears within a few seconds, under the
doc_idyour application gave it. Click it to see its steps, AI calls and timings.
With capture: hash_only (what the agent set up), the document appears with its id, steps,
timings, AI model names and token counts, but it is not checked: Zyonix has no content to
check it against, so it shows as not checked. To have documents checked, turn on full capture as
described next.
You are connected. Merge the branch through your usual review process and deploy.
Turning on full capture deliberately
Zyonix finds wrong answers by comparing the AI's result with the document it read. For that it needs the content. Full capture sends it.
hash_only (what the agent set up) | full | |
|---|---|---|
| What is sent | Hashes (SHA-256 fingerprints) of every piece of content, plus metadata in clear: your doc_id, source, service and release, step and function names, the schema name, model names, token counts, timings, statuses and exception types | The same, plus the redacted document text, prompts, AI answers, step inputs and outputs, the output record, exception messages and the file name (doc_name) |
| Documents checked | No (shown as not checked) | Yes |
| Causes explained | No | Yes |
zyonix test, zyonix replay | Not available | Available |
Redacted means that before anything leaves your process, the SDK masks email addresses, phone numbers (with a country code), IBANs and card numbers, plus any patterns you add. Redaction masks patterns; it does not find every personal or confidential value. A hash is not anonymous either: a short or guessable value (an amount, an invoice number) can be checked against its hash.
To turn it on:
-
Agree first with whoever is responsible for your data what may be sent to Zyonix.
-
Create a
zyonix.yamlfile in the folder your application starts from (its working directory):service: invoice-extractorendpoint: https://zyonix.example.comegress_allow: [zyonix.example.com]capture: fullredaction:presets: [email, phone, iban, card_number]custom_patterns:- {name: customer_ref, pattern: "CUST-[0-9]{6}"}zyonix init --service invoice-extractor --endpoint https://zyonix.example.comwrites a commented starter file you can edit instead. That file already sayscapture: full; keep the line only once you have agreed to it. -
Check what would be sent before sending it. Run a few test documents with
ZYONIX_MODE=localand read the file it writes (see Testing locally). It contains exactly what remote mode would send. Add redaction patterns until nothing you may not share is readable. -
Deploy with the file and run
zyonix doctoragain. It now sayscapture=full (set in zyonix.yaml).
Every setting of the file is described in Configuration.
If zyonix.yaml exists but cannot be read (a YAML mistake, an unknown key, a wrong value),
the SDK sends nothing at all until it is fixed, because it cannot know what the file meant to
restrict. Your application keeps running normally. zyonix doctor names the file and the
problem.
Troubleshooting
| What you see | Cause and fix |
|---|---|
| The agent says the AI part is not Python | The SDK is Python only. Connect the Python part, or contact Zyonix. |
| The agent stops at a dependency conflict | Your project pins pydantic 1, an httpx older than 0.27 or OpenTelemetry older than 1.45. Upgrade it first, or keep Zyonix out of that environment. See Install. |
| The agent says no step can be replayable | Your model call reads its prompt or client from globals or self. Everything else still works; only zyonix test and zyonix replay need a replayable step. See When may a step be replayable. |
| The agent wants a key | Do not give it one. It verifies its work in local mode without a key. |
zyonix doctor: tracing is off: set ZYONIX_API_KEY | The key is not in this process's environment. Check the variable name and that you set it in the same shell or container. If your application reads .env itself, see Settings in a .env file. |
zyonix doctor: ... is not local and not listed in egress_allow | Set ZYONIX_EGRESS_ALLOW to the host of your Zyonix address. |
zyonix doctor: CERTIFICATE_VERIFY_FAILED | Your Zyonix server uses a private certificate. Set ZYONIX_CA_FILE to the path of its CA certificate (a .pem file your administrator gives you). |
zyonix doctor: API key rejected (HTTP 401) | The key is wrong, revoked, or belongs to another Zyonix installation. Create a new sdk key. |
zyonix doctor passes, but your documents do not arrive | The application does not see the same variables as your shell (a different container, service or .env handling), or it is a script that exits before sending (add zyonix.flush(10)). More in Troubleshooting. |
| The same document appears many times | The doc_id is random or changes between attempts. Use the document's own id. |
More cases, including multiple processes and performance: SDK troubleshooting.