https://github.com/coder/aisdk-go
A Go implementation of Vercel's AI SDK Data Stream Protocol.
https://github.com/coder/aisdk-go
ai go sdk vercel
Last synced: 7 months ago
JSON representation
A Go implementation of Vercel's AI SDK Data Stream Protocol.
- Host: GitHub
- URL: https://github.com/coder/aisdk-go
- Owner: coder
- License: mit
- Created: 2025-04-06T04:44:40.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-06-06T15:24:53.000Z (7 months ago)
- Last Synced: 2025-06-13T14:06:39.903Z (7 months ago)
- Topics: ai, go, sdk, vercel
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# aisdk-go
[](https://github.com/coder/aisdk-go/releases)
[](https://godoc.org/github.com/coder/aisdk-go)
[](https://github.com/coder/aisdk-go/actions)
> [!WARNING]
> This library is super new and may change a lot.
A Go implementation of Vercel's AI SDK [Data Stream Protocol](https://sdk.vercel.ai/docs/ai-sdk-ui/stream-protocol#data-stream-example).
- Supports OpenAI, Google, and Anthropic (with Bedrock support)
- Examples for integrating `useChat`
- Chain tool usage in Go, just like `maxSteps`
```ts
// frontend.tsx
const { messages } = useChat({
// Points to our Go backend!
api: "/api/chat",
})
```
```go
// backend.go
// Accept the POST request...
var req *aisdk.Chat
messages, err := aisdk.MessagesToOpenAI(req.Messages)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Convert the http.ResponseWriter to a Data Stream.
dataStream := aisdk.NewDataStream(w)
stream := openaiClient.Chat.Completions.NewStreaming(...)
aisdk.PipeOpenAIToDataStream(stream, dataStream)
```
## Development
Run tests with `go test`. Start the `useChat` demo with:
```bash
# any or all of these can be set
export OPENAI_API_KEY=
export ANTHROPIC_API_KEY=
export GOOGLE_API_KEY=
cd demo
bun i
bun dev
```