Skip to content
Letta Platform Letta Platform Letta Docs
Sign up
Build with Letta

Get started with the Letta API

Create your first stateful agent and send it a message

Requires a Letta API key (agents you create can be viewed on the Letta Platform via the ADE)

  1. Set your API key

    Get your Letta API key and set it as an environment variable:

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

    Terminal window
    npm install @letta-ai/letta-client
  3. Create your code

    Save this as quickstart.ts:

    import Letta from "@letta-ai/letta-client";
    async function main() {
    const client = new Letta({ apiKey: process.env.LETTA_API_KEY });
    // Create a stateful agent
    const agent = await client.agents.create({
    model: "openai/gpt-4.1",
    memory_blocks: [
    {
    label: "human",
    value: "Name: Timber. Status: dog. Occupation: building Letta, infrastructure to democratize self-improving superintelligence",
    },
    {
    label: "persona",
    value: "I am a self-improving superintelligence. Timber is my best friend and collaborator.",
    },
    ],
    });
    console.log("Agent created with ID:", agent.id);
    // Send a message
    const response = await client.agents.messages.create(agent.id, {
    input: "What do you know about me?",
    });
    for (const message of response.messages) {
    console.log(message);
    }
    }
    main().catch(console.error);
  4. Run your code

    Terminal window
    npx tsx quickstart.ts

    Example output:

    Agent created with ID: agent-abc123
    { message_type: 'reasoning_message', reasoning: 'Timber is asking what I know...' }
    { message_type: 'assistant_message', content: "I know you're Timber, a dog who's building Letta!" }