modelslab

package module
v0.0.0-...-583034f Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 9 Imported by: 0

README ΒΆ

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

API Description Package
Community Text-to-Image, Image-to-Image, Inpainting, ControlNet github.com/modelslab/modelslab-go/pkg/apis/community
Audio Text-to-Speech, Music Generation, Voice Cloning github.com/modelslab/modelslab-go/pkg/apis/audio
Video Text-to-Video, Image-to-Video github.com/modelslab/modelslab-go/pkg/apis/video
Deepfake Face Swap, Video Face Swap github.com/modelslab/modelslab-go/pkg/apis/deepfake
Image Editing Super Resolution, Background Removal, Outpainting github.com/modelslab/modelslab-go/pkg/apis/image_editing
Interior Interior Design, Room Decoration github.com/modelslab/modelslab-go/pkg/apis/interior
3D Text-to-3D, Image-to-3D github.com/modelslab/modelslab-go/pkg/apis/threed
Realtime Real-time Image Generation github.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,
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Documentation ΒΆ

Overview ΒΆ

Package modelslab provides the main SDK interface for ModelsLab API

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type ModelsLab ΒΆ

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

ModelsLab represents the main SDK client

func New ΒΆ

func New(apiKey string) *ModelsLab

New creates a new ModelsLab SDK instance

func NewEnterprise ΒΆ

func NewEnterprise(apiKey string) *ModelsLab

NewEnterprise creates a new ModelsLab SDK instance for enterprise use

func NewEnterpriseWithConfig ΒΆ

func NewEnterpriseWithConfig(config *client.Config) *ModelsLab

NewEnterpriseWithConfig creates a new enterprise ModelsLab SDK instance with custom configuration

func NewWithClient ΒΆ

func NewWithClient(c *client.Client, enterprise bool) *ModelsLab

NewWithClient creates a new ModelsLab SDK instance with a custom client

func NewWithConfig ΒΆ

func NewWithConfig(config *client.Config) *ModelsLab

NewWithConfig creates a new ModelsLab SDK instance with custom configuration

func (*ModelsLab) Audio ΒΆ

func (m *ModelsLab) Audio() *audio.API

Audio returns the audio API module

func (*ModelsLab) Community ΒΆ

func (m *ModelsLab) Community() *community.API

Community returns the community API module

func (*ModelsLab) DeepFake ΒΆ

func (m *ModelsLab) DeepFake() *deepfake.API

DeepFake returns the deepfake API module

func (*ModelsLab) GetClient ΒΆ

func (m *ModelsLab) GetClient() *client.Client

GetClient returns the underlying HTTP client

func (*ModelsLab) ImageEditing ΒΆ

func (m *ModelsLab) ImageEditing() *image_editing.API

ImageEditing returns the image editing API module

func (*ModelsLab) Interior ΒΆ

func (m *ModelsLab) Interior() *interior.API

Interior returns the interior design API module

func (*ModelsLab) IsEnterprise ΒΆ

func (m *ModelsLab) IsEnterprise() bool

IsEnterprise returns whether this is an enterprise instance

func (*ModelsLab) Realtime ΒΆ

func (m *ModelsLab) Realtime() *realtime.API

Realtime returns the realtime API module

func (*ModelsLab) ThreeD ΒΆ

func (m *ModelsLab) ThreeD() *threed.API

ThreeD returns the 3D generation API module

func (*ModelsLab) Video ΒΆ

func (m *ModelsLab) Video() *video.API

Video returns the video API module

Directories ΒΆ

Path Synopsis
pkg
apis/audio
Package audio provides audio-related API operations
Package audio provides audio-related API operations
apis/base
Package base provides base functionality for all API modules
Package base provides base functionality for all API modules
apis/community
Package community provides community API operations
Package community provides community API operations
apis/deepfake
Package deepfake provides deepfake API operations
Package deepfake provides deepfake API operations
apis/image_editing
Package image_editing provides image editing API operations
Package image_editing provides image editing API operations
apis/interior
Package interior provides interior design API operations
Package interior provides interior design API operations
apis/realtime
Package realtime provides realtime API operations
Package realtime provides realtime API operations
apis/threed
Package threed provides 3D generation API operations
Package threed provides 3D generation API operations
apis/video
Package video provides video-related API operations
Package video provides video-related API operations
client
Package client provides the core HTTP client for ModelsLab API
Package client provides the core HTTP client for ModelsLab API
schemas/audio
Package audio provides schemas for audio-related API operations
Package audio provides schemas for audio-related API operations
schemas/base
Package base provides base schemas and common structures
Package base provides base schemas and common structures
schemas/community
Package community provides schemas for community API operations
Package community provides schemas for community API operations
schemas/deepfake
Package deepfake provides schemas for deepfake API operations
Package deepfake provides schemas for deepfake API operations
schemas/image_editing
Package image_editing provides schemas for image editing API operations
Package image_editing provides schemas for image editing API operations
schemas/interior
Package interior provides schemas for interior design API operations
Package interior provides schemas for interior design API operations
schemas/realtime
Package realtime provides schemas for realtime API operations
Package realtime provides schemas for realtime API operations
schemas/threed
Package threed provides schemas for 3D generation API operations
Package threed provides schemas for 3D generation API operations
schemas/video
Package video provides schemas for video-related API operations
Package video provides schemas for video-related API operations
utils
Package utils provides utility functions for the ModelsLab SDK
Package utils provides utility functions for the ModelsLab SDK

Jump to

Keyboard shortcuts

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