Documentation
¶
Overview ¶
Package imagetovideo provides a small Go client for creating and polling Image to Video AI generation tasks.
Index ¶
Examples ¶
Constants ¶
const ( StatusPending = "pending" StatusProcessing = "processing" StatusSuccess = "success" StatusFailed = "failed" StatusCanceled = "canceled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the Image to Video AI API.
func (*Client) CreateVideo ¶
func (c *Client) CreateVideo(ctx context.Context, request CreateRequest) (*CreateResponse, error)
CreateVideo starts an image-to-video generation task.
Example ¶
package main
import (
"context"
"fmt"
"os"
imagetovideo "github.com/waeckerlinfederowicz66-sketch/imagetovideo-go"
)
func main() {
client, err := imagetovideo.NewClient(os.Getenv("IMAGETOVIDEO_API_KEY"))
if err != nil {
panic(err)
}
task, err := client.CreateVideo(context.Background(), imagetovideo.CreateRequest{
Source: imagetovideo.ImageSource{"https://example.com/source.jpg"},
Prompt: "A slow camera push-in with soft natural movement",
Duration: 5,
Model: "seedance-1.5-pro",
AspectRatio: "16:9",
})
if err != nil {
panic(err)
}
fmt.Println(task.TaskID)
}
Output:
func (*Client) Wait ¶
Wait polls a generation task until it succeeds, fails, is canceled, or the context is canceled.
Example ¶
package main
import (
"context"
"fmt"
"os"
"time"
imagetovideo "github.com/waeckerlinfederowicz66-sketch/imagetovideo-go"
)
func main() {
client, err := imagetovideo.NewClient(os.Getenv("IMAGETOVIDEO_API_KEY"))
if err != nil {
panic(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
result, err := client.Wait(ctx, "task-id")
if err != nil {
panic(err)
}
if result.Status == imagetovideo.StatusSuccess {
fmt.Println(result.URL)
}
}
Output:
type CreateRequest ¶
type CreateRequest struct {
Source ImageSource `json:"url"`
Prompt string `json:"prompt,omitempty"`
Duration int `json:"duration"`
Model string `json:"model"`
Resolution string `json:"resolution,omitempty"`
AspectRatio string `json:"aspectRatio,omitempty"`
AudioURL string `json:"audioUrl,omitempty"`
GenerateAudio *bool `json:"generateAudio,omitempty"`
TailImageURL string `json:"tailImageUrl,omitempty"`
}
CreateRequest describes an image-to-video generation request.
type CreateResponse ¶
type CreateResponse struct {
TaskID string `json:"taskId"`
RequestID string `json:"requestId"`
Status string `json:"status"`
}
CreateResponse identifies a newly-created generation task.
type ImageSource ¶
type ImageSource []string
ImageSource holds one or more public source-image URLs. A single URL is encoded as a JSON string, while multiple URLs are encoded as an array.
func (ImageSource) MarshalJSON ¶
func (source ImageSource) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type Option ¶
Option customizes a Client.
func WithBaseURL ¶
WithBaseURL replaces the default API base URL. It is primarily useful for tests.
func WithHTTPClient ¶
WithHTTPClient replaces the default HTTP client.
func WithPollInterval ¶
WithPollInterval sets the interval used by Wait.
type Task ¶
type Task struct {
TaskID string `json:"taskId"`
Status string `json:"status"`
URL string `json:"url,omitempty"`
Videos []Video `json:"videos,omitempty"`
Result *TaskInfo `json:"result,omitempty"`
}
Task describes the current state and output of a generation task.