{"id":22084048,"url":"https://github.com/dleviminzi/anthrogo","last_synced_at":"2025-07-24T16:31:15.669Z","repository":{"id":184286107,"uuid":"671581567","full_name":"dleviminzi/anthrogo","owner":"dleviminzi","description":"Anthropic api wrapper for Go","archived":false,"fork":false,"pushed_at":"2024-06-28T21:13:26.000Z","size":43,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-28T22:26:55.117Z","etag":null,"topics":["anthropic","anthropic-claude","anthropic-go","claude","claude-3","claude-3-haiku","claude-3-opus","claude-3-sonnet","claude-api","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dleviminzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-27T16:40:11.000Z","updated_at":"2024-06-28T21:12:06.000Z","dependencies_parsed_at":"2024-03-14T03:24:22.008Z","dependency_job_id":"462ec109-935c-43d1-b442-8cf960bc1068","html_url":"https://github.com/dleviminzi/anthrogo","commit_stats":null,"previous_names":["dleviminzi/go-anthropic","dleviminzi/anthropic-go","dleviminzi/anthrogo"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dleviminzi%2Fanthrogo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dleviminzi%2Fanthrogo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dleviminzi%2Fanthrogo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dleviminzi%2Fanthrogo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dleviminzi","download_url":"https://codeload.github.com/dleviminzi/anthrogo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227457665,"owners_count":17777992,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anthropic","anthropic-claude","anthropic-go","claude","claude-3","claude-3-haiku","claude-3-opus","claude-3-sonnet","claude-api","go"],"created_at":"2024-12-01T00:19:44.379Z","updated_at":"2024-12-01T00:19:46.962Z","avatar_url":"https://github.com/dleviminzi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# anthropic go (anthrogo)\n[![Go Reference](https://pkg.go.dev/badge/github.com/dleviminzi/anthrogo.svg)](https://pkg.go.dev/github.com/dleviminzi/anthrogo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dleviminzi/anthrogo)](https://goreportcard.com/report/github.com/dleviminzi/anthrogo)\n[![codecov](https://codecov.io/gh/dleviminzi/anthrogo/branch/main/graph/badge.svg?token=OP2W7ENYN5)](https://codecov.io/gh/dleviminzi/anthrogo)\n\nThis is a simple client for using Anthropic's api to get claude completions. It is not an official client. Contributions are welcome!\n\n## Installation\n```\ngo get github.com/dleviminzi/anthrogo\n```\n\n## Basic usage \n\n### Message API\n```go\nfunc main() {\n\tc, err := anthrogo.NewClient()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\n\tsystemPrompt := \"you are an expert in all things bananas\"\n\n\t// Read user input for the prompt\n\treader := bufio.NewReader(os.Stdin)\n\tfmt.Print(\"Enter your prompt: \")\n\tuserPrompt, _ := reader.ReadString('\\n')\n\tuserPrompt = strings.TrimSuffix(userPrompt, \"\\n\")\n\n\tresp, err := c.MessageRequest(context.Background(), anthrogo.MessagePayload{\n\t\tModel: anthrogo.ModelClaude3Opus,\n\t\tMessages: []anthrogo.Message{{\n\t\t\tRole: anthrogo.RoleTypeUser,\n\t\t\tContent: []anthrogo.MessageContent{{\n\t\t\t\tType: anthrogo.ContentTypeText,\n\t\t\t\tText: \u0026userPrompt,\n\t\t\t}},\n\t\t}},\n\t\tSystem:    \u0026systemPrompt,\n\t\tMaxTokens: 1000,\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(resp.Content[0].Text)\n}\n```\n\n## Message Streaming\n[message-streaming-example](https://github.com/dleviminzi/anthrogo/assets/51272568/4d7dafa6-4088-4c57-951a-97d7a9898408)\n```go\nfunc main() {\n\tc, err := anthrogo.NewClient()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\t\n\tsystemPrompt := \"you are an expert in all things bananas\"\n\t\n\t// Read user input for the prompt\n\treader := bufio.NewReader(os.Stdin)\n\tfmt.Print(\"Enter your prompt: \")\n\tuserPrompt, _ := reader.ReadString('\\n')\n\tuserPrompt = strings.TrimSuffix(userPrompt, \"\\n\")\n\t\n\tr, _, err := c.MessageStreamRequest(context.Background(), anthrogo.MessagePayload{\n\t\tModel: anthrogo.ModelClaude3Opus,\n\t\tMessages: []anthrogo.Message{{\n\t\t\tRole: anthrogo.RoleTypeUser,\n\t\t\tContent: []anthrogo.MessageContent{{\n\t\t\t\tType: anthrogo.ContentTypeText,\n\t\t\t\tText: \u0026userPrompt,\n\t\t\t}},\n\t\t}},\n\t\tSystem:    \u0026systemPrompt,\n\t\tMaxTokens: 1000,\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\tdefer r.Close()\n\t\n\t// Create an SSEDecoder\n\tdecoder := anthrogo.NewMessageSSEDecoder(r)\n\tfor {\n\t\tmessage, err := decoder.Decode(anthrogo.DecodeOptions{ContentOnly: true})\n\t\tif err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tfmt.Print(err)\n\t\t\tcontinue\n\t\t}\n\t\n\t\tif message.Event == \"message_stop\" {\n\t\t\tbreak\n\t\t}\n\t\n\t\tfmt.Print(message.Data.Content)\n\t}\n}\n```\n\n### Completions (old api)\n```go\nfunc main() {\n\tc, err := anthrogo.NewClient()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Read user input for the prompt\n\treader := bufio.NewReader(os.Stdin)\n\tfmt.Print(\"Enter your prompt: \")\n\tuserPrompt, _ := reader.ReadString('\\n')\n\tuserPrompt = strings.TrimSuffix(userPrompt, \"\\n\")\n\n\t// Create conversation with user input\n\tconversation := anthrogo.NewConversation()\n\tconversation.AddMessage(anthrogo.RoleHuman, userPrompt)\n\n\t// Set up the payload and send completion stream request\n\tresp, err := c.CompletionRequest(context.Background(), anthrogo.CompletionPayload{\n\t\tMaxTokensToSample: 256,\n\t\tModel:             anthrogo.ModelClaude2,\n\t\tPrompt:            conversation.GeneratePrompt(),\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(resp.Completion)\n\n\t// Add claude's response to conversation for further prompting...\n\tconversation.AddMessage(anthrogo.RoleAssistant, resp.Completion)\n}\n```\n\n## Completion Streaming\n[streaming-completion-example (trimmed).webm](https://github.com/dleviminzi/go-anthropic/assets/51272568/14f80831-a53b-47bd-a8e3-67fe4c279df6)\n\u003cdetails\u003e\n\u003csummary\u003eCode\u003c/summary\u003e\t\n\t\n```go\nfunc main() {\n\t// Create a new client\n\t// optionally provide api key otherwise we will look for it in ANTHROPIC_API_KEY variable\n\tc, err := anthrogo.NewClient()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Read user input for the prompt\n\treader := bufio.NewReader(os.Stdin)\n\tfmt.Print(\"Enter your prompt: \")\n\tuserPrompt, _ := reader.ReadString('\\n')\n\tuserPrompt = strings.TrimSuffix(userPrompt, \"\\n\")\n\n\t// Create conversation with user input\n\tconversation := anthrogo.NewConversation()\n\tconversation.AddMessage(anthrogo.RoleHuman, userPrompt)\n\n\t// Set up the payload and send completion stream request\n\tcompleteStreamResp, _ := c.StreamingCompletionRequest(context.Background(), anthrogo.CompletionPayload{\n\t\tMaxTokensToSample: 256,\n\t\tModel:             anthrogo.ModelClaude2,\n\t\tPrompt:            conversation.GeneratePrompt(),\n\t\tCompleteOptions: anthrogo.CompleteOptions{\n\t\t\tStream:      true,\n\t\t\tTemperature: 1,\n\t\t},\n\t})\n\n\t// Ensure that the request is canceled after timeout (default 1 minute)\n\tdefer completeStreamResp.Cancel()\n\n\t// Ensure that the stream response body is closed when the function returns\n\tdefer completeStreamResp.Close()\n\n\t// Continually read from the response until an error or EOF is encountered\n\tfor {\n\t\tevent, err := completeStreamResp.Decode()\n\t\tif err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t} else {\n\t\t\t\tfmt.Println(err)\n\t\t\t\tos.Exit(1)\n\t\t\t}\n\t\t}\n\n\t\tif event != nil {\n\t\t\tfmt.Printf(\"%s\", event.Data.Completion)\n\t\t}\n\t}\n}\n```\n\u003c/details\u003e\n\u003c/details\u003e\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdleviminzi%2Fanthrogo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdleviminzi%2Fanthrogo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdleviminzi%2Fanthrogo/lists"}