# Trigger from your code

import { Steps } from "@astrojs/starlight/components"
import Prereqs from "@docs/Prereqs.astro"
import UiWalkthrough from "@docs/UiWalkthrough.astro"
import ClientTabs from "@docs/ClientTabs.astro"

Start a new agent [session](/docs/deep-dives/concepts/agents/sessions/) from your own code. No browser needed. Use this to open sessions from CI, webhooks, or scripts, then drive them over the connection URL.

<Prereqs>
  - A Ren account with a [project](/docs/deep-dives/concepts/compute/projects/) and at least one
  [agent](/docs/deep-dives/concepts/agents/agents/) - [The CLI installed](/docs/developers/cli/), or a personal access
  token for the API and TypeScript calls
</Prereqs>

## In the UI

<UiWalkthrough>
  {/* TODO(demo): screen recording – starting a session with a prompt from the dashboard, ~8s loop */}
</UiWalkthrough>

<Steps>

1. Open **Sessions** in the sidebar and click **New session**.

2. Choose a project and agent, then type your prompt.

3. Click **Run**. The session starts immediately.

</Steps>

## Programmatically

Creating a session opens the agent's sandbox and returns the session object. You then drive the session over its connection URL, or read its messages back. To start a session that runs a prompt on its own with no connection, schedule a [cron trigger](/docs/guides/automate/schedule-cron-trigger/). The trigger's `inputMessage` is the prompt the agent receives on each fire.

<ClientTabs clients={["cli", "api", "typescript"]}>

<Fragment slot="cli">
  **Create a session**

```bash
ren sessions create \
  --pod-id pod_abc123 \
  --project-id prj_def456 \
  --title "Weekly report"
```

**List sessions**

```bash
ren sessions list --project-id prj_def456
```

**Get a session's connection URL** (for driving the session or opening it in a coding agent)

```bash
ren sessions url ses_abc123
```

</Fragment>

<Fragment slot="api">
  **Create a session**

```bash
curl -X POST https://api.renai.build/api/sessions \
  -H "Authorization: Bearer $REN_PAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "podId": "pod_abc123",
    "projectId": "prj_def456",
    "title": "Weekly report"
  }'
```

**List sessions**

```bash
curl "https://api.renai.build/api/sessions?projectId=prj_def456" \
  -H "Authorization: Bearer $REN_PAT_TOKEN"
```

**Get a session's connection URL**

```bash
curl "https://api.renai.build/api/sessions/ses_abc123/url" \
  -H "Authorization: Bearer $REN_PAT_TOKEN"
```

</Fragment>

<Fragment slot="typescript">
  ```ts
  import { createRenClient, pat } from "@renai-labs/sdk"

const client = createRenClient({
baseUrl: "https://api.renai.build",
auth: pat(process.env.REN_PAT_TOKEN!),
})

// Create a session
const { data: session, error } = await client.session.create({
body: {
podId: "pod_abc123",
projectId: "prj_def456",
title: "Weekly report",
},
})
if (error) throw error
console.log(session.id, session.status) // "ses_abc123" "idle"

// Get its connection URL to drive the session
const { data: url } = await client.session.url({ path: { id: session.id } })
console.log(url.authedUrl) // "https://…"

```
</Fragment>

</ClientTabs>
```