Prerequisites

  1. Elixir 1.19+ and OTP 26+
  2. Amp CLI installed and authenticated

Install the Amp CLI

curl -fsSL https://ampcode.com/install.sh | bash

Or via npm:

npm install -g @sourcegraph/amp

Authenticate

amp login

Or pass an API key explicitly through Options.env.

amp login and AMP_API_KEY are standalone direct-use authentication. In governed execution, Amp credentials, command, cwd, env, target, and redaction metadata must come from the supplied governed authority.

Add to Your Project

# mix.exs
def deps do
  [
    {:amp_sdk, "~> 0.6.0"}
  ]
end
mix deps.get

Your First Query

The simplest way to use the SDK is AmpSdk.run/2, which sends a prompt and returns the final result:

{:ok, result} = AmpSdk.run("What files are in this directory?")
IO.puts(result)

Streaming Responses

For real-time output, use AmpSdk.execute/2 which returns a lazy Stream:

alias AmpSdk.Types.{AssistantMessage, ResultMessage, SystemMessage, TextContent}

"Explain the architecture of this project"
|> AmpSdk.execute()
|> Enum.each(fn
  %SystemMessage{tools: tools} ->
    IO.puts("Session started with #{length(tools)} tools")

  %AssistantMessage{message: %{content: content}} ->
    for %TextContent{text: text} <- content, do: IO.write(text)

  %ResultMessage{duration_ms: ms} ->
    IO.puts("\nDone in #{ms}ms")

  _ -> :ok
end)

Configuration

All options are passed via AmpSdk.Types.Options:

alias AmpSdk.Types.Options

AmpSdk.run("Review this code", %Options{
  mode: "smart",
  visibility: "private",
  dangerously_allow_all: true
})

See the Configuration guide for all available options.

Next Steps