bithuman

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 6 Imported by: 0

README

bitHuman Go SDK

Go CI Go Lint Go SAST Docs Visualization License

Go SDK for the bitHuman Real-Time Avatar Animation API.

bitHuman creates digital avatars that lip-sync to audio in real time. Audio in, animated video out at 25 FPS.

Installation

go get github.com/plexusone/bithuman-go

Quick Start

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/plexusone/bithuman-go"
    "github.com/plexusone/bithuman-go/api"
)

func main() {
    // Create client (uses BITHUMAN_API_KEY env var if not specified)
    client, err := bithuman.NewClient(
        bithuman.WithAPIKey(os.Getenv("BITHUMAN_API_KEY")),
    )
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // Validate credentials
    resp, err := client.Validate(ctx)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Credentials valid: %v\n", resp.Valid)

    // List agents
    agents, err := client.Agents().List(ctx, api.ListAgentsParams{})
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Found %d agents\n", len(agents.Agents))

    // Create a real-time session
    session, err := client.Sessions().Create(ctx, &api.CreateSessionRequest{
        AgentID: "your-agent-id",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Session created: %s\n", session.ID)
    fmt.Printf("LiveKit URL: %s\n", session.LivekitURL.Value)
}

Features

  • 🤖 Agents: Create, manage, and interact with avatar agents
  • 📡 Sessions: Real-time conversation sessions with LiveKit integration
  • 🗣️ TTS: Text-to-speech synthesis with 30+ language support
  • 🎬 Videos: Generate talking video MP4 files
  • 📁 Files: Upload images, video, audio, and documents
  • 🔔 Webhooks: Event notifications for async operations
  • 🔌 OmniAvatar Adapter: Use bitHuman render behind the provider-agnostic OmniAvatar interfaces

Environment Variables

Variable Description
BITHUMAN_API_KEY Your bitHuman API key (from Developer → API Keys)

API Reference

Client Options
client, _ := bithuman.NewClient(
    bithuman.WithAPIKey("your-api-key"),
    bithuman.WithBaseURL("https://api.bithuman.ai"),  // Optional
    bithuman.WithTimeout(60 * time.Second),           // Optional
    bithuman.WithHTTPClient(customClient),            // Optional
)
Services
Service Description
client.Agents() Avatar agent management
client.Sessions() Real-time conversation sessions
client.TTS() Text-to-speech synthesis
client.Videos() Talking video generation
client.Files() File uploads
client.Billing() Account balance
client.Webhooks() Event notifications
Low-Level API Access

For endpoints not covered by the high-level services:

apiClient := client.API()
// Use ogen-generated methods directly

LiveKit Integration

bitHuman sessions can connect to LiveKit for real-time WebRTC streaming:

session, _ := client.Sessions().Create(ctx, &api.CreateSessionRequest{
    AgentID:      "your-agent-id",
    LivekitURL:   api.NewOptString("wss://your-livekit-server"),  // Optional external LiveKit
    LivekitToken: api.NewOptString("your-token"),                  // Optional external token
})

// Use session.LivekitURL and session.LivekitToken to connect

Development

Regenerating the API Client

The SDK uses ogen to generate Go code from the OpenAPI specification:

# Install ogen
go install github.com/ogen-go/ogen/cmd/ogen@latest

# Regenerate API client
./generate.sh
Running Tests
go test ./...
Linting
golangci-lint run

OmniAvatar Integration

The omniavatar subpackage implements the provider-agnostic OmniAvatar render interfaces (render.Provider, render.AudioUploader) on top of this SDK, so bitHuman video generation can be used behind the OmniAvatar abstraction. It depends only on omniavatar-core.

import bithumanomni "github.com/plexusone/bithuman-go/omniavatar"

p, err := bithumanomni.NewRenderProvider(bithumanomni.RenderConfig{
    APIKey: os.Getenv("BITHUMAN_API_KEY"),
})

Provider adapters live in the provider SDK repos so all bitHuman-specific knowledge stays here; the real-time live adapter, which requires LiveKit, lives in the batteries-included omniavatar package.

License

MIT License - see LICENSE for details.

Documentation

Overview

Package bithuman provides a Go client for the bitHuman API.

bitHuman is a real-time avatar animation platform that creates digital avatars with lip-sync to audio at 25 FPS. Audio in, animated video out.

The client wraps the ogen-generated API client with a higher-level interface that handles authentication and provides convenient methods for common operations.

Quick Start

client, err := bithuman.NewClient(bithuman.WithAPIKey("your-api-key"))
if err != nil {
    log.Fatal(err)
}

// Create a session with an agent
session, err := client.Sessions().Create(ctx, &api.CreateSessionRequest{
    AgentId: "agent-id",
})

Environment Variables

If no API key is provided, the client will look for BITHUMAN_API_KEY in the environment.

Index

Constants

View Source
const DefaultBaseURL = "https://api.bithuman.ai"

DefaultBaseURL is the default bitHuman API base URL.

View Source
const Version = "0.1.0"

Version is the SDK version.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentsService

type AgentsService struct {
	// contains filtered or unexported fields
}

AgentsService handles avatar agent management.

func (*AgentsService) Create

func (s *AgentsService) Create(ctx context.Context, req *api.CreateAgentRequest) (*api.Agent, error)

Create creates a new avatar agent.

func (*AgentsService) Delete

func (s *AgentsService) Delete(ctx context.Context, agentID string) error

Delete deletes an agent.

func (*AgentsService) Get

func (s *AgentsService) Get(ctx context.Context, agentID string) (*api.Agent, error)

Get returns a specific agent.

func (*AgentsService) List

List returns all agents.

func (*AgentsService) Speak

func (s *AgentsService) Speak(ctx context.Context, agentID string, req *api.SpeakRequest) (*api.SpeakResponse, error)

Speak makes an agent speak the given text.

func (*AgentsService) Update

func (s *AgentsService) Update(ctx context.Context, agentID string, req *api.UpdateAgentRequest) (*api.Agent, error)

Update updates an agent.

type BillingService

type BillingService struct {
	// contains filtered or unexported fields
}

BillingService handles account balance and usage.

func (*BillingService) GetBalance

func (s *BillingService) GetBalance(ctx context.Context) (*api.Balance, error)

GetBalance returns the account credit balance.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the main bitHuman client for interacting with the API.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new bitHuman client with the given options.

func (*Client) API

func (c *Client) API() *api.Client

API returns the underlying ogen-generated API client for advanced usage. Use this when you need access to API endpoints not covered by the high-level wrapper methods.

func (*Client) APIKey

func (c *Client) APIKey() string

APIKey returns the API key used by the client.

func (*Client) Agents

func (c *Client) Agents() *AgentsService

Agents returns the agents service for avatar agent management.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the base URL used by the client.

func (*Client) Billing

func (c *Client) Billing() *BillingService

Billing returns the billing service for account balance.

func (*Client) Files

func (c *Client) Files() *FilesService

Files returns the files service for file uploads.

func (*Client) Sessions

func (c *Client) Sessions() *SessionsService

Sessions returns the sessions service for real-time conversation sessions.

func (*Client) TTS

func (c *Client) TTS() *TTSService

TTS returns the TTS service for text-to-speech synthesis.

func (*Client) Validate

func (c *Client) Validate(ctx context.Context) (*api.ValidateResponse, error)

Validate checks if the API credentials are valid.

func (*Client) Videos

func (c *Client) Videos() *VideosService

Videos returns the videos service for talking video generation.

func (*Client) Webhooks

func (c *Client) Webhooks() *WebhooksService

Webhooks returns the webhooks service for event notifications.

type FilesService

type FilesService struct {
	// contains filtered or unexported fields
}

FilesService handles file uploads.

func (*FilesService) Upload

func (s *FilesService) Upload(ctx context.Context, req *api.UploadFileRequest) (*api.File, error)

Upload uploads a file (image, video, audio, or document).

type Option

type Option func(*clientOptions)

Option is a functional option for configuring the Client.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for authentication.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the request timeout.

type SessionsService

type SessionsService struct {
	// contains filtered or unexported fields
}

SessionsService handles real-time conversation sessions.

func (*SessionsService) Create

Create creates a new real-time session with an agent. Returns connection details for WebRTC/LiveKit.

func (*SessionsService) CreateEmbedToken

func (s *SessionsService) CreateEmbedToken(ctx context.Context, req *api.CreateEmbedTokenRequest) (*api.EmbedToken, error)

CreateEmbedToken creates a short-lived JWT for website embedding.

func (*SessionsService) End

func (s *SessionsService) End(ctx context.Context, sessionID string) error

End ends an active session.

func (*SessionsService) Get

func (s *SessionsService) Get(ctx context.Context, sessionID string) (*api.Session, error)

Get returns a specific session.

type TTSService

type TTSService struct {
	// contains filtered or unexported fields
}

TTSService handles text-to-speech synthesis.

func (*TTSService) ListVoices

func (s *TTSService) ListVoices(ctx context.Context) (*api.VoiceList, error)

ListVoices returns available TTS voices.

func (*TTSService) Synthesize

func (s *TTSService) Synthesize(ctx context.Context, req *api.TTSRequest) (*api.TextToSpeechOK, error)

Synthesize converts text to audio. Returns audio data as bytes (audio/mpeg format).

type VideosService

type VideosService struct {
	// contains filtered or unexported fields
}

VideosService handles talking video generation.

func (*VideosService) Create

Create starts a new video generation job. This is async; poll Get() to check status.

func (*VideosService) Get

func (s *VideosService) Get(ctx context.Context, videoID string) (*api.VideoJob, error)

Get returns video job status and download URL when complete.

type WebhooksService

type WebhooksService struct {
	// contains filtered or unexported fields
}

WebhooksService handles webhook event notifications.

func (*WebhooksService) Create

Create registers a new webhook endpoint.

func (*WebhooksService) Delete

func (s *WebhooksService) Delete(ctx context.Context, webhookID string) error

Delete removes a webhook.

func (*WebhooksService) List

List returns all registered webhooks.

Directories

Path Synopsis
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
Package omniavatar provides an OmniAvatar render provider backed by the bitHuman API.
Package omniavatar provides an OmniAvatar render provider backed by the bitHuman API.

Jump to

Keyboard shortcuts

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