anthropic

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 9 Imported by: 0

README

OmniLLM Provider for Anthropic

Go CI Go Lint Go SAST Go Report Card Docs Visualization License

Thick provider for OmniLLM using the official anthropic-sdk-go SDK.

Installation

go get github.com/plexusone/omnillm-anthropic

Quick Start

import (
    omnillm "github.com/plexusone/omnillm-core"
    _ "github.com/plexusone/omnillm-anthropic" // Auto-registers thick provider
)

client, _ := omnillm.NewClient(omnillm.ClientConfig{
    Provider: omnillm.ProviderNameAnthropic,
    APIKey:   os.Getenv("ANTHROPIC_API_KEY"),
})

Feature Support

Feature Supported
Chat Completion Yes
Streaming Yes
Tool Calling Yes
System Messages Yes
JSON Mode No

Configuration

Field Required Description
APIKey Yes Anthropic API key
BaseURL No Custom endpoint

Documentation

See OmniLLM Core for full API documentation.

License

MIT

Documentation

Overview

Package anthropic provides an OmniLLM adapter for Anthropic's Claude API using the official anthropic-sdk-go.

This package implements the core.Provider interface from omnillm-core, wrapping the official Anthropic Go SDK (github.com/anthropics/anthropic-sdk-go).

Features

The adapter supports all major Anthropic features:

  • Chat completions (Claude 3 Opus, Sonnet, Haiku, etc.)
  • Streaming responses
  • Tool/function calling
  • Vision (image inputs)
  • System prompts

Basic Usage

import (
    core "github.com/plexusone/omnillm-core"
    "github.com/plexusone/omnillm-anthropic"
)

func main() {
    provider, err := anthropic.New(anthropic.Config{
        APIKey: os.Getenv("ANTHROPIC_API_KEY"),
    })
    if err != nil {
        log.Fatal(err)
    }
    defer provider.Close()

    resp, err := provider.CreateChatCompletion(ctx, &core.ChatCompletionRequest{
        Model: "claude-3-opus-20240229",
        Messages: []core.Message{
            {Role: core.RoleUser, Content: "Hello!"},
        },
    })
}

Configuration

The Config struct supports:

  • APIKey: Your Anthropic API key (required)
  • BaseURL: Custom API endpoint (optional)

Streaming

stream, err := provider.CreateChatCompletionStream(ctx, &core.ChatCompletionRequest{
    Model: "claude-3-sonnet-20240229",
    Messages: []core.Message{
        {Role: core.RoleUser, Content: "Tell me a story"},
    },
})
if err != nil {
    log.Fatal(err)
}
defer stream.Close()

for {
    chunk, err := stream.Recv()
    if err == io.EOF {
        break
    }
    if err != nil {
        log.Fatal(err)
    }
    // Process chunk
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIKey is the Anthropic API key (required).
	APIKey string

	// BaseURL is an optional custom API endpoint.
	BaseURL string
}

Config holds configuration for the Anthropic provider.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements core.Provider using the official Anthropic SDK.

func New

func New(cfg Config) (*Provider, error)

New creates a new Anthropic provider with the given configuration.

func (*Provider) Capabilities

func (p *Provider) Capabilities() core.Capabilities

Capabilities returns the provider's supported features.

func (*Provider) Close

func (p *Provider) Close() error

Close releases resources held by the provider.

func (*Provider) CreateChatCompletion

func (p *Provider) CreateChatCompletion(ctx context.Context, req *core.ChatCompletionRequest) (*core.ChatCompletionResponse, error)

CreateChatCompletion sends a chat completion request and returns the response.

func (*Provider) CreateChatCompletionStream

func (p *Provider) CreateChatCompletionStream(ctx context.Context, req *core.ChatCompletionRequest) (core.ChatCompletionStream, error)

CreateChatCompletionStream creates a streaming chat completion.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider identifier.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL