# The SDK

> Start and follow tasks, and answer approvals, from code with @sypnia/agent.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://agent.docs.sypnia.com/tools/sdk/

For agents: createClient({ token }) from '@sypnia/agent/client': tasks.create({ repository, request, case?, budget }), tasks.events(id) async iterator (step, question, approval, done), questions.answer(id, choice), approvals.decide(id, 'approve'|'deny'), tasks.cancel(id). '@sypnia/agent/runner': createRunner({ workspace, model: { endpoint, key }, rules }) to run locally.

```ts
import { createClient } from '@sypnia/agent/client';

const agent = createClient({ token: process.env.SYPNIA_TOKEN });

const task = await agent.tasks.create({
  repository: 'laespiga/web',
  request: 'Customers can cancel an order until 10 am',
  budget: { credits: 40 },
});

for await (const event of agent.tasks.events(task.id)) {
  if (event.type === 'question') await agent.questions.answer(event.id, event.choices[0].id);
  if (event.type === 'approval') console.log('Waiting for a person to approve:', event.summary);
  if (event.type === 'done') console.log(event.pullRequest, event.cost);
}
```

The client never approves on its own unless your code does it explicitly; approvals of **always ask** actions require a person's session, not an API token ([Approvals](https://agent.docs.sypnia.com/safety/approvals)).

## Running locally

```ts
import { createRunner } from '@sypnia/agent/runner';

const runner = createRunner({
  workspace: process.cwd(),
  model: { endpoint: 'https://openrouter.ai/api/v1', key: process.env.OPENROUTER_API_KEY },
});
```
