# AI examples

Complete, runnable AI examples - the need, the code, the configuration and the failure behavior.

Each example is a complete scenario - the need it answers, the code, the configuration, the expected output and the failure behavior. The code runs as pasted - the only placeholders are names and keys of your own.

| Need | Uses | Example |
| --- | --- | --- |
| A chat that keeps a separate history for each user | `chat`, `chat_id`, `max_history_turns`, `chat_expiry`, a skill | [Chat with memory](https://zato.io/docs/ai/examples/chat-with-memory.html) |
| One service against hosted, self-hosted and gateway-proxied models | LLM connections, the model catalog, enmasse | [Self-hosted models](https://zato.io/docs/ai/examples/self-hosted-models.html) |
| Reliable JSON out of a model | A skill, parsing, validation, a retry path | [Structured output](https://zato.io/docs/ai/examples/structured-output.html) |
| Knowing what each call costs, per caller | The `usage` dictionary of every response | [Token usage](https://zato.io/docs/ai/examples/token-usage.html) |
| A service that survives its provider | Timeouts, exceptions with the provider's reason, the audit log | [Provider failures](https://zato.io/docs/ai/examples/provider-failures.html) |
| Agents calling OAuth-secured enterprise APIs | An MCP gateway, outgoing REST with [Bearer tokens](https://zato.io/docs/security/bearer-tokens/index.html) | [Secured APIs as tools](https://zato.io/docs/ai/examples/secured-apis-as-tools.html) |
| Agents picking the right tool and getting arguments right | Docstrings, declared I/O, argument validation | [Tool selection](https://zato.io/docs/ai/examples/tool-selection.html) |
| Following one agent request end to end | The CID across the audit log, server log and LLM calls | [Tracing one call](https://zato.io/docs/ai/examples/tracing-one-call.html) |
| Several agents that cannot see or affect each other | Credentials, sessions, rate limits, separate gateways | [Multi-agent isolation](https://zato.io/docs/ai/examples/multi-agent-isolation.html) |
| The whole AI setup in version control | One enmasse YAML for security, gateways, connections | [Everything as code](https://zato.io/docs/ai/examples/everything-as-code.html) |
| Testing a service that calls an LLM | Structural assertions, replays, the audit log | [Evaluating AI flows](https://zato.io/docs/ai/examples/evaluating-ai-flows.html) |
