Anthropic
Connect to Anthropic with an API key, choose a Claude model, and use it with the usual nimgent generation APIs.
Make a request
Section titled “Make a request”import std/osimport nimgentimport nimgent/providers/anthropic
let model = anthropic(getEnv("ANTHROPIC_API_KEY")).model("claude-sonnet-4-6")echo generateText(model, prompt = "Say hello in one sentence.").textSet ANTHROPIC_API_KEY before you run the program.
Enable extended thinking
Section titled “Enable extended thinking”Use AnthropicOptions when you want to enable Anthropic thinking with a budget.
import std/options
let response = generateText( model, prompt = "Solve this carefully.", providerOptions = ProviderOptions( anthropic: AnthropicOptions( thinking: some(EnabledThinking), budgetTokens: some(1024))))EnabledThinking requires budgetTokens, and the minimum budget is 1024. Use AdaptiveThinking when you want Anthropic to choose the thinking budget.
Next steps
Section titled “Next steps”See Settings for portable controls, or Structured output for typed results.