What the SDK does for your application
PHPWhat your application does through the SDK — run flows, wait for them, keep customers and their credits, check webhooks — and what the SDK does by itself on every call.
3 min read
The SDK is the code of your application that works with Slen. It runs the flows of your project and reads how they ended, keeps your customers and their credits, and checks the webhooks Slen sends you. Slen has an SDK for PHP and one for Node.js. Both call the same API and have the same calls.
What you do with it
| Task | The calls | Read more |
|---|---|---|
| Run a flow | operations.execute(), operations.executeAsync() | Send a request |
| Wait for a run and read its trace | executions.wait(), executions.get(), executions.trace() | Async runs and waiting |
| Keep customers and their credits | customers.create(), customers.topUp(), customers.charge(), customers.entries() | Customers and credits |
| Receive webhooks | webhooks.constructEvent() | Webhooks |
A flow is built and published on AI Flows, and the decisions about money are made in it: which model to call, which budget to check, what to do when a call is refused. A model node of the flow holds the money before it calls the model and settles what the call cost. The SDK has no call that moves money around a model call: it starts the flow and reads how it ended.
What the SDK does by itself
It names each piece of work. A run and a movement of credits carry an idempotency key, and the SDK makes one when you pass none. A repeat under your own key is answered, not run again — Idempotency keys.
It sends a request again when that is safe: after no answer, a
429or a503, under the same key. It never repeats a500,502or504, because a provider may have been paid — Retries and timeouts.It raises one type of error for each code, the same type in both SDKs. The type says whether money may have been spent — Handling errors.
It waits for a run at the pace the API asks for — Async runs and waiting.
What stays in the console
The people of the workspace set things up in the console:
flows and their versions, budgets, policies, provider connections and pools, API keys, members;
the prices of operations in credits, which
customers.prices()reads;the webhooks and their signing secrets, on Webhooks;
approvals: a person decides on Approvals, and your application learns the outcome by waiting for the run or from a webhook.
Your API key goes to your server, never to a browser. Issue one on Keys & Access.
PHP and Node.js
The two SDKs have the same calls, raise the same error types and write the same journal and the same spans. The PHP SDK comes with a Laravel integration. The Node.js SDK reads its key from SLEN_API_KEY and sends spans to OpenTelemetry. PHP and Node.js compares them.
Every call of the SDK that reaches Slen is an ordinary HTTP request of the API. Installation shows the request of a run over HTTP.
Where to go next
Quickstart — the first run of a flow.
Installation — what each SDK needs, and the API key.
Client and methods — every call of the SDK.