anthropic4s
GitHub

Reference Messages

messages.create

Sends a request and waits for the whole reply.

Reference#

create(request, options?)#

core · AnthropicClient.scala
def create(request: MessageRequest, options: RequestOptions): F[Message]
def create(request: MessageRequest): F[Message]

Parameters

Returns

The model's Message. Failures are raised in F as AnthropicError.

Caveats

createRaw(request, options)#

core · AnthropicClient.scala
def createRaw(request: MessageRequest, options: RequestOptions): F[ApiResponse[Message]]

The same call, returning the reply inside an ApiResponse with the status, the headers (rate limits, for example) and the request id.

Usage#

A single reply#

README.md
import anthropic4s._
import cats.effect.{IO, IOApp}

object Hello extends IOApp.Simple {
  def run: IO[Unit] =
    Anthropic4s.fromEnv[IO].use { client =>            // reads ANTHROPIC_API_KEY
      val request = MessageRequest(Model.ClaudeOpus5_5, maxTokens = 16000, MessageParam.user("Why do cats purr?"))
      client.messages.create(request).flatMap(reply => IO.println(reply.text))
    }
}

More in the Quick start.

Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.