Build with a coding agent
These docs are written so that a coding agent, such as Claude Code, Codex or Cursor, can build an integration from them alone. What it needs is all plain text:
| File | What it holds |
|---|---|
/llms.txt |
The rules an integration must follow, and a link to every page’s Markdown copy. Start here. |
/_llms-txt/khalani-api.txt |
Every get-started, guide and concept page for the API, in one file. |
/openapi/v3.json |
The OpenAPI 3.1 contract: every route, field, status and example. |
/<page>.md |
Any page as Markdown: add .md to its path, such as /guides/fund-orders.md. |
Have it read the files raw
Section titled “Have it read the files raw”Tell your agent to download these files, for example with curl, rather than through a web-browsing or fetch tool. Many such tools summarize a page before the agent sees it, and a summary drops exact values from tables and code: an error code, a field name, an amount in base units. An agent working from a summary writes plausible code against an API that doesn’t exist.
A prompt to start from
Section titled “A prompt to start from”Paste this into your agent, and add your own stack and where the code goes:
Build a backend integration with the Khalani API v3 (https://api.hyperstream.dev/v3).
Read these with curl, raw, before writing code. Don't use a summarizing fetch tool:- https://docs.khalani.network/llms.txt (the integration rules: follow every one)- https://docs.khalani.network/_llms-txt/khalani-api.txt (the guides)- https://docs.khalani.network/openapi/v3.json (the contract; generate types from it)
Build: fetch the catalog, quote a trade, create an order from an option theuser's wallet can fund, return the funding steps to the frontend, poll theorder until summary.pollAfterSeconds is null, and relay a cancel signed byrefundTo. Read the API key from the KHALANI_API_KEY environment variable;it must never reach the browser.
Handle every error by its `recovery` field, not its `code`. Treat open listsas open. Send API-Revision: 0 on every request. Write tests that mock theAPI and the wallet; never send a real deposit from a test.Generate types
Section titled “Generate types”Generate TypeScript types from the contract, so the compiler checks field names:
npx openapi-typescript@7.13.0 https://docs.khalani.network/openapi/v3.json -o khalani-v3.d.tsEach named schema, such as Order, QuoteResponse and ApiError, becomes components["schemas"]["Order"]. Open lists come through as their known values or any string, so a value added later still type-checks.
Test without moving funds
Section titled “Test without moving funds”Most of an integration can be exercised for free:
GET /v3/catalogandPOST /v3/quotecreate nothing.POST /v3/orderscreates an order, but nothing moves until the user funds it. An order you never fund expires at no cost. It does count against your rate limits.- Errors are easy to provoke: a 1-unit quote returns
422 AMOUNT_TOO_SMALL, and a secondPOST /v3/orderswith the same option and other accounts returns409 QUOTE_USED.
Run one real order with a small amount, as the quickstart does, before you go live. There is no test environment: every call reaches production.
Review what it wrote
Section titled “Review what it wrote”Check these by hand. They are where generated integrations go wrong:
- The API key is read on the backend only, and never logged.
- Asset ids come from the catalog, and amounts are base-unit strings converted with each asset’s
decimals, never floats. - The option
idis sent toPOST /v3/ordersunchanged. - An option whose
requiresholds a value the code doesn’t know is skipped. - On an EVM source, the deposit is sent from the
payer, after the allowance check, with the step’svalueandgasLimit. - On a non-EVM source, exactly the transfer step’s
amountgoes to itstoaddress as given, once. - Polling follows
summary.pollAfterSecondsand stops when it is null. It doesn’t stop atdelivering. - Errors are handled by
recovery. A request that failed withretryis resent unchanged. - Response parsing ignores unknown fields.