---
title: "Quickstart"
description: "Create an API key, install the SDK, and run Fantail or Moa from your host language."
seo:
  title: "Code Agent SDK Quickstart"
  description: "Create an Autohand API key, install the Code Agent SDK, and run Fantail or Moa from TypeScript, Python, Go, Java, Swift, Rust, Ruby, C#/.NET, or C++."
---

The examples below use the current CLI-backed SDK flow where each wrapper starts or controls the Autohand runtime, streams events, and returns a final run result. Requests to Autohand-hosted models authenticate with `AUTOHAND_API_KEY`.

## 1\. Choose your language [#choose-language]

Pick the SDK you want to start with. The install command and first prompt example update to match.

## 2\. Create an API key [#api-key]

Open [API Keys in the Autohand Console](https://console.autohand.ai/api-keys) and select **Create API Key**. Use a recognizable name for the machine, service, or environment that will run the SDK.

<img src="/media/agent-sdk/console-api-keys.jpg" alt="Autohand Console API Keys page with the Create API Key action and one-time secret warning" />

Open API Keys and select **Create API Key**.

<img src="/media/agent-sdk/console-create-api-key.jpg" alt="Autohand Console dialog for naming and creating an API key" />

Name the client or environment, then create and copy the key.

1. Enter a descriptive name such as `local-sdk` or `production-reviewer`.
2. Select **Create Key**.
3. Copy the raw key immediately. The Console will not show the complete value again.

**Keep the key server-side.** Do not place it in browser code, commit it to a repository, or include it in screenshots and logs. Revoke the key in the Console before rotating the client that uses it.

## 3\. Check prerequisites [#prerequisites]

**TypeScript**

- Node.js or Bun.
- The Autohand Code CLI config in `~/.autohand/config.json`.
- A repo you want the agent to work in.

**Python**

- Python 3.10 or newer.
- The Autohand Code CLI config in `~/.autohand/config.json`.
- A repo you want the agent to work in.

**Go**

- Go 1.21 or newer.
- The Autohand Code CLI config in `~/.autohand/config.json`.
- A repo you want the agent to work in.

**Java**

- Java 21 or newer.
- Maven 3.9 or newer.
- The Autohand Code CLI config in `~/.autohand/config.json`.

**Swift**

- Swift 6.0 or newer.
- A provider key such as OpenAI or OpenRouter for the native Swift SDK.
- A repo you want the agent to work in.

**Rust**

- Rust 1.80 or newer.
- Tokio runtime.
- Autohand Code CLI installed, authenticated, and configured.

**Ruby**

- Ruby 3.2 or newer.
- Bundler.
- Autohand Code CLI installed with `bundle exec autohand-sdk install-cli` or supplied with `cli_path:`.

**C#/.NET**

- .NET 8 or newer.
- Autohand Code CLI installed, authenticated, and configured.
- Optional `AUTOHAND_CLI_PATH` for local CLI builds.

**C++**

- C++20 compiler.
- CMake 3.22 or newer.
- Autohand Code CLI installed, authenticated, and configured.

## 4\. Install the SDK [#install]

**TypeScript**

```package-install
npm i @autohandai/agent-sdk
```

The TypeScript SDK is published on npm as [`@autohandai/agent-sdk`](https://www.npmjs.com/package/@autohandai/agent-sdk).

**Python**

```bash title="uv"
uv add autohand-sdk
```

```bash title="pip"
pip install autohand-sdk
```

**Go**

```bash
go get github.com/autohandai/agent-sdk-go
```

**Java**

```xml
<dependency>
    <groupId>ai.autohand</groupId>
    <artifactId>agent-sdk-java</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
```

**Swift**

```swift
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "MyAgentApp",
    platforms: [.macOS(.v14)],
    dependencies: [
        .package(path: "../AgentSDK")
    ],
    targets: [
        .executableTarget(
            name: "MyAgentApp",
            dependencies: ["AgentSDK"]
        )
    ]
)
```

**Rust**

```toml
[dependencies]
autohand-sdk = { git = "https://github.com/autohandai/code-agent-sdk-rust" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

**Ruby**

```ruby title="Gemfile"
gem "autohand_sdk", git: "https://github.com/autohandai/code-agent-sdk-ruby"
```

```bash title="CLI"
bundle install
bundle exec autohand-sdk install-cli
bundle exec autohand-sdk doctor
```

**C#/.NET**

```bash title=".NET"
dotnet add package Autohand.CodeAgentSdk
```

```bash title="Source"
# Until the NuGet package is published, reference the project or repository directly from your solution.
```

**C++**

```cmake
include(FetchContent)

FetchContent_Declare(
  autohand_sdk
  GIT_REPOSITORY https://github.com/autohandai/code-agent-sdk-cpp.git
  GIT_TAG main
)

FetchContent_MakeAvailable(autohand_sdk)
target_link_libraries(my_app PRIVATE autohand::sdk)
```

## 5\. Configure authentication [#configure]

Export the key in the shell or secret manager that launches your application. The CLI-backed SDKs read `AUTOHAND_API_KEY` from the server environment.

```bash title="macOS / Linux"
export AUTOHAND_API_KEY="your-api-key"
```

```powershell title="PowerShell"
$env:AUTOHAND_API_KEY = "your-api-key"
```

Use `fantail` for focused, latency-sensitive coding loops and `moa` for deeper repository-wide work. The examples on the [documentation home page](/) show both model identifiers for every supported language.

If you bring your own provider instead, configure that provider in `~/.autohand/config.json` or through the provider-native SDK adapter. Keep every provider credential server-side.

## 6\. Run your first prompt [#first-prompt]

**TypeScript**

```ts
import { AutohandSDK } from '@autohandai/agent-sdk';

async function main() {
  const sdk = new AutohandSDK({ cwd: '.', debug: true });
  await sdk.start();

  for await (const event of sdk.streamPrompt({
    message: 'List the main source files and tell me what looks risky.'
  })) {
    if (event.type === 'message_update') {
      process.stdout.write(event.delta);
    }
  }

  await sdk.stop();
}

main();
```

**Python**

```python
import asyncio
from autohand_sdk import AutohandSDK

async def main():
    async with AutohandSDK(cwd='.') as sdk:
        async for event in sdk.stream_prompt('List the main source files and tell me what looks risky.'):
            if event['type'] == 'message_update':
                print(event.get('delta', ''), end='')

asyncio.run(main())
```

**Go**

```go
package main

import (
    "context"
    "fmt"
    "log"

    autohand "github.com/autohandai/agent-sdk-go"
)

func main() {
    ctx := context.Background()
    sdk := autohand.NewSDK(&autohand.Config{CWD: "."})

    if err := sdk.Start(ctx); err != nil {
        log.Fatal(err)
    }
    defer sdk.Close()

    events, err := sdk.StreamPrompt(ctx, &autohand.PromptParams{
        Message: "List the main source files and tell me what looks risky.",
    })
    if err != nil {
        log.Fatal(err)
    }

    for event := range events {
        if e, ok := event.(autohand.MessageUpdateEvent); ok {
            fmt.Print(e.Delta)
        }
    }
}
```

**Java**

```java
import ai.autohand.sdk.sdk.Agent;
import ai.autohand.sdk.sdk.AgentOptions;
import ai.autohand.sdk.types.Events;

public final class Main {
    public static void main(String[] args) throws Exception {
        Agent agent = Agent.create(AgentOptions.builder()
            .cwd(".")
            .instructions("Be concise and specific.")
            .build());

        var run = agent.send("List the main source files and tell me what looks risky.");
        run.stream(event -> {
            if (event instanceof Events.MessageUpdateEvent mue) {
                System.out.print(mue.delta());
            }
        });
        agent.close();
    }
}
```

**Swift**

```swift
import AgentSDK
import Foundation

let provider = OpenAIProvider(apiKey: "sk-...")
let agent = Agent(
    name: "Reviewer",
    instructions: "Be concise and specific.",
    tools: [.readFile, .bash],
    model: ModelID("gpt-4o"),
    provider: provider
)

let stream = Runner.runStream(
    agent: agent,
    prompt: "List the main source files and tell me what looks risky."
)

for try await event in stream {
    if event.type == .content, let data = event.data {
        print(data, terminator: "")
    }
}
```

**Rust**

```rust
use autohand_sdk::{Agent, Config, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut agent = Agent::create(
        Config::from_env()
            .with_cwd(".")
            .with_instructions("Review code with senior Rust judgement."),
    )
    .await?;

    let result = agent
        .run("List the main source files and tell me what looks risky.")
        .await?;

    println!("{}", result.text);
    agent.close().await?;
    Ok(())
}
```

**Ruby**

```ruby
require "autohand_sdk"

AutohandSDK::Agent.open(
  cwd: ".",
  instructions: "Review code with staff-level Ruby judgement.",
  permission_mode: "interactive"
) do |agent|
  run = agent.send("List the main source files and tell me what looks risky.")

  run.stream.each do |event|
    print event["delta"] if event["type"] == "message_update"
  end

  result = run.wait
  puts result.fetch(:text)
end
```

**C#/.NET**

```csharp
using Autohand.CodeAgentSdk;

await using var agent = await Agent.CreateAsync(new AgentOptions
{
    WorkingDirectory = ".",
    Instructions = "Review code with staff-level C# judgement.",
});

var run = agent.Send("List the main source files and tell me what looks risky.");

await foreach (var item in run.StreamAsync())
{
    if (item is MessageUpdateEvent message)
    {
        Console.Write(message.Delta);
    }
}

var result = await run.WaitAsync();
Console.WriteLine(result.Text);
```

**C++**

```cpp
#include <autohand/sdk.hpp>
#include <iostream>

int main() {
  autohand::Agent agent(
      autohand::Config::from_environment()
          .with_cwd(".")
          .with_instructions("Review code with senior C++ judgement."));

  auto run = agent.send("List the main source files and tell me what looks risky.");

  run.stream([](const autohand::SdkEvent& event) {
    if (event.type == "message_update") {
      std::cout << event.text_delta();
    }
  });

  auto result = run.wait();
  std::cout << result.text << "\n";
  agent.close();
}
```

### Run the example

**TypeScript**

```bash title="Bun"
bun main.ts
```

```bash title="Node.js"
npx tsx main.ts
```

**Python**

```bash
python main.py
```

**Go**

```bash
go run .
```

**Java**

```bash
mvn compile exec:java -Dexec.mainClass=Main
```

**Swift**

```bash
swift run
```

**Rust**

```bash
cargo run
```

**Ruby**

```bash
bundle exec ruby main.rb
```

**C#/.NET**

```bash
dotnet run
```

**C++**

```bash
cmake -S . -B build
cmake --build build
./build/my_app
```

### You’re connected when the response streams from your repository [#sdk-connected-heading]

The exact answer depends on the project. A successful first run should start without an authentication error, stream text into the terminal, and refer to files in the working directory.

```text
Analyzing the current repository…
src/main.ts
src/runtime/session.ts

The highest-risk change is…
```

- The runtime starts without an API-key or CLI-path error.
- Response events arrive before the final result completes.
- The answer names files or risks from the current repository.

[Check or rotate the API key](https://console.autohand.ai/api-keys) [Troubleshoot authentication](/guides/troubleshooting) [Troubleshoot runtime startup](/agent-sdk/concepts/cli-runtime-control)

<AcademyCta course="building-with-the-code-agent-sdk" title="Building with the Code Agent SDK" blurb="Start an agent from TypeScript or Python, stream its events, and answer its approval requests." />

## 7\. Next moves [#next]

- Go to [Handle approvals and user input](/agent-sdk/io/approvals) when you need human review in the loop.
- Open the language guides: [TypeScript](/agent-sdk/typescript), [Python](/agent-sdk/python), [Go](/agent-sdk/go), [Java](/agent-sdk/java), [Swift](/agent-sdk/swift), [Rust](/agent-sdk/rust), [Ruby](/agent-sdk/ruby), [C#/.NET](/agent-sdk/csharp), [C++](/agent-sdk/cpp).
- Use the [streaming docs](/agent-sdk/io/streaming) next if you are building a terminal UI, dashboard, or chat surface around the SDK.
