Get started with the Claude Messages API
mainTo interact with Claude, instantiate an AnthropicClient and use the Messages.Create method. You must provide MessageCreateParams, which includes the Model name, MaxTokens limit, and a list of Messages containing the conversation history with specific Role assignments (e.g., Role.User).
using System;
using Anthropic;
using Anthropic.Models.Messages;
AnthropicClient client = new();
MessageCreateParams parameters = new()
{
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = "Hello, Claude",
},
],
Model = "claude-opus-4-6",
};
var message = await client.Messages.Create(parameters);
Console.WriteLine(message);