ModelsLab Go SDK

Official Go SDK for ModelsLab API - Generate AI content including images, videos, audio, 3D models, and more.

Features

Text-to-Image & Image-to-Image generation Text-to-Speech & Music generation Face Swap & Deepfake operations Interior Design & 3D modeling Image Editing (upscaling, background removal, etc.) Realtime generation APIs Enterprise features support

Quick Start

1. Installation

go mod init your-project
go get github.com/modelslab/modelslab-go

2. Get Your API Key

  1. Sign up at ModelsLab.com
  2. Go to your dashboard
  3. get your API key

3. Basic Usage with community models

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/modelslab/modelslab-go/pkg/apis/community"
	"github.com/modelslab/modelslab-go/pkg/client"
	communitySchema "github.com/modelslab/modelslab-go/pkg/schemas/community"
)

func main() {
	c := client.New("your-api-key")
	api := community.New(c, false)

	model := "midjourney"
	req := &communitySchema.Text2ImageRequest{
		Prompt:  "a cat",
		ModelID: &model,
	}

	resp, err := api.TextToImage(context.Background(), &req)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	out, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Println(string(out))
}

4. Run Your Code

go run main.go

API Examples

Text-to-Speech

package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/modelslab/modelslab-go/pkg/apis/audio"
	"github.com/modelslab/modelslab-go/pkg/client"
	audioSchema "github.com/modelslab/modelslab-go/pkg/schemas/audio"
)

func main() {
	c := client.New("your-api-key")
	api := audio.New(c, false)

	voice_id := "madison"
	language := "english"
	req := audioSchema.Text2SpeechRequest{
		Prompt:   "a cat sitting on a mat",
		VoiceID:  &voice_id,
		Language: &language,
	}

	resp, err := api.TextToSpeech(context.Background(), &req)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	out, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Println(string(out))
}

Multiple Face Swap

package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/modelslab/modelslab-go/pkg/apis/deepfake"
	"github.com/modelslab/modelslab-go/pkg/client"
	"github.com/modelslab/modelslab-go/pkg/schemas/base"
	deepfakeSchema "github.com/modelslab/modelslab-go/pkg/schemas/deepfake"
)

func main() {
	c := client.New("your-api-key")
	deepfakeAPI := deepfake.New(c, false)

	initImageURL := "https://i.pinimg.com/564x/4c/6a/d0/4c6ad0f74a3a251344cb115699a9a7c9.jpg"
	targetImageURL := "https://i.pinimg.com/564x/11/ac/0d/11ac0ddaf6962e395f30abc61043393e.jpg"

	req := deepfakeSchema.MultipleFaceSwapRequest{
		InitImage: base.FileInput{
			URL: &initImageURL,
		},
		TargetImage: base.FileInput{
			URL: &targetImageURL,
		},
	}

	resp, err := deepfakeAPI.MultipleFaceSwap(context.Background(), &req)
	if err != nil {
		panic(err)
	}

	prettyJSON, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Println(string(prettyJSON))
}

Text-to-Video

package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/modelslab/modelslab-go/pkg/apis/video"
	"github.com/modelslab/modelslab-go/pkg/client"
	videoSchema "github.com/modelslab/modelslab-go/pkg/schemas/video"
)

func main() {
	c := client.New("your-api-key")
	videoAPI := video.New(c, false)

	req := videoSchema.Text2VideoRequest{
		Prompt:  "A cat playing with a ball in a sunny garden",
		ModelID: "cogvideox",
	}

	resp, err := videoAPI.TextToVideo(context.Background(), &req)
	if err != nil {
		panic(err)
	}

	prettyJSON, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Println(string(prettyJSON))
}

Available APIs

APIDescriptionPackage
CommunityText-to-Image, Image-to-Image, Inpainting, ControlNetgithub.com/modelslab/modelslab-go/pkg/apis/community
AudioText-to-Speech, Music Generation, Voice Cloninggithub.com/modelslab/modelslab-go/pkg/apis/audio
VideoText-to-Video, Image-to-Videogithub.com/modelslab/modelslab-go/pkg/apis/video
DeepfakeFace Swap, Video Face Swapgithub.com/modelslab/modelslab-go/pkg/apis/deepfake
Image EditingSuper Resolution, Background Removal, Outpaintinggithub.com/modelslab/modelslab-go/pkg/apis/image_editing
InteriorInterior Design, Room Decorationgithub.com/modelslab/modelslab-go/pkg/apis/interior
3DText-to-3D, Image-to-3Dgithub.com/modelslab/modelslab-go/pkg/apis/threed
RealtimeReal-time Image Generationgithub.com/modelslab/modelslab-go/pkg/apis/realtime

Configuration

Basic Client

import "github.com/modelslab/modelslab-go/pkg/client"

// Simple client
c := client.New("your-api-key")

Custom Configuration

import (
	"time"
	"github.com/modelslab/modelslab-go/pkg/client"
)

config := &client.Config{
	APIKey:       "your-api-key",
	BaseURL:      "https://modelslab.com/api/",
	FetchRetry:   10,
	FetchTimeout: 2 * time.Second,
	HTTPTimeout:  30 * time.Second,
}

c := client.NewWithConfig(config)

Enterprise Mode

// For enterprise users
communityAPI := community.New(c, true) // true = enterprise mode

Response Format

The SDK returns complete raw API responses as map[string]interface{} to preserve all fields:
{
  "status": "success",
  "message": "Image generated successfully",
  "output": ["https://example.com/generated-image.jpg"],
  "id": 12345,
  "meta": {
    "prompt": "A beautiful sunset",
    "model": "stable-diffusion",
    "steps": 20,
    "seed": 12345
  },
  "generationTime": 5.2,
  "proxy_links": ["https://cdn.example.com/image.jpg"]
}
You get ALL fields returned by the API, including metadata, generation time, proxy links, and any future fields.

File Input Options

The SDK supports multiple ways to provide images/audio:
import "github.com/modelslab/modelslab-go/pkg/schemas/base"

// URL input
imageURL := "https://example.com/image.jpg"
fileInput := base.FileInput{
    URL: &imageURL,
}

// Base64 input
base64Data := "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
fileInput := base.FileInput{
    Base64: &base64Data,
}

// File path (for local files)
filePath := "/path/to/image.jpg"
fileInput := base.FileInput{
    FilePath: &filePath,
}
Repository: