What the SDK does for your application

PHP

What 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

TaskThe callsRead more
Run a flowoperations.execute(), operations.executeAsync()Send a request
Wait for a run and read its traceexecutions.wait(), executions.get(), executions.trace()Async runs and waiting
Keep customers and their creditscustomers.create(), customers.topUp(), customers.charge(), customers.entries()Customers and credits
Receive webhookswebhooks.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 429 or a 503, under the same key. It never repeats a 500, 502 or 504, 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.

  • It writes a journal and spans to a logger and a recorder you give it: the route, the status, the ids and the money, never a key, a body or a prompt — Logging, Spans.

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