LangWatch supports tracing Anthropic Claude API calls using the same otelopenai middleware used for OpenAI. Configure the client to point to Anthropic’s API endpoint.
Installation
go get github.com/langwatch/langwatch/sdk-go github.com/openai/openai-go
Usage
The LangWatch API key is configured by default via the LANGWATCH_API_KEY environment variable.
Configure the OpenAI client with Anthropic’s base URL and API key:
package main
import (
"context"
"log"
"os"
otelopenai "github.com/langwatch/langwatch/sdk-go/instrumentation/openai"
"github.com/openai/openai-go"
oaioption "github.com/openai/openai-go/option"
)
func main() {
ctx := context.Background()
client := openai.NewClient(
oaioption.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")),
oaioption.WithBaseURL(os.Getenv("ANTHROPIC_BASE_URL")),
oaioption.WithMiddleware(otelopenai.Middleware("<project_name>",
otelopenai.WithCaptureInput(),
otelopenai.WithCaptureOutput(),
)),
)
response, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
Model: "claude-4-5-sonnet",
Messages: []openai.ChatCompletionMessageParamUnion{
openai.SystemMessage("You are a helpful assistant."),
openai.UserMessage("Hello, Anthropic!"),
},
})
if err != nil {
log.Fatalf("Chat completion failed: %v", err)
}
log.Printf("Chat completion: %s", response.Choices[0].Message.Content)
}
Set ANTHROPIC_BASE_URL to https://api.anthropic.com/v1 and use your Anthropic API key.