claude: Servant bindings to Anthropic's Claude API

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

This package provides comprehensive and type-safe bindings to Anthropic's Claude API, providing both a Servant interface and non-Servant interface for convenience.

Read the README below for a fully worked usage example.

Otherwise, browse the Claude.V1 module, which is the intended package entrypoint.


[Skip to Readme]

Properties

Versions 1.0.0, 1.0.0, 1.0.1
Change log CHANGELOG.md
Dependencies aeson (>=2.0 && <2.3), base (>=4.15.0.0 && <5), base64-bytestring (>=1.0 && <1.3), bytestring (>=0.10 && <0.13), claude, containers (>=0.6 && <0.8), filepath (>=1.4 && <1.6), http-api-data (>=0.4 && <0.7), http-client (>=0.7 && <0.8), http-client-tls (>=0.3 && <0.4), http-types (>=0.12 && <0.13), servant (>=0.19 && <0.21), servant-client (>=0.19 && <0.21), text (>=1.2 && <2.2), time (>=1.9 && <1.15), vector (>=0.12 && <0.14) [details]
License BSD-3-Clause
Copyright 2025
Author Paul-Arthur Asselin
Maintainer pa@mercury.com
Category AI, API, LLM
Source repo head: git clone https://github.com/MercuryTechnologies/claude
Uploaded by asselinpaul at 2025-12-17T04:14:41Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for claude-1.0.0

[back to package description]

claude

Haskell bindings to Anthropic's Claude API using servant.

Example usage

{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns        #-}
{-# LANGUAGE OverloadedLists       #-}
{-# LANGUAGE OverloadedStrings     #-}

import Claude.V1
import Claude.V1.Messages
import Data.Foldable (traverse_)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
import qualified System.Environment as Environment

main :: IO ()
main = do
    key <- Environment.getEnv "ANTHROPIC_KEY"
    clientEnv <- getClientEnv "https://api.anthropic.com"
    let Methods{ createMessage } = makeMethods clientEnv (Text.pack key) (Just "2023-06-01")

    MessageResponse{ content } <- createMessage _CreateMessage
        { model = "claude-sonnet-4-5-20250929"
        , messages = [ Message{ role = User, content = [ textContent "Hello!" ] } ]
        , max_tokens = 1024
        }

    let display (ContentBlock_Text{ text }) = Text.IO.putStrLn text
        display _ = pure ()
    traverse_ display content

Setup

  1. Ensure you have Nix with flakes enabled
  2. Copy the sample environment file:
cp .envrc.sample .envrc
  1. Edit .envrc with your Anthropic API key
  2. Run direnv allow

Manual Setup

cabal build

Environment Variables

Set your Anthropic API key as an environment variable:

# Option 1: Set directly in your shell
export ANTHROPIC_KEY="your-anthropic-api-key"

# Option 2: Using .envrc with direnv (recommended)
cp .envrc.sample .envrc
# Edit .envrc to add your API key
direnv allow

The API key is needed for running the test suite and example programs.

Testing

Run the test suite:

cabal test

Running the Examples

cabal run claude-example
cabal run claude-stream-example
cabal run claude-tool-example
cabal run claude-vision-example
cabal run claude-tool-search-example
cabal run claude-programmatic-tool-calling-example

Advanced Examples

The claude-tool-search-example and claude-programmatic-tool-calling-example demonstrate beta features that require the advanced-tool-use-2025-11-20 beta header:

To enable these features, use makeMethodsWith with the beta header:

let options = defaultClientOptions
        { apiKey = key
        , anthropicBeta = Just "advanced-tool-use-2025-11-20"
        }
let Methods{ createMessage } = makeMethodsWith clientEnv options