iicp-client · Rust SDK
Official Rust client library for the IICP protocol — route AI agent tasks by intent across a self-organising mesh of provider nodes. No central broker. No hardcoded endpoints.
urn:iicp:intent:llm:chat:v1 → discover → select → submit
Add to Cargo.toml
[]
= "0.2"
Or for the latest unreleased code:
[]
= { = "https://github.com/RobLe3/iicp-client-rust" }
Quickstart
use ;
async
Configuration
use ClientConfig;
let config = ClientConfig ;
| Field | Default | Description |
|---|---|---|
directory_url |
"https://iicp.network/api" |
IICP directory endpoint |
timeout_ms |
30000 |
Request timeout — max 120 000 ms |
region |
None |
Preferred node region |
node_token |
None |
Bearer token for authenticated nodes |
Discover options
use DiscoverOptions;
let nodes = client.discover.await?;
Error handling
use IicpError;
match client.submit.await
Error codes match the IICP error reference.
Serving as a node — handler contract
When you run a serving node (IicpNode::serve), your handler returns the inner result
value; serve() wraps it in the TaskResponse.result envelope for you. Do not return
an already-wrapped {"result": ...} value — that double-nests the response and breaks
cross-flavour interop with the Python/TS SDKs (response shape must be {"result": {...}}).
The backends::invoke_backend / openai_compat::invoke helpers return a
{"result": ...} consumer envelope, so when using them as a serve handler, unwrap the
inner value first:
let v = invoke_backend
.await
.unwrap_or_else;
// serve() re-wraps in TaskResponse.result — return the inner value to stay single-level.
Ok
NAT traversal — v0.7.0
IICP nodes pick the best available NAT path automatically (ADR-041):
| Tier | Method | Requirement |
|---|---|---|
| 0 | Direct — publicly routable | Open port 8020 |
| 1 | UPnP/IGD port mapping | Home router with UPnP |
| 2 | IPv6 firewall pinhole | IPv6 + UPnP/IGD2 |
| 3 | Relay-as-last-resort | A relay operator in the mesh |
Relay-as-last-resort lets a node behind CGNAT stay reachable by binding an outbound
channel to a public relay node that forwards inbound tasks down it.
Requires the iicp-tcp feature (adds CBOR framing via ciborium).
Running a relay-capable node (relay operator)
[]
= { = "0.7", = ["iicp-tcp"] }
use ;
let node = new;
Node behind CGNAT (connects outbound to relay)
let node = new;
When the worker binds it re-registers with the relay's public address
(transport_method="turn_relay"), making it discoverable.
SDK conformance
| Rule | Description | Status |
|---|---|---|
| SDK-01 | discover → select → submit pipeline | ✓ |
| SDK-02 | task_id auto-generated (UUID v4) |
✓ |
| SDK-03 | Intent URN pattern validation (regex) | ✓ |
| SDK-04 | timeout_ms capped at 120 000 ms |
✓ |
| SDK-05 | Retry on 429 / 503 | planned |
| SDK-06 | W3C traceparent propagation |
planned |
Conformance tier: iicp:sdk:v1 (spec S.14) · Request a badge
Development
Links
- Protocol spec — full IICP specification
- Node setup guide — run your own node
- Error reference — all error codes
- iicp-client-python — Python SDK
- iicp-client-typescript — TypeScript SDK
Apache 2.0 · iicp.network