{"id":26766397,"url":"https://github.com/cubeofcube-dev/go-anthropic","last_synced_at":"2025-03-28T20:20:01.606Z","repository":{"id":228960549,"uuid":"775367689","full_name":"cubeofcube-dev/go-anthropic","owner":"cubeofcube-dev","description":"用 Go 实现的 Anthropic SDK，支持 Claude 2.1、Claude 3、Claude 3.5（文字和图片）等模型。Anthropic SDK implemented in Go, supporting models such as Claude 2.1, Claude 3, and Claude 3.5 (supports sending images), etc.","archived":false,"fork":false,"pushed_at":"2024-06-21T06:43:02.000Z","size":60,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-22T08:31:26.636Z","etag":null,"topics":["anthropic","claude-2","claude-3","claude-3-5","claude-3-haiku","claude-3-opus","claude-3-sonnet","go","sdk"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/cubeofcube-dev/go-anthropic","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/cubeofcube-dev.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":"2024-03-21T09:02:38.000Z","updated_at":"2024-06-21T03:27:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"484f18cb-4a8a-422d-82c3-e8a49d838da4","html_url":"https://github.com/cubeofcube-dev/go-anthropic","commit_stats":null,"previous_names":["cubeofcube-dev/go-anthropic"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubeofcube-dev%2Fgo-anthropic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubeofcube-dev%2Fgo-anthropic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubeofcube-dev%2Fgo-anthropic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubeofcube-dev%2Fgo-anthropic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cubeofcube-dev","download_url":"https://codeload.github.com/cubeofcube-dev/go-anthropic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246093165,"owners_count":20722403,"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","claude-2","claude-3","claude-3-5","claude-3-haiku","claude-3-opus","claude-3-sonnet","go","sdk"],"created_at":"2025-03-28T20:20:01.096Z","updated_at":"2025-03-28T20:20:01.589Z","avatar_url":"https://github.com/cubeofcube-dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Anthropic\n\n**English** | [简体中文](./README.zh-CN.md)\n\nAnthropic SDK implemented in Go, supporting models such as Claude 2.1, Claude 3, and Claude 3.5 (supports sending images), etc.\n\n## Installation\n\n```\ngo get github.com/cubeofcube-dev/go-anthropic\n```\n\n## Usage\n\nBy default, it will fetch `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL` from the environment variables.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/cubeofcube-dev/go-anthropic\"\n)\n\nfunc main() {\n\tcli := anthropic.NewClient()\n\t// cli := anthropic.NewClient(anthropic.ClientOptions{\n\t// \tApiKey:  os.Getenv(\"ANTHROPIC_API_KEY\"),\n\t// \tBaseUrl: anthropic.DEFAULT_ANTHROPIC_BASE_URL,\n\t// })\n\n\tresp, err := cli.CreateMessages(anthropic.MessagesRequest{\n\t\t// `MODEL_CLAUDE_35_SONNET`、`MODEL_CLAUDE_3_SONNET`、`MODEL_CLAUDE_3_OPUS`、`MODEL_CLAUDE_2_1`\n\t\tModel: anthropic.MODEL_CLAUDE_3_HAIKU\n\t\tMessages: []anthropic.Message{{\n\t\t\tRole: \"user\",\n\t\t\tContent: []anthropic.MessageContent{\n\t\t\t\t\u0026anthropic.MessageContentText{\n\t\t\t\t\tType: \"text\",\n\t\t\t\t\tText: \"Hello Claude!\",\n\t\t\t\t},\n\t\t\t}},\n\t\t},\n\t\tMaxTokens: 1024,\n\t})\n\tif err != nil {\n\t\tfmt.Println(err.Error())\n\t\treturn\n\t}\n\tfmt.Println(resp.Content[0].Text)\n}\n```\n\n## Streaming Responses\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/cubeofcube-dev/go-anthropic\"\n)\n\nfunc main() {\n\tcli := anthropic.NewClient()\n\t// cli := anthropic.NewClient(anthropic.ClientOptions{\n\t// \tApiKey:  os.Getenv(\"ANTHROPIC_API_KEY\"),\n\t// \tBaseUrl: anthropic.DEFAULT_ANTHROPIC_BASE_URL,\n\t// })\n\n\tstream, _ := cli.CreateMessagesStream(anthropic.MessagesRequest{\n\t\t// `MODEL_CLAUDE_35_SONNET`、`MODEL_CLAUDE_3_SONNET`、`MODEL_CLAUDE_3_OPUS`、`MODEL_CLAUDE_2_1`\n\t\tModel: anthropic.MODEL_CLAUDE_3_HAIKU\n\t\tMessages: []anthropic.Message{{\n\t\t\tRole: \"user\",\n\t\t\tContent: []anthropic.MessageContent{\n\t\t\t\t\u0026anthropic.MessageContentText{\n\t\t\t\t\tType: \"text\",\n\t\t\t\t\tText: \"Hello Claude!\",\n\t\t\t\t},\n\t\t\t}},\n\t\t},\n\t\tMaxTokens: 1024,\n\t\tStream:    true,\n\t})\n\tdefer stream.Close()\n\tfor {\n\t\tresp, err := stream.Recv()\n\t\tif err != nil {\n\t\t\tfmt.Println(err.Error())\n\t\t\treturn\n\t\t}\n\t\tfmt.Println(resp.Delta.Text)\n\t}\n}\n```\n\n## References\n\n- https://docs.anthropic.com/claude/reference/messages_post\n- https://docs.anthropic.com/claude/reference/messages-streaming\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubeofcube-dev%2Fgo-anthropic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcubeofcube-dev%2Fgo-anthropic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubeofcube-dev%2Fgo-anthropic/lists"}