# Common SDK uses

> Authentication, integrations, functions, analytics and error handling.


## Authentication

```ts
const user = await ds.auth.register({ email, password, full_name });
const user2 = await ds.auth.loginViaEmailPassword(email, password);
const me = await ds.auth.me();            // null when signed out
await ds.auth.updateMe({ company: "Acme" });
const signedIn = await ds.auth.isAuthenticated();
ds.auth.logout("/");                      // optional redirect
```

## Integrations

```ts
const text = await ds.integrations.Core.InvokeLLM({ prompt: "Summarize: " + notes });

const data = await ds.integrations.Core.InvokeLLM<{ title: string; tags: string[] }>({
  prompt: "Extract a title and tags from: " + notes,
  response_json_schema: { type: "object", properties: { title: { type: "string" }, tags: { type: "array", items: { type: "string" } } } },
});

const { url } = await ds.integrations.Core.GenerateImage({ prompt: "watercolor lighthouse at dawn" });
const { file_url } = await ds.integrations.Core.UploadFile({ file });       // up to 10 MB
await ds.integrations.Core.SendEmail({ to, subject: "Hi", body: "<p>Hello</p>" });
```

AI calls count against the app owner's limits.

## Functions and analytics

```ts
const res = await ds.functions.invoke("createInvoice", { orderId });
ds.analytics.track({ eventName: "invoice_created", properties: { amount: 42 } });
```

## AI agents

```ts
const convo = await ds.agents.createConversation("support");
const reply = await ds.agents.sendMessage(convo.id, "What did I order last week?");
console.log(reply.content);
```

See [Agents reference](/docs/developers/backend/agents).

## Errors

```ts
import { DraftshipError } from "@/lib/draftship";
try {
  await ds.entities.Post.update(id, { title });
} catch (e) {
  if (e instanceof DraftshipError && e.status === 403) alert("You can only edit your own posts");
}
```
