goaisdk

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

go-ai-sdk

An idiomatic Go port of the Vercel AI SDK: a single, provider-agnostic API for generating text, streaming text, generating structured objects, calling tools, computing embeddings, and generating images/speech/transcriptions across 39 providers — OpenAI, Anthropic, Google (Gemini), Groq, xAI, DeepSeek, Together, Fireworks, Cerebras, Perplexity, Moonshot, Qwen, MiniMax, DeepInfra, Hugging Face, Baseten, LM Studio, NVIDIA NIM, Vercel AI Gateway, Mistral, Cohere, Voyage, Mixedbread, Azure OpenAI, Vertex AI, Amazon Bedrock, ElevenLabs, fal, Replicate, Luma, Deepgram, LMNT, Hume, AssemblyAI, Gladia, Rev.ai, Cartesia, Prodia, and Black Forest Labs — with the same concepts and naming as the TypeScript original, expressed in native Go (context.Context, iter.Seq, generics, typed errors) rather than mirrored line-for-line.

Status: v0.2. The public API has reached full parity with the AI SDK 6 core (see the migration guide's AI SDK 6 delta for the feature-by-feature record, and the v6 parity final audit for the closing have-list). It's implemented and tested end-to-end (unit tests plus a shared provider-conformance suite), but it is young: expect rough edges, and expect the API to move before a 1.0. Coming from the TypeScript SDK? Start with Migrating from the Vercel AI SDK.

v0.2.0 breaking change: ai.Telemetry.OnSpanStart gained a leading ctx context.Context parameter, and ai.SpanInfo gained CorrelationID — a one-line signature update for any hand-rolled Telemetry implementation. See CHANGELOG.md.

Install

go get github.com/azrtydxb/go-ai-sdk

Requires Go 1.26+. The OpenTelemetry bridge is a separate module (kept out of the root so the core SDK stays dependency-free) — go get it only if you want it:

go get github.com/azrtydxb/go-ai-sdk/contrib/otel

Quickstart

package main

import (
	"context"
	"fmt"

	"github.com/azrtydxb/go-ai-sdk/ai"
	"github.com/azrtydxb/go-ai-sdk/providers/anthropic"
)

func main() {
	model := anthropic.New().Model("claude-sonnet-5") // reads ANTHROPIC_API_KEY

	result, err := ai.GenerateText(context.Background(), ai.GenerateTextOpts{
		Model:  model,
		Prompt: "Why is the sky blue? Answer in one sentence.",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(result.Text)
}

Streaming looks the same shape, with the result's parts consumed as a Go iterator instead of a collected string:

import "github.com/azrtydxb/go-ai-sdk/provider"

stream, err := ai.StreamText(context.Background(), ai.GenerateTextOpts{
	Model:  model,
	Prompt: "Count from one to five.",
})
if err != nil {
	panic(err)
}
defer stream.Close()

for part := range stream.Parts() {
	if delta, ok := part.(provider.TextDelta); ok {
		fmt.Print(delta.Text)
	}
}
if err := stream.Err(); err != nil {
	panic(err)
}

That's the whole surface for the two most common calls — everything else (tool calling, structured output, embeddings, media, streaming internals, middleware, MCP, telemetry, provider-specific options) is one guide away in docs/, starting at Getting started. Complete, runnable, env-guarded examples covering text, streaming, tools, structured output, embeddings, images, speech, transcription, and MCP — including the multi-step tool-calling loop and ai.GenerateObject[T] — live in examples/, each compiled by CI.

Features

  • Text generationai.GenerateText/ai.StreamText, with an automatic multi-step tool-calling loop (StopWhen, PrepareStep, OnStepFinish) and conversation continuation. Lifecycle callbacks (OnModelCallStart/OnModelCallEnd, OnToolExecutionStart/ OnToolExecutionEnd) bracket each underlying model request and tool execution. See Generating text.
  • Tool calling — typed tools via ai.NewTool[Args] with a reflection-derived JSON Schema, ActiveTools, RepairToolCall, and a typed error taxonomy, plus ai.WithToolStrict()/ai.WithToolInputExamples (provider-enforced strict schemas and example payloads, folded into tool descriptions for providers without native support via ai.AddToolInputExamplesMiddleware) and per-tool input-streaming lifecycle hooks (ai.WithToolInputCallbacks). See Tools.
  • Structured timeoutsGenerateTextOpts.Timeout{Total, Step, Chunk} bounds a whole run, each step, and stream-chunk staleness independently, surfacing an SDK-imposed bound as a typed *ai.TimeoutError, distinct from the caller's own context.Context being canceled (still OnAbort/ the plain ctx error, exactly as before). See Generating text § Timeout.
  • Tool-execution approvalsai.RequireApproval/ai.ApprovalRequirer gate a tool call on an inline decision (ApproveToolCall) or a suspend-then-resume flow (PendingApprovals/Approvals), with denials surfaced as a typed *ai.ToolApprovalDeniedError tool result. See Tools § Approvals for tool execution.
  • RuntimeContext — an arbitrary application-value bag (GenerateTextOpts.RuntimeContext, ai.RuntimeContextFrom(ctx)) threaded into every tool call, approval check, and inline approval decision for a run. See Tools § RuntimeContext.
  • Agentsagent.Agent bundles a model, instructions, tools, and loop options for repeated runs (Generate/Stream), and agent.AsTool exposes one agent as a tool for another to delegate to. See Agents.
  • Code Modecodemode.Tool wraps a set of tools into a single run_code tool the model writes short programs against, executed by a caller-supplied Sandbox (the SDK ships no runtime). See Code Mode.
  • Structured outputai.GenerateObject[T]/ai.StreamObject[T], native-JSON where a provider supports it and forced-tool-call mode otherwise. See Structured output.
  • Output modes on GenerateTextGenerateTextOpts.Output (OutputObject[T], OutputArray[T], OutputChoice, OutputJSON) decodes a GenerateText call's final text into a typed value, extracted via ai.OutputAs[T], without a separate GenerateObject call (GenerateText-only for now; StreamText returns a typed error if Output is set). See Generating text § Output modes.
  • Streaming — a StreamPart sequence (iter.Seq) covering text, tool calls, reasoning, and sources uniformly, plus ai.SmoothStream for steady-cadence UI rendering. See Streaming.
  • Reasoning/thinking — surfaced uniformly as ReasoningPart/ ReasoningDelta/ReasoningEnd across every provider that supports it, and requestable uniformly too: GenerateTextOpts.Reasoning maps a single Effort/BudgetTokens option onto each provider's native reasoning knob (reasoning_effort, thinking, thinkingConfig, or additionalModelRequestFields.thinking). See Reasoning.
  • Embeddingsai.Embed/ai.EmbedMany with automatic batching and ai.CosineSimilarity. See Embeddings.
  • Rerankingai.Rerank ranks documents by relevance to a query via provider.RerankingModel (Cohere, Voyage, Mixedbread). See Embeddings § Reranking.
  • Media — image generation, video generation, speech synthesis, transcription (including live streaming transcription), and audio translation, all behind the same provider-agnostic pattern where one exists. See Media.
  • Video generationai.GenerateVideo/provider.VideoModel, Luma (Dream Machine, async poll), fal, and Replicate (both synchronous). See Media § GenerateVideo.
  • Streaming transcriptionai.StreamTranscribe/ provider.StreamingTranscriptionModel, a live bidirectional session over a stdlib-only WebSocket client (internal/websocket); Deepgram and OpenAI (Realtime API, transcription mode) implement it. See Media § StreamTranscribe.
  • Audio translationai.Translate/provider.TranslationModel (English-only output, regardless of source language), OpenAI only. See Media § Translate.
  • Realtime voice session(*openai.Provider).RealtimeSession, a live bidirectional voice/text conversation over OpenAI's Realtime API; OpenAI-only, no generic provider interface. See Media § Realtime voice session.
  • Files and skillsai.UploadFile/ai.DeleteFile/ provider.FileStore (OpenAI, Anthropic), referenced from a prompt via provider.FilePart.FileID; Anthropic's Skills API ((*anthropic.Provider).UploadSkill) is a distinct, Anthropic-only capability. See Media § Files & skills.
  • Middleware and registry — compose behavior onto any provider.LanguageModel (ExtractReasoningMiddleware, SimulateStreamingMiddleware, DefaultSettingsMiddleware, TelemetryMiddleware) and resolve "provider:model" strings via ai.Registry. See Middleware and registry.
  • Provider options — a raw-wire-key escape hatch (ProviderOptions/ProviderMetadata) for provider-specific request parameters that don't have a dedicated field. See Provider options.
  • Errors and retries — every model call goes through a shared retry wrapper with typed, errors.As-able failure modes. See Errors and retries.
  • Telemetry — a minimal, dependency-free span-reporting seam (ai.Telemetry/ai.TelemetryMiddleware) in the root module, plus a ready-to-use OpenTelemetry bridgecontrib/otel, a separate Go module (so the root stays zero-dependency) emitting real GenAI-semconv spans (gen_ai.operation.name, gen_ai.system, gen_ai.request.model, gen_ai.usage.*, gen_ai.response.finish_reasons). See Telemetry and contrib/otel/README.md.
  • MCP (Model Context Protocol) — an MCP client (stdio and Streamable HTTP transports) that adapts a server's tools straight into ai.Tool, plus resources, resource templates, prompts, argument completions, and server-initiated elicitation (stdio only — Streamable HTTP has no server→client channel to receive it on), and token-provider auth with transient retry on the HTTP transport. See MCP.

Documentation

Provider and capability matrix

All 39 supported providers, by capability (✅ = supported · — = not exposed by this package · ⚠ = supported with a caveat, see that provider's page in docs/providers/):

Provider Chat & streaming Tool calling Structured output Embeddings Reranking Images Video Speech (TTS) Transcription (STT)
OpenAI ✅ native ✅ ⚠ live
Azure OpenAI ✅ native
Groq ✅ native
xAI ✅ native ✅ ⚠
DeepSeek json_object-only
Cerebras ✅ native
Together ✅ native
Fireworks ✅ native
Perplexity ⚠ no live tools ✅ native
Moonshot ✅ native
Qwen ✅ native
MiniMax ✅ native
DeepInfra ✅ native
Hugging Face ⚠ tool-mode
Baseten ✅ native
LM Studio ✅ native
NVIDIA NIM ✅ native
Vercel AI Gateway ⚠ tool-mode
Mistral ⚠ schema dropped
Cohere ✅ native
Voyage
Mixedbread
ElevenLabs
Anthropic ⚠ tool-mode
Google ✅ native
Vertex AI ✅ native
Amazon Bedrock ⚠ tool-mode
fal
Replicate
Luma
Deepgram ✅ ⚠ live
LMNT
Hume
AssemblyAI
Gladia
Rev.ai
Cartesia
Prodia
Black Forest Labs

"Native" structured output means schema-constrained JSON directly via native JSON mode; "tool-mode" (Anthropic, Bedrock, Hugging Face, Vercel AI Gateway) uses an automatically injected, forced tool call instead — the same GenerateObject[T] call works identically either way. Rerank is ai.Rerank/provider.RerankingModel — see Embeddings § Reranking. StreamTranscribe (Deepgram, OpenAI, live/bidirectional) and Translate (OpenAI-only) are not ai.Registry/capability-matrix columns above — see Media for both, plus RealtimeSession (OpenAI-only) and FileStore (OpenAI, Anthropic), also outside the registry.

This is the full capability matrix from docs/providers/README.md, which also carries the exact wording of every ⚠ caveat above and links to each provider's own page for the full detail.

Provider coverage
Providers Notes
OpenAI, Anthropic, Google (Gemini) Three distinct wire formats prove the abstraction
Groq, xAI, DeepSeek, Together, Fireworks, Cerebras, Perplexity, Moonshot, Qwen, MiniMax, DeepInfra, Hugging Face, Baseten, LM Studio, NVIDIA NIM, Vercel AI Gateway Thin presets over the OpenAI-compatible base
Mistral, Cohere, Voyage, Mixedbread Own APIs, full provider implementations (Voyage: embeddings + reranking; Mixedbread: reranking only)
Azure OpenAI, Vertex AI, Amazon Bedrock Platform auth: Azure (API-key preset over the OpenAI-compatible base), Vertex AI (Google service-account/ADC auth), Bedrock (AWS SigV4 request signing)
ElevenLabs, fal, Replicate, Luma, Deepgram, LMNT, Hume, AssemblyAI, Gladia, Rev.ai, Cartesia, Prodia, Black Forest Labs; image/speech/transcription for OpenAI, Google/Vertex, xAI, Groq Media-only or media-layered providers, all behind the same ImageModel/SpeechModel/TranscriptionModel interfaces

A handful of AI SDK 6 providers remain unimplemented — planned per the v6 parity roadmap.

See CHANGELOG.md for the full release history, and the design spec for architecture, package layout, and the full decisions log.

Contributing

See docs/architecture.md for how the SDK is laid out — the three-package-layer split, the OpenAI/Gemini "compat base" pattern most providers build on, the StreamResponse disciplines every streaming implementation follows, and step-by-step checklists for adding a new provider or a new capability.

License

Apache License 2.0.

Documentation

Overview

Package goaisdk is the module root of go-ai-sdk, an idiomatic Go port of the Vercel AI SDK: one provider-agnostic API for text generation, streaming, structured output, tool calling, embeddings, and image/speech/transcription across 39 providers.

This root package contains no code — it exists to orient you. Start with github.com/azrtydxb/go-ai-sdk/ai.

Layout

The module is layered, and you generally import exactly two packages: ai for the calls, and one providers/* package to name a model.

  • ai — the high-level API. GenerateText, StreamText, GenerateObject[T], Embed/EmbedMany, GenerateImage/Speech/Video, Transcribe, plus tools, middleware, telemetry, and the retry/error model. Provider-agnostic: it reaches into no providers/* package.
  • provider — the interfaces every provider implements (LanguageModel, EmbeddingModel, ImageModel, …) and the wire types they exchange (Message, ContentPart, StreamPart, Response, Usage). Implement these to add a provider; import them to write middleware.
  • providers/* — one package per provider (anthropic, openai, google, bedrock, …), each returning models that satisfy provider's interfaces.
  • agent — a reusable model+instructions+tools bundle over ai's loop, and sub-agent delegation via AsTool.
  • mcp — a Model Context Protocol client, exposing an MCP server's tools as ai.Tool values via mcp.Tools.
  • codemode — executing model-authored code against your tools.
  • ai/aitest, provider/providertest — test doubles and a shared provider conformance suite.

The OpenTelemetry bridge lives in a separate module, github.com/azrtydxb/go-ai-sdk/contrib/otel, so the core SDK stays dependency-free.

Quickstart

model := anthropic.New().Model("claude-sonnet-5")

result, err := ai.GenerateText(ctx, ai.GenerateTextOpts{
	Model:  model,
	Prompt: "Why is the sky blue? Answer in one sentence.",
})
if err != nil {
	log.Fatal(err)
}
fmt.Println(result.Text)

Swapping providers means changing only the Model line. See the runnable examples on ai for streaming, structured output, and tool calling.

Documentation

The docs/ directory in the repository holds the full guide set: getting-started.md, architecture.md (how ai, provider, and providers/* relate), core/ (one guide per capability), providers/ (one per provider), mcp.md, troubleshooting.md, and migrating-from-vercel-ai-sdk.md for anyone arriving from the TypeScript SDK.

Directories

Path Synopsis
Package agent provides a reusable, higher-level configuration on top of package ai's GenerateText/StreamText: an Agent bundles a model, system instructions, tools, and a handful of loop-shaping options (MaxSteps, StopWhen, Output, RuntimeContext, ApproveToolCall) into one value that can be run repeatedly with different inputs via RunOpts, and exposed to another Agent as a tool via AsTool.
Package agent provides a reusable, higher-level configuration on top of package ai's GenerateText/StreamText: an Agent bundles a model, system instructions, tools, and a handful of loop-shaping options (MaxSteps, StopWhen, Output, RuntimeContext, ApproveToolCall) into one value that can be run repeatedly with different inputs via RunOpts, and exposed to another Agent as a tool via AsTool.
ai
Package ai is the high-level, provider-agnostic API for go-ai-sdk: text generation, structured output, tool calling, streaming, embeddings, and media generation, built entirely on the interfaces in package provider.
Package ai is the high-level, provider-agnostic API for go-ai-sdk: text generation, structured output, tool calling, streaming, embeddings, and media generation, built entirely on the interfaces in package provider.
aitest
Package aitest provides test doubles for the ai and provider packages.
Package aitest provides test doubles for the ai and provider packages.
Package codemode implements "Code Mode": instead of exposing each tool as a separate function call the model invokes one at a time, Tool wraps a set of ai.Tool values into a single run_code tool.
Package codemode implements "Code Mode": instead of exposing each tool as a separate function call the model invokes one at a time, Tool wraps a set of ai.Tool values into a single run_code tool.
contrib
otel module
examples
embed command
Command embed shows Embed, computing an embedding vector for a string.
Command embed shows Embed, computing an embedding vector for a string.
generate-image command
Command generate-image shows GenerateImage, creating an image from a text prompt.
Command generate-image shows GenerateImage, creating an image from a text prompt.
generate-object command
Command generate-object decodes a structured Recipe from the model.
Command generate-object decodes a structured Recipe from the model.
generate-speech command
Command generate-speech shows GenerateSpeech, synthesizing spoken audio from text.
Command generate-speech shows GenerateSpeech, synthesizing spoken audio from text.
generate-text command
Command generate-text shows the simplest possible GenerateText call.
Command generate-text shows the simplest possible GenerateText call.
mcp-tools command
Command mcp-tools drives an MCP stdio server's tools through GenerateText.
Command mcp-tools drives an MCP stdio server's tools through GenerateText.
stream-text command
Command stream-text shows StreamText, printing text deltas as they arrive.
Command stream-text shows StreamText, printing text deltas as they arrive.
tool-calling command
Command tool-calling shows GenerateText driving a multi-step tool loop.
Command tool-calling shows GenerateText driving a multi-step tool loop.
transcribe command
Command transcribe shows Transcribe, converting speech audio to text.
Command transcribe shows Transcribe, converting speech audio to text.
internal
eventstream
Package eventstream implements a minimal reader/writer for the AWS binary event stream format (content-type application/vnd.amazon.eventstream) used by streaming AWS APIs such as Bedrock's ConverseStream.
Package eventstream implements a minimal reader/writer for the AWS binary event stream format (content-type application/vnd.amazon.eventstream) used by streaming AWS APIs such as Bedrock's ConverseStream.
eventstream/eventstreamtest
Package eventstreamtest builds AWS event stream frames for test fixtures.
Package eventstreamtest builds AWS event stream frames for test fixtures.
fetchmedia
Package fetchmedia downloads media (image/video/audio) bytes from a server-chosen URL with SSRF and memory-DoS guards, for providers that return generated media as URLs rather than inline data.
Package fetchmedia downloads media (image/video/audio) bytes from a server-chosen URL with SSRF and memory-DoS guards, for providers that return generated media as URLs rather than inline data.
gauth
Package gauth mints OAuth2 access tokens for Google Cloud APIs from a service-account key, using only the standard library (RS256 JWT bearer grant, per https://developers.google.com/identity/protocols/oauth2/service-account).
Package gauth mints OAuth2 access tokens for Google Cloud APIs from a service-account key, using only the standard library (RS256 JWT bearer grant, per https://developers.google.com/identity/protocols/oauth2/service-account).
geminicompat
Package geminicompat implements the go-ai-sdk provider interfaces against Google's Generative Language (Gemini) wire format, parameterized so that Gemini-compatible providers can reuse it by supplying a Config.
Package geminicompat implements the go-ai-sdk provider interfaces against Google's Generative Language (Gemini) wire format, parameterized so that Gemini-compatible providers can reuse it by supplying a Config.
geminicompat/compattest
Package compattest provides a shared httptest fixture server that speaks the Gemini generateContent/streamGenerateContent/batchEmbedContents wire format, for use by provider/providertest conformance runs and other tests of internal/geminicompat-based providers.
Package compattest provides a shared httptest fixture server that speaks the Gemini generateContent/streamGenerateContent/batchEmbedContents wire format, for use by provider/providertest conformance runs and other tests of internal/geminicompat-based providers.
httpheader
Package httpheader provides the shared helper for applying user-supplied extra HTTP headers (provider.Call.Headers and its per-modality equivalents) to outgoing requests, without letting them override the provider's own authentication header.
Package httpheader provides the shared helper for applying user-supplied extra HTTP headers (provider.Call.Headers and its per-modality equivalents) to outgoing requests, without letting them override the provider's own authentication header.
multipartutil
Package multipartutil holds a small guard shared by every provider that builds a multipart/form-data request from caller-controlled strings (file MediaType/Filename, ProviderOptions keys/values, and similar caller-derived field names or values).
Package multipartutil holds a small guard shared by every provider that builds a multipart/form-data request from caller-controlled strings (file MediaType/Filename, ProviderOptions keys/values, and similar caller-derived field names or values).
openaicompat
Package openaicompat implements the go-ai-sdk provider interfaces against the OpenAI Chat Completions and Embeddings wire format, parameterized so that OpenAI-compatible providers (OpenAI itself, and any provider that exposes an OpenAI-compatible API) can reuse it by supplying a Config.
Package openaicompat implements the go-ai-sdk provider interfaces against the OpenAI Chat Completions and Embeddings wire format, parameterized so that OpenAI-compatible providers (OpenAI itself, and any provider that exposes an OpenAI-compatible API) can reuse it by supplying a Config.
openaicompat/compattest
Package compattest provides a shared httptest fixture server that speaks the OpenAI chat-completions + embeddings wire format, for use by provider/providertest conformance runs and other tests of internal/openaicompat-based providers.
Package compattest provides a shared httptest fixture server that speaks the OpenAI chat-completions + embeddings wire format, for use by provider/providertest conformance runs and other tests of internal/openaicompat-based providers.
partialjson
Package partialjson repairs a truncated (partial) JSON document — the kind produced mid-stream while accumulating a growing JSON string from an LLM — into a syntactically valid JSON document that best-effort preserves the content already present.
Package partialjson repairs a truncated (partial) JSON document — the kind produced mid-stream while accumulating a growing JSON string from an LLM — into a syntactically valid JSON document that best-effort preserves the content already present.
providerutil
Package providerutil holds two tiny helpers that every HTTP provider needs and that were previously copy-pasted per provider: extracting a human-readable message from an error response body, and merging ProviderOptions["<name>"] into an already-marshaled JSON request.
Package providerutil holds two tiny helpers that every HTTP provider needs and that were previously copy-pasted per provider: extracting a human-readable message from an error response body, and merging ProviderOptions["<name>"] into an already-marshaled JSON request.
schema
Package schema generates JSON Schema documents from Go struct types via reflection, following the subset of JSON Schema draft used by tool/object generation in the AI SDK.
Package schema generates JSON Schema documents from Go struct types via reflection, following the subset of JSON Schema draft used by tool/object generation in the AI SDK.
sigv4
Package sigv4 implements AWS Signature Version 4 request signing (https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html), sufficient for signing requests to AWS service APIs such as Bedrock Runtime.
Package sigv4 implements AWS Signature Version 4 request signing (https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html), sufficient for signing requests to AWS service APIs such as Bedrock Runtime.
sse
transcribeutil
Package transcribeutil holds small helpers shared by the asynchronous (upload-then-poll) transcription providers — assemblyai, gladia, and revai — whose Transcribe flows are structurally identical (upload/create a job, poll it to a terminal state, ctx-aware between polls) even though each speaks a different wire format.
Package transcribeutil holds small helpers shared by the asynchronous (upload-then-poll) transcription providers — assemblyai, gladia, and revai — whose Transcribe flows are structurally identical (upload/create a job, poll it to a terminal state, ctx-aware between polls) even though each speaks a different wire format.
websocket
Package websocket implements an RFC 6455 WebSocket client using only the Go standard library.
Package websocket implements an RFC 6455 WebSocket client using only the Go standard library.
websocket/websockettest
Package websockettest provides minimal RFC 6455 server-side helpers for testing internal/websocket's client, and for fixture servers used by provider packages elsewhere in this module.
Package websockettest provides minimal RFC 6455 server-side helpers for testing internal/websocket's client, and for fixture servers used by provider packages elsewhere in this module.
wsstream
Package wsstream provides the shared machinery behind a live, bidirectional WebSocket stream that yields decoded events: the read-pump goroutine, its clean-teardown and leak-safety guarantees, and idempotent Close/Err/Events semantics.
Package wsstream provides the shared machinery behind a live, bidirectional WebSocket stream that yields decoded events: the read-pump goroutine, its clean-teardown and leak-safety guarantees, and idempotent Close/Err/Events semantics.
Package mcp implements a client for the Model Context Protocol (MCP): a JSON-RPC 2.0 based protocol that lets an AI application discover and invoke tools exposed by an external server process.
Package mcp implements a client for the Model Context Protocol (MCP): a JSON-RPC 2.0 based protocol that lets an AI application discover and invoke tools exposed by an external server process.
Package provider is the spec every go-ai-sdk provider implements: a set of interfaces (LanguageModel, EmbeddingModel, ImageModel, SpeechModel, TranscriptionModel) plus the unified request/response types they share — Call, Response, Message/ContentPart, StreamPart, ToolDef, FinishReason, Usage.
Package provider is the spec every go-ai-sdk provider implements: a set of interfaces (LanguageModel, EmbeddingModel, ImageModel, SpeechModel, TranscriptionModel) plus the unified request/response types they share — Call, Response, Message/ContentPart, StreamPart, ToolDef, FinishReason, Usage.
providertest
Package providertest is a conformance suite for provider.LanguageModel implementations.
Package providertest is a conformance suite for provider.LanguageModel implementations.
providers
anthropic
Package anthropic implements the go-ai-sdk provider interfaces against Anthropic's Messages API.
Package anthropic implements the go-ai-sdk provider interfaces against Anthropic's Messages API.
assemblyai
Package assemblyai implements the go-ai-sdk provider.TranscriptionModel interface against AssemblyAI's asynchronous speech-to-text API: audio is uploaded, a transcript is created from the resulting URL, then the transcript is polled until it reaches a terminal state.
Package assemblyai implements the go-ai-sdk provider.TranscriptionModel interface against AssemblyAI's asynchronous speech-to-text API: audio is uploaded, a transcript is created from the resulting URL, then the transcript is polled until it reaches a terminal state.
azure
Package azure provides the Azure OpenAI provider.
Package azure provides the Azure OpenAI provider.
baseten
Package baseten provides the Baseten provider: Baseten's Model APIs expose an OpenAI-chat-completions compatible interface, so this package is a preset over the shared openaicompat base.
Package baseten provides the Baseten provider: Baseten's Model APIs expose an OpenAI-chat-completions compatible interface, so this package is a preset over the shared openaicompat base.
bedrock
Package bedrock implements the go-ai-sdk provider.LanguageModel interfaces against Amazon Bedrock's Converse and ConverseStream APIs, signing requests with AWS Signature Version 4.
Package bedrock implements the go-ai-sdk provider.LanguageModel interfaces against Amazon Bedrock's Converse and ConverseStream APIs, signing requests with AWS Signature Version 4.
bfl
Package bfl implements the go-ai-sdk provider.ImageModel interface against Black Forest Labs' asynchronous image-generation API: a generation is created, then polled at the absolute polling_url it returns until it reaches a terminal state.
Package bfl implements the go-ai-sdk provider.ImageModel interface against Black Forest Labs' asynchronous image-generation API: a generation is created, then polled at the absolute polling_url it returns until it reaches a terminal state.
cartesia
Package cartesia implements the go-ai-sdk provider.SpeechModel interface against Cartesia's text-to-speech API.
Package cartesia implements the go-ai-sdk provider.SpeechModel interface against Cartesia's text-to-speech API.
cerebras
Package cerebras provides the Cerebras provider: Cerebras's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package cerebras provides the Cerebras provider: Cerebras's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
cohere
Package cohere implements the go-ai-sdk provider interfaces against Cohere's v2 chat and embed APIs.
Package cohere implements the go-ai-sdk provider interfaces against Cohere's v2 chat and embed APIs.
deepgram
Package deepgram implements the go-ai-sdk provider.TranscriptionModel interface against the Deepgram speech-to-text API.
Package deepgram implements the go-ai-sdk provider.TranscriptionModel interface against the Deepgram speech-to-text API.
deepinfra
Package deepinfra provides the DeepInfra provider: DeepInfra's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package deepinfra provides the DeepInfra provider: DeepInfra's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
deepseek
Package deepseek provides the Deepseek provider: Deepseek's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package deepseek provides the Deepseek provider: Deepseek's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
elevenlabs
Package elevenlabs implements the go-ai-sdk provider.SpeechModel and provider.TranscriptionModel interfaces against the ElevenLabs API.
Package elevenlabs implements the go-ai-sdk provider.SpeechModel and provider.TranscriptionModel interfaces against the ElevenLabs API.
fal
Package fal implements the go-ai-sdk provider.ImageModel interface against fal.ai's synchronous fal.run image-generation endpoint.
Package fal implements the go-ai-sdk provider.ImageModel interface against fal.ai's synchronous fal.run image-generation endpoint.
fireworks
Package fireworks provides the Fireworks provider: Fireworks' API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package fireworks provides the Fireworks provider: Fireworks' API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
gateway
Package gateway provides the Vercel AI Gateway provider: an OpenAI-compatible routing endpoint that fronts many upstream model providers (OpenAI, Anthropic, Google, and more) behind "provider/model" routing slugs such as "openai/gpt-4o" or "anthropic/claude-3-5-sonnet".
Package gateway provides the Vercel AI Gateway provider: an OpenAI-compatible routing endpoint that fronts many upstream model providers (OpenAI, Anthropic, Google, and more) behind "provider/model" routing slugs such as "openai/gpt-4o" or "anthropic/claude-3-5-sonnet".
gladia
Package gladia implements the go-ai-sdk provider.TranscriptionModel interface against Gladia's asynchronous speech-to-text API: audio is uploaded, a pre-recorded transcription job is created from the resulting URL, then the job is polled until it reaches a terminal state.
Package gladia implements the go-ai-sdk provider.TranscriptionModel interface against Gladia's asynchronous speech-to-text API: audio is uploaded, a pre-recorded transcription job is created from the resulting URL, then the job is polled until it reaches a terminal state.
google
Package google implements the go-ai-sdk provider interfaces against Google's Generative Language API (Gemini).
Package google implements the go-ai-sdk provider interfaces against Google's Generative Language API (Gemini).
groq
Package groq provides the Groq provider: Groq's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package groq provides the Groq provider: Groq's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
huggingface
Package huggingface provides the Hugging Face provider: Hugging Face's Inference Router exposes an OpenAI-chat-completions compatible API, so this package is a preset over the shared openaicompat base.
Package huggingface provides the Hugging Face provider: Hugging Face's Inference Router exposes an OpenAI-chat-completions compatible API, so this package is a preset over the shared openaicompat base.
hume
Package hume implements the go-ai-sdk provider.SpeechModel interface against Hume's Octave text-to-speech API.
Package hume implements the go-ai-sdk provider.SpeechModel interface against Hume's Octave text-to-speech API.
lmnt
Package lmnt implements the go-ai-sdk provider.SpeechModel interface against LMNT's text-to-speech API.
Package lmnt implements the go-ai-sdk provider.SpeechModel interface against LMNT's text-to-speech API.
lmstudio
Package lmstudio provides the LM Studio provider: LM Studio's local server exposes an OpenAI-chat-completions compatible API, so this package is a preset over the shared openaicompat base.
Package lmstudio provides the LM Studio provider: LM Studio's local server exposes an OpenAI-chat-completions compatible API, so this package is a preset over the shared openaicompat base.
luma
Package luma implements the go-ai-sdk provider.ImageModel interface against Luma's Dream Machine image-generation API, which is asynchronous: a generation is created, then polled until it reaches a terminal state.
Package luma implements the go-ai-sdk provider.ImageModel interface against Luma's Dream Machine image-generation API, which is asynchronous: a generation is created, then polled until it reaches a terminal state.
minimax
Package minimax provides the MiniMax provider: MiniMax's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package minimax provides the MiniMax provider: MiniMax's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
mistral
Package mistral implements the go-ai-sdk provider interfaces against Mistral's chat completions and embeddings API, as a preset over the shared openaicompat base.
Package mistral implements the go-ai-sdk provider interfaces against Mistral's chat completions and embeddings API, as a preset over the shared openaicompat base.
mixedbread
Package mixedbread implements the go-ai-sdk provider.RerankingModel interface against Mixedbread AI's rerank API.
Package mixedbread implements the go-ai-sdk provider.RerankingModel interface against Mixedbread AI's rerank API.
moonshot
Package moonshot provides the Moonshot provider: Moonshot's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package moonshot provides the Moonshot provider: Moonshot's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
nvidia
Package nvidia provides the NVIDIA NIM provider: NVIDIA's NIM API endpoints are OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package nvidia provides the NVIDIA NIM provider: NVIDIA's NIM API endpoints are OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
openai
Package openai implements the go-ai-sdk provider interfaces against OpenAI's Chat Completions and Embeddings APIs.
Package openai implements the go-ai-sdk provider interfaces against OpenAI's Chat Completions and Embeddings APIs.
perplexity
Package perplexity provides the Perplexity provider: Perplexity's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package perplexity provides the Perplexity provider: Perplexity's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
prodia
Package prodia implements the go-ai-sdk provider.ImageModel interface against Prodia's v2 synchronous inference API.
Package prodia implements the go-ai-sdk provider.ImageModel interface against Prodia's v2 synchronous inference API.
qwen
Package qwen provides the Qwen provider: Alibaba's DashScope OpenAI-compatible mode is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package qwen provides the Qwen provider: Alibaba's DashScope OpenAI-compatible mode is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
replicate
Package replicate implements the go-ai-sdk provider.ImageModel interface against Replicate's synchronous ("Prefer: wait") predictions API.
Package replicate implements the go-ai-sdk provider.ImageModel interface against Replicate's synchronous ("Prefer: wait") predictions API.
revai
Package revai implements the go-ai-sdk provider.TranscriptionModel interface against Rev.ai's asynchronous speech-to-text API: a job is created from the uploaded audio, the job is polled until it reaches a terminal state, then the transcript is fetched.
Package revai implements the go-ai-sdk provider.TranscriptionModel interface against Rev.ai's asynchronous speech-to-text API: a job is created from the uploaded audio, the job is polled until it reaches a terminal state, then the transcript is fetched.
together
Package together provides the Together provider: Together's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package together provides the Together provider: Together's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
vertex
Package vertex implements the go-ai-sdk provider interfaces against Google Cloud's Vertex AI API (Gemini models hosted on Google Cloud).
Package vertex implements the go-ai-sdk provider interfaces against Google Cloud's Vertex AI API (Gemini models hosted on Google Cloud).
voyage
Package voyage implements the go-ai-sdk provider.EmbeddingModelWithOptions and provider.RerankingModel interfaces against Voyage AI's embeddings and rerank APIs.
Package voyage implements the go-ai-sdk provider.EmbeddingModelWithOptions and provider.RerankingModel interfaces against Voyage AI's embeddings and rerank APIs.
xai
Package xai provides the X.AI provider: X.AI's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.
Package xai provides the X.AI provider: X.AI's API is OpenAI-chat-completions compatible, so this package is a preset over the shared openaicompat base.

Jump to

Keyboard shortcuts

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