@@ -16,7 +16,8 @@ Documentation: https://onceonly.tech/docs/
1616- Sync + Async client (httpx-based)
1717- Fail-open mode for production safety
1818- Stable idempotency keys (supports Pydantic & dataclasses)
19- - Decorator for zero-boilerplate usage
19+ - Decorators for zero-boilerplate usage
20+ - Native AI API (long-running jobs, local side-effects)
2021- Optional AI / LangChain integrations
2122
2223---
@@ -35,7 +36,7 @@ pip install "onceonly-sdk[langchain]"
3536
3637---
3738
38- ## Quick Start
39+ ## Quick Start (Webhooks / Automations)
3940
4041``` python
4142from onceonly import OnceOnly
@@ -53,11 +54,54 @@ else:
5354 print (" First execution" )
5455```
5556
57+ Use ` check_lock() ` for:
58+ - Webhooks
59+ - Make / Zapier scenarios
60+ - Cron jobs
61+ - Distributed workers
62+
63+ ---
64+
65+ ## AI Jobs (Server-side)
66+
67+ Use the AI API for long-running or asynchronous jobs.
68+
69+ ``` python
70+ result = client.ai.run_and_wait(
71+ key = " ai:job:daily_summary:2026-01-09" ,
72+ metadata = {" task" : " daily_summary" , " model" : " gpt-4.1" },
73+ timeout = 60 ,
74+ )
75+
76+ print (result.status)
77+ print (result.result)
78+ ```
79+
80+ - Charged ** once per key**
81+ - Polling is free
82+ - Safe across retries and restarts
83+
5684---
5785
58- ## AI Agents / LangChain Integration 🤖
86+ ## AI Agents / Local Side-Effects
5987
60- OnceOnly integrates cleanly with AI-agent frameworks like LangChain.
88+ Use the AI Lease API when your code performs the side-effect locally
89+ (payments, emails, webhooks) but still needs exactly-once guarantees.
90+
91+ ``` python
92+ lease = client.ai.lease(key = " ai:agent:charge:user_42:invoice_100" , ttl = 300 )
93+
94+ if lease[" status" ] == " acquired" :
95+ try :
96+ do_side_effect()
97+ client.ai.complete(key = KEY , lease_id = lease[" lease_id" ], result = {" ok" : True })
98+ except Exception :
99+ client.ai.fail(key = KEY , lease_id = lease[" lease_id" ], error_code = " failed" )
100+ ```
101+
102+ ---
103+
104+ ## LangChain Integration 🤖
61105
62106``` python
63107from onceonly.integrations.langchain import make_idempotent_tool
@@ -69,11 +113,14 @@ tool = make_idempotent_tool(
69113)
70114```
71115
72- Repeated tool calls with the same inputs will execute ** exactly once** , even across retries or agent restarts.
116+ Repeated tool calls with the same inputs will execute ** exactly once** ,
117+ even across retries or agent restarts.
118+
119+ See ` examples/ai/ ` for canonical patterns.
73120
74121---
75122
76- ## Decorator
123+ ## Decorators
77124
78125``` python
79126from onceonly.decorators import idempotent
@@ -83,7 +130,7 @@ def process_order(order_id):
83130 ...
84131```
85132
86- Idempotency keys are generated automatically and are stable across restarts.
133+ Idempotency keys are generated automatically and remain stable across restarts.
87134
88135---
89136
0 commit comments