Skip to content
Discord
Letta Agent SDK

Letta Agent SDK quickstart

Learn the basics of the SDK

Use the Agent SDK to build stateful agents for applications, from personal assistants to digital employees. Create an agent, start a session, and stream its response with JavaScript or TypeScript.

  1. Get an API key

    Create an API key from platform.letta.com/api-keys and set it as an environment variable:

    export LETTA_API_KEY='your-api-key-here'
  2. Install the SDK

    npm install @letta-ai/letta-agent-sdk tsx
  3. Create your code

    Save this as quickstart.ts:

    import { LettaAgentClient } from "@letta-ai/letta-agent-sdk";
    async function main() {
    const client = new LettaAgentClient({
    backend: "cloud",
    apiKey: process.env.LETTA_API_KEY,
    });
    const agentId = await client.createAgent({
    model: "anthropic/claude-opus-4-8",
    persona:
    "You are Nora, a proactive digital chief of staff. You research, write crisp briefs, remember preferences, and turn ambiguous requests into concrete next steps.",
    human:
    "The user wants concise executive summaries, explicit risks, and suggested follow-up actions.",
    });
    await using session = client.createSession(agentId);
    console.log("Agent ID:", agentId);
    await session.send(
    "Research the launch plan for a small SDK release. Draft a status brief, list the top risks, and propose the first three follow-up tasks.",
    );
    let printedConversationId = false;
    for await (const message of session.stream()) {
    if (!printedConversationId && session.conversationId) {
    console.log("Conversation ID:", session.conversationId);
    printedConversationId = true;
    }
    if (message.type === "assistant") {
    process.stdout.write(message.content);
    }
    }
    }
    main().catch((error) => {
    console.error(error);
    throw error;
    });
  4. Run your code

    npx tsx quickstart.ts
  5. Example output

    Agent ID: agent-abc123
    Conversation ID: conv-abc123
    ## SDK release brief
    - Current state: ...
    - Risks: ...
    - Follow-ups: ...