sora

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSoraClientID = "app_1LOVEceTvrP2tHFDNnrPLQkJ"

DefaultSoraClientID 默认的 Sora 客户端 ID

Variables

View Source
var ValidStyles = []string{
	"festive", "kakalaka", "news", "selfie", "handheld",
	"golden", "anime", "retro", "nostalgic", "comic",
}

ValidStyles 有效的视频风格列表

Functions

func ExtractRemixID

func ExtractRemixID(text string) string

ExtractRemixID 从文本或 URL 中提取 Remix 视频 ID 支持: https://sora.chatgpt.com/p/s_[hex32] 或直接 s_[hex32]

func ExtractStyle

func ExtractStyle(prompt string) (string, string)

ExtractStyle 从提示词中提取 {style} 风格标记 返回清理后的提示词和风格 ID(无风格时为空字符串) 示例: "一只猫 {anime}" -> ("一只猫", "anime")

func ExtractVideoID added in v1.0.1

func ExtractVideoID(text string) string

ExtractVideoID 从 Sora 分享链接或文本中提取视频 ID 支持: https://sora.chatgpt.com/p/s_xxx 或直接 s_xxx 等格式

func ParseProxy

func ParseProxy(proxy string) string

ParseProxy 解析代理字符串

支持格式:

Types

type Client

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

Client Sora API 客户端

func New

func New(proxyURL string) (*Client, error)

New 创建客户端,proxyURL 为空则不使用代理

func (*Client) CreateImageTask

func (c *Client) CreateImageTask(accessToken, sentinelToken, prompt string, width, height int) (string, error)

CreateImageTask 创建图片生成任务(文生图) 如需图生图,先调用 UploadImage 获取 mediaID,再传入 CreateImageTaskWithImage

func (*Client) CreateImageTaskWithImage

func (c *Client) CreateImageTaskWithImage(accessToken, sentinelToken, prompt string, width, height int, mediaID string) (string, error)

CreateImageTaskWithImage 创建图生图任务 mediaID 为空表示文生图,非空表示图生图

func (*Client) CreateVideoTask

func (c *Client) CreateVideoTask(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size string) (string, error)

CreateVideoTask 创建视频生成任务(文生视频) 如需图生视频,先调用 UploadImage 获取 mediaID,再传入 CreateVideoTaskWithImage

func (*Client) CreateVideoTaskWithImage

func (c *Client) CreateVideoTaskWithImage(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID string) (string, error)

CreateVideoTaskWithImage 创建图生视频任务

func (*Client) CreateVideoTaskWithOptions

func (c *Client) CreateVideoTaskWithOptions(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID, styleID string) (string, error)

CreateVideoTaskWithOptions 创建视频任务的完整方法 mediaID 为空表示文生视频,非空表示图生视频 styleID 为空表示无风格,可选值见 ValidStyles

func (*Client) EnhancePrompt

func (c *Client) EnhancePrompt(accessToken, prompt, expansionLevel string, durationSec int) (string, error)

EnhancePrompt 使用 Sora 的提示词优化 API 增强提示词 expansionLevel: "medium" 或 "long" durationSec: 5、10、15 或 25

func (*Client) GenerateSentinelToken

func (c *Client) GenerateSentinelToken(accessToken string) (string, error)

GenerateSentinelToken 获取 sentinel token(含 PoW 计算)

func (*Client) GetCreditBalance added in v1.0.4

func (c *Client) GetCreditBalance(accessToken string) (CreditBalance, error)

GetCreditBalance 获取当前账号的可用次数和配额信息

func (*Client) GetDownloadURL

func (c *Client) GetDownloadURL(accessToken, taskID string) (string, error)

GetDownloadURL 从 drafts 接口获取下载链接

func (*Client) GetSubscriptionInfo added in v1.0.4

func (c *Client) GetSubscriptionInfo(accessToken string) (SubscriptionInfo, error)

GetSubscriptionInfo 获取当前账号的订阅信息(套餐类型、到期时间)

func (*Client) GetWatermarkFreeURL added in v1.0.1

func (c *Client) GetWatermarkFreeURL(accessToken, videoID string) (string, error)

GetWatermarkFreeURL 获取 Sora 视频的无水印下载链接 需要使用 RefreshAccessToken 获取的 token,普通 ChatGPT access_token 不支持 videoID 为 Sora 分享链接中的视频 ID,也可以传入完整链接(自动提取 ID)

func (*Client) PollImageTask

func (c *Client) PollImageTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) (string, error)

PollImageTask 轮询图片任务进度,返回图片 URL onProgress 可为 nil,非 nil 时在每次轮询后回调进度

func (*Client) PollVideoTask

func (c *Client) PollVideoTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) error

PollVideoTask 轮询视频任务进度 onProgress 可为 nil,非 nil 时在每次轮询后回调进度

func (*Client) QueryImageTaskOnce added in v1.0.3

func (c *Client) QueryImageTaskOnce(accessToken, taskID string, startTime time.Time) ImageTaskResult

QueryImageTaskOnce 单次查询图片任务状态(非阻塞,供 TUI 使用)

func (*Client) QueryVideoTaskOnce added in v1.0.3

func (c *Client) QueryVideoTaskOnce(accessToken, taskID string, startTime time.Time, maxProgress int) VideoTaskResult

QueryVideoTaskOnce 单次查询视频任务状态(非阻塞,供 TUI 使用) maxProgress 应传入之前的最大进度值,返回的结果中会包含更新后的进度

func (*Client) RefreshAccessToken added in v1.0.1

func (c *Client) RefreshAccessToken(refreshToken, clientID string) (newAccessToken, newRefreshToken string, err error)

RefreshAccessToken 使用 refresh_token 获取新的 access_token 返回新的 accessToken 和 refreshToken(OpenAI 每次刷新都会返回新的 refresh_token)

func (*Client) RemixVideo

func (c *Client) RemixVideo(accessToken, sentinelToken, remixTargetID, prompt, orientation string, nFrames int, styleID string) (string, error)

RemixVideo 基于已有视频创建 Remix 任务 remixTargetID 为 Sora 分享链接中的视频 ID,格式: s_[hex32]

func (*Client) UploadImage

func (c *Client) UploadImage(accessToken string, imageData []byte, filename string) (string, error)

UploadImage 上传图片,返回 mediaID,用于图生图/图生视频 imageData 为图片二进制数据,filename 为文件名(如 "image.png")

type CreditBalance added in v1.0.4

type CreditBalance struct {
	RemainingCount    int  // 剩余可用次数
	RateLimitReached  bool // 是否触发速率限制
	AccessResetsInSec int  // 访问权限重置时间(秒)
}

CreditBalance 配额信息

type ImageTaskResult added in v1.0.3

type ImageTaskResult struct {
	Progress Progress
	Done     bool
	ImageURL string
	Err      error
}

ImageTaskResult 图片任务单次查询结果

type Progress

type Progress struct {
	Percent int    // 进度百分比 0-100
	Status  string // 任务状态
	Elapsed int    // 已耗时(秒)
}

Progress 任务进度信息

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc 进度回调函数类型

type SubscriptionInfo added in v1.0.4

type SubscriptionInfo struct {
	PlanID    string // 套餐类型,例如 "chatgptplusplan"
	PlanTitle string // 套餐名称,例如 "ChatGPT Plus"
	EndTs     int64  // 订阅到期时间戳(秒)
}

SubscriptionInfo 订阅信息

type VideoTaskResult added in v1.0.3

type VideoTaskResult struct {
	Progress Progress
	Done     bool
	Err      error
}

VideoTaskResult 视频任务单次查询结果

Jump to

Keyboard shortcuts

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