Documentation
¶
Overview ¶
Package huntapi is the official Go SDK for the HuntAPI API (https://www.huntapi.com).
Download video and audio from public media URLs, or extract their metadata, with one async REST API.
Create one client and reuse it:
client, err := huntapi.NewClient("", nil) // reads HUNTAPI_API_KEY
response, err := client.MediaMetadata(ctx, ...)
Every documented endpoint has a typed method; Client.Request reaches any other path.
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func Float(v float64) *float64
- func Int(v int64) *int64
- func String(v string) *string
- type APIError
- type AudioDownloadParams
- type BatchResult
- type Client
- func (c *Client) AudioDownload(ctx context.Context, params *AudioDownloadParams, options ...RequestOption) (*Response, error)
- func (c *Client) Jobs(ctx context.Context, params *JobsParams, options ...RequestOption) (*Response, error)
- func (c *Client) MediaMetadata(ctx context.Context, params *MediaMetadataParams, options ...RequestOption) (*Response, error)
- func (c *Client) Request(ctx context.Context, method, path string, params map[string]any, ...) (*Response, error)
- func (c *Client) Stats(ctx context.Context, params *StatsParams, options ...RequestOption) (*Response, error)
- func (c *Client) Usage(ctx context.Context, options ...RequestOption) (*Response, error)
- func (c *Client) VideoDownload(ctx context.Context, params *VideoDownloadParams, options ...RequestOption) (*Response, error)
- func (c *Client) WaitForJob(ctx context.Context, jobID string, options *WaitForJobOptions) (*Response, error)
- type ClientOptions
- type ConfigurationError
- type JobTimeoutError
- type JobsParams
- type MediaMetadataParams
- type RequestOption
- type Response
- type ResponseDecodingError
- type SerializationError
- type StatsParams
- type TransportError
- type VideoDownloadParams
- type WaitForJobOptions
Constants ¶
const ( // DefaultBaseURL is the production API origin. DefaultBaseURL = "https://api.huntapi.com" // DefaultTimeout bounds every request unless ClientOptions.Timeout says otherwise. DefaultTimeout = 120 * time.Second // APIKeyEnvironmentVariable is read when NewClient receives an empty API key. APIKeyEnvironmentVariable = "HUNTAPI_API_KEY" // DefaultConcurrency is the number of tasks Batch runs at the same time. DefaultConcurrency = 10 // MaxRetries is the default number of retries after a network error or a 408, 429, 500, 502, 503 or 504. MaxRetries = 3 // RetryBackoffFactor multiplies the delay before each new retry (a Retry-After header wins). RetryBackoffFactor = 1.5 // DefaultRetryDelay is the delay before the first retry. DefaultRetryDelay = time.Second // MaxRetryDelay caps the delay between two attempts. MaxRetryDelay = 30 * time.Second )
const Version = "0.1.0"
Version is the SDK version sent in the User-Agent header.
Variables ¶
var JobTerminalStatuses = []string{"CompletedJob", "Error", "NotFound", "BadRequest"}
JobTerminalStatuses are the job statuses WaitForJob stops on.
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
// Message is the "error" (or "message") field of the JSON body, when present.
Message string
Response *Response
}
APIError is returned for non-2xx responses.
func IsAPIError ¶
IsAPIError reports whether err is an *APIError and returns it.
type AudioDownloadParams ¶
type AudioDownloadParams struct {
// URL to download audio from.
Query string `json:"query" api:"query,required"`
// Desired download type. Supported values: audio (default). Default: "audio".
DownloadType *string `json:"download_type" api:"download_type"`
// Maximum duration of the downloaded content in seconds. If the audio is longer than this value, only the content up to this duration will be downloaded.
MaxDuration *float64 `json:"max_duration" api:"max_duration"`
// Desired audio quality. Default: "best".
AudioQuality *string `json:"audio_quality" api:"audio_quality"`
// Desired output format for the audio. Default: "mp3".
AudioFormat *string `json:"audio_format" api:"audio_format"`
// URL of the webhook where results will be sent. When specified, the system will attempt to send the response to this URL up to 3 times with a 5-second delay between each attempt. The results will be sent as a POST request.
WebhookURL *string `json:"webhook_url" api:"webhook_url"`
// Authorization header for the webhook. This parameter allows you to add authentication to your webhook endpoint.
WebhookAuthorization *string `json:"webhook_authorization" api:"webhook_authorization"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
AudioDownloadParams holds the parameters of AudioDownload (GET / POST /v1/audio/download). Required fields are plain values; optional fields are pointers (use huntapi.String, huntapi.Float, huntapi.Bool) or nil slices and maps.
type BatchResult ¶
BatchResult is the outcome of one Batch item.
func Batch ¶
func Batch[I, T any](ctx context.Context, items []I, concurrency int, task func(ctx context.Context, item I) (T, error)) []BatchResult[T]
Batch runs task for every item with at most concurrency calls in flight (DefaultConcurrency when concurrency <= 0) and returns one result per item, in input order. A failing item never stops the others; items not started when ctx is done get ctx.Err().
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a reusable, concurrency-safe HuntAPI API client.
func NewClient ¶
func NewClient(apiKey string, options *ClientOptions) (*Client, error)
NewClient creates a client. An empty apiKey falls back to the HUNTAPI_API_KEY environment variable.
func (*Client) AudioDownload ¶
func (c *Client) AudioDownload(ctx context.Context, params *AudioDownloadParams, options ...RequestOption) (*Response, error)
AudioDownload — Audio Download. Download audio from a URL via HuntAPI and receive a job id. Credit cost: 1 credit per call.
GET / POST /v1/audio/download
func (*Client) Jobs ¶
func (c *Client) Jobs(ctx context.Context, params *JobsParams, options ...RequestOption) (*Response, error)
Jobs — Jobs. Poll status, progress (0–100), and result of an async HuntAPI job.
GET /v1/jobs/{id}
func (*Client) MediaMetadata ¶
func (c *Client) MediaMetadata(ctx context.Context, params *MediaMetadataParams, options ...RequestOption) (*Response, error)
MediaMetadata — Media Metadata. Extract metadata from a media URL without downloading the file. Credit cost: 1 credit per call.
GET /v1/media/metadata
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method, path string, params map[string]any, options ...RequestOption) (*Response, error)
Request sends any request, including endpoints released after this SDK version. GET parameters travel in the query string; POST parameters travel in a JSON body.
func (*Client) Stats ¶
func (c *Client) Stats(ctx context.Context, params *StatsParams, options ...RequestOption) (*Response, error)
Stats — Stats. Infrastructure health for an engine or endpoint over the last hour. Not scoped to your account or tenant. Enabled per account: HTTP 403 means contact support to activate it.
GET /v1/stats
func (*Client) Usage ¶
Usage — Usage. Retrieve real-time usage statistics and credit balance for your Huntapi account.
GET /v1/usage
func (*Client) VideoDownload ¶
func (c *Client) VideoDownload(ctx context.Context, params *VideoDownloadParams, options ...RequestOption) (*Response, error)
VideoDownload — Video Download. Credit cost: 1 credit per call.
GET / POST /v1/video/download
func (*Client) WaitForJob ¶
func (c *Client) WaitForJob(ctx context.Context, jobID string, options *WaitForJobOptions) (*Response, error)
WaitForJob polls GET /v1/jobs/{id} until the job reaches a terminal status and returns the last response.
type ClientOptions ¶
type ClientOptions struct {
// BaseURL overrides DefaultBaseURL.
BaseURL string
// Timeout bounds each request. Zero uses DefaultTimeout; a negative value disables it.
Timeout time.Duration
// HTTPClient is copied and used for requests. Redirects are never followed.
HTTPClient *http.Client
// Headers are sent with every request.
Headers map[string]string
// MaxRetries overrides the number of retries. Zero uses MaxRetries; a negative value disables retries.
MaxRetries int
// RetryDelay is the delay before the first retry. Zero uses DefaultRetryDelay.
RetryDelay time.Duration
}
ClientOptions configures a Client. The zero value is valid.
type ConfigurationError ¶
ConfigurationError reports a missing or unusable client configuration.
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
func (*ConfigurationError) Unwrap ¶
func (e *ConfigurationError) Unwrap() error
type JobTimeoutError ¶
JobTimeoutError reports an async job that did not finish before the deadline.
func (*JobTimeoutError) Error ¶
func (e *JobTimeoutError) Error() string
type JobsParams ¶
type JobsParams struct {
// Job UUID returned as job_id by async endpoints such as /v1/video/download and /v1/audio/download.
ID string `json:"id" api:"id,required"`
}
JobsParams holds the parameters of Jobs (GET /v1/jobs/{id}). Required fields are plain values; optional fields are pointers (use huntapi.String, huntapi.Float, huntapi.Bool) or nil slices and maps.
type MediaMetadataParams ¶
type MediaMetadataParams struct {
// Media URL to inspect (YouTube, Instagram, TikTok, Vimeo, X, Facebook, Twitch, Reddit, etc.).
Query string `json:"query" api:"query,required"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
MediaMetadataParams holds the parameters of MediaMetadata (GET /v1/media/metadata). Required fields are plain values; optional fields are pointers (use huntapi.String, huntapi.Float, huntapi.Bool) or nil slices and maps.
type RequestOption ¶
type RequestOption func(*requestOptions)
RequestOption customizes one request.
func WithHeader ¶
func WithHeader(name, value string) RequestOption
WithHeader adds a header to one request.
func WithMaxRetries ¶
func WithMaxRetries(n int) RequestOption
WithMaxRetries overrides the number of retries for one request (0 disables them).
func WithMethod ¶
func WithMethod(method string) RequestOption
WithMethod selects GET or POST. Operations default to GET when they support it.
type Response ¶
type Response struct {
StatusCode int
Header http.Header
ContentType string
// Body holds the raw bytes: JSON text, or a file such as an image or PDF.
Body []byte
// IsJSON reports whether the body is JSON (Content-Type application/json or +json).
IsJSON bool
}
Response is a buffered, successful API response.
type ResponseDecodingError ¶
ResponseDecodingError reports a success response that could not be decoded.
func (*ResponseDecodingError) Error ¶
func (e *ResponseDecodingError) Error() string
func (*ResponseDecodingError) Unwrap ¶
func (e *ResponseDecodingError) Unwrap() error
type SerializationError ¶
SerializationError reports a parameter that is missing or cannot be sent.
func (*SerializationError) Error ¶
func (e *SerializationError) Error() string
func (*SerializationError) Unwrap ¶
func (e *SerializationError) Unwrap() error
type StatsParams ¶
type StatsParams struct {
// API family to check, for example video. Provide at least engine or path.
Engine *string `json:"engine" api:"engine"`
// Specific endpoint to check, for example /v1/video/download. If you also pass engine, use an endpoint from that API.
Path *string `json:"path" api:"path"`
}
StatsParams holds the parameters of Stats (GET /v1/stats). Required fields are plain values; optional fields are pointers (use huntapi.String, huntapi.Float, huntapi.Bool) or nil slices and maps.
type TransportError ¶
TransportError reports a failure before a complete HTTP response was received, including client-side timeouts and context cancellation (see Unwrap).
func (*TransportError) Error ¶
func (e *TransportError) Error() string
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error
type VideoDownloadParams ¶
type VideoDownloadParams struct {
// Video URL to download.
Query string `json:"query" api:"query,required"`
// Desired download type. You have three options: Default: "audio_video".
DownloadType *string `json:"download_type" api:"download_type"`
// Maximum duration of the downloaded content in seconds. If the video/audio is longer than this value, only the content up to this duration will be downloaded.
MaxDuration *float64 `json:"max_duration" api:"max_duration"`
// Desired video quality. Available options: Default: "best".
VideoQuality *string `json:"video_quality" api:"video_quality"`
// Desired output format for the video. Available options: Default: "mp4".
VideoFormat *string `json:"video_format" api:"video_format"`
// URL of the webhook where results will be sent. When specified, the system will attempt to send the response to this URL up to 3 times with a 5-second delay between each attempt. The results will be sent as a POST request.
WebhookURL *string `json:"webhook_url" api:"webhook_url"`
// Authorization header for the webhook. This parameter allows you to add authentication to your webhook endpoint. This value will be included in the Authorization header when making the webhook request to your server.
WebhookAuthorization *string `json:"webhook_authorization" api:"webhook_authorization"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
VideoDownloadParams holds the parameters of VideoDownload (GET / POST /v1/video/download). Required fields are plain values; optional fields are pointers (use huntapi.String, huntapi.Float, huntapi.Bool) or nil slices and maps.