Skip to main content
Working code for the agent lifecycle. For prompt design, tool configuration, and template variables, see Configuring voice agents.

Create an agent

const resp = await fetch("https://api.slng.ai/v1/agents", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Appointment Reminder",
    system_prompt:
      "You are a friendly appointment reminder for {{clinic_name}}. " +
      "Confirm the patient upcoming visit or help them reschedule. " +
      "Keep responses to one or two sentences.",
    greeting: "Hi {{patient_name}}, this is a reminder from {{clinic_name}} about your upcoming appointment.",
    language: "en",
    models: {
      stt: "slng/deepgram/nova:3-en",
      llm: "groq/moonshotai/kimi-k2-instruct-0905",
      tts: "slng/deepgram/aura:2-en",
      tts_voice: "aura-2-thalia-en",
    },
    template_defaults: {
      clinic_name: "Downtown Health Clinic",
      patient_name: "there",
    },
    livekit_deployment: "default-eu",
    slng_api_key: "YOUR_API_KEY",
  }),
});

const agent = await resp.json();
console.log(agent.id);

Test with a web session

Web sessions let you talk to your agent from a browser — no phone number or SIP trunk required. The response includes LiveKit credentials you can use with any LiveKit client SDK.
const resp = await fetch(
  `https://api.slng.ai/v1/agents/${agent.id}/web-sessions`,
  {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      arguments: { patient_name: "Maria", clinic_name: "Greenfield Family Medicine" },
    }),
  },
);

const session = await resp.json();
// session.livekit_url   — WebSocket URL to connect to
// session.livekit_token — access token for the room
// session.room_name     — LiveKit room name
// session.call_id       — use this to look up the call later
// session.max_session_seconds — how long the session stays open
Both fields are optional. arguments overrides template_defaults on the agent, and participant_name sets a display name in the LiveKit room.

Update an agent

PATCH updates only the fields you send. Use PUT if you want to replace the entire configuration.
const resp = await fetch(
  `https://api.slng.ai/v1/agents/${agent.id}`,
  {
    method: "PATCH",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      greeting: "Hello {{patient_name}}, thanks for picking up.",
      models: {
        stt: "slng/deepgram/nova:3-en",
        llm: "groq/moonshotai/kimi-k2-instruct-0905",
        tts: "slng/deepgram/aura:2-en",
        tts_voice: "aura-2-thalia-en",
        llm_kwargs: { temperature: 0.3 },
      },
    }),
  },
);

const updated = await resp.json();

List and inspect agents

// List all agents
const agents = await fetch("https://api.slng.ai/v1/agents", {
  headers: { Authorization: "Bearer YOUR_API_KEY" },
}).then((r) => r.json());

for (const a of agents) {
  console.log(`${a.name} (${a.id})`);
}

// Get a single agent and check its template variables
const agent = await fetch(`https://api.slng.ai/v1/agents/${agents[0].id}`, {
  headers: { Authorization: "Bearer YOUR_API_KEY" },
}).then((r) => r.json());

console.log(agent.template_variables);
// { clinic_name: { required: true, default: "Downtown Health Clinic" }, ... }

Delete an agent

Returns 204 No Content on success.
await fetch(`https://api.slng.ai/v1/agents/${agent.id}`, {
  method: "DELETE",
  headers: { Authorization: "Bearer YOUR_API_KEY" },
});