Documentation
¶
Overview ¶
Package capturekit is the official Go SDK for the CaptureKit API (https://www.capturekit.dev).
Capture websites as PNG, JPEG, WebP or PDF, extract their content, or analyse them with AI.
Create one client and reuse it:
client, err := capturekit.NewClient("", nil) // reads CAPTUREKIT_API_KEY
response, err := client.Content(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 AnalyzeParams
- type BatchResult
- type CaptureParams
- type Client
- func (c *Client) Analyze(ctx context.Context, params *AnalyzeParams, options ...RequestOption) (*Response, error)
- func (c *Client) Capture(ctx context.Context, params *CaptureParams, options ...RequestOption) (*Response, error)
- func (c *Client) Content(ctx context.Context, params *ContentParams, options ...RequestOption) (*Response, error)
- func (c *Client) Jobs(ctx context.Context, params *JobsParams, 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) WaitForJob(ctx context.Context, jobID string, options *WaitForJobOptions) (*Response, error)
- func (c *Client) WebsiteCrawler(ctx context.Context, params *WebsiteCrawlerParams, options ...RequestOption) (*Response, error)
- type ClientOptions
- type ConfigurationError
- type ContentParams
- type JobTimeoutError
- type JobsParams
- type RequestOption
- type Response
- type ResponseDecodingError
- type SerializationError
- type StatsParams
- type TransportError
- type WaitForJobOptions
- type WebsiteCrawlerParams
Constants ¶
const ( // DefaultBaseURL is the production API origin. DefaultBaseURL = "https://api.capturekit.dev" // DefaultTimeout bounds every request unless ClientOptions.Timeout says otherwise. DefaultTimeout = 120 * time.Second // APIKeyEnvironmentVariable is read when NewClient receives an empty API key. APIKeyEnvironmentVariable = "CAPTUREKIT_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 AnalyzeParams ¶
type AnalyzeParams struct {
// The URL of the webpage to capture.
URL string `json:"url" api:"url,required"`
// Pass custom response fields to be included in the AI response.
CustomResponse *string `json:"custom_response" api:"custom_response"`
// Add your own instructions to guide the AI’s analysis.
CustomPrompt *string `json:"custom_prompt" api:"custom_prompt"`
// Specify a proxy server to route your request through.
Proxy *string `json:"proxy" api:"proxy"`
// Cache the response. Default: false.
Cache *bool `json:"cache" api:"cache"`
// Cache the response for a custom TTL (in seconds). Default: 2592000.
CacheTTL *float64 `json:"cache_ttl" api:"cache_ttl"`
// 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"`
}
AnalyzeParams holds the parameters of Analyze (GET / POST /v1/analyze). Required fields are plain values; optional fields are pointers (use capturekit.String, capturekit.Float, capturekit.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 CaptureParams ¶
type CaptureParams struct {
// The URL of the webpage to capture. Examples: https://www.amazon.com/s?k=pokemon
URL string `json:"url" api:"url,required"`
// The output format of the screenshot. Allowed values: jpeg, jpg, pdf, png, webp. Default: "png".
Format *string `json:"format" api:"format"`
// The device type to emulate for the screenshot. Allowed values: galaxy_fold4, galaxy_s23, galaxy_s23_ultra, galaxy_s8, huawei_mate_50_pro, huawei_p60_pro, ipad, iphone_12, iphone_13_mini, iphone_13_pro_max, iphone_14_pro, iphone_14_pro_max, iphone_x, pixel_5, pixel_6a, pixel_7_pro, redmi_note_11, re…
Device *string `json:"device" api:"device"`
// Capture the entire page instead of just the visible viewport. Default: false.
FullPage *bool `json:"full_page" api:"full_page"`
// Scroll the page to fully load lazy-loaded elements before capturing a full-page screenshot. Default: false.
FullPageScroll *bool `json:"full_page_scroll" api:"full_page_scroll"`
// Time in milliseconds for scrolling before capturing the full page. Default: 400.
FullPageScrollDuration *float64 `json:"full_page_scroll_duration" api:"full_page_scroll_duration"`
// The width of the browser viewport in pixels. Default: 1280.
ViewportWidth *float64 `json:"viewport_width" api:"viewport_width"`
// The height of the browser viewport in pixels. Default: 1024.
ViewportHeight *float64 `json:"viewport_height" api:"viewport_height"`
// The scale factor for high-resolution screenshots. Default: 1.
ScaleFactor *float64 `json:"scale_factor" api:"scale_factor"`
// Generate images with custom quality settings. Default: "80".
ImageQuality *string `json:"image_quality" api:"image_quality"`
// Capture a specific element on the page instead of the full viewport.
Selector *string `json:"selector" api:"selector"`
// Cache the response. Default: false.
Cache *bool `json:"cache" api:"cache"`
// Cache the response for a custom TTL (in seconds). Default: 2592000.
CacheTTL *float64 `json:"cache_ttl" api:"cache_ttl"`
// A comma-separated list of elements to hide before capturing (e.g., ads, popups).
RemoveSelectors *string `json:"remove_selectors" api:"remove_selectors"`
// Automatically remove cookie banners before capturing. Default: false.
RemoveCookieBanners *bool `json:"remove_cookie_banners" api:"remove_cookie_banners"`
// Automatically remove ads before capturing. Default: false.
RemoveAds *bool `json:"remove_ads" api:"remove_ads"`
// Comma-separated list of resource types to block (e.g., “image,stylesheet,font”). Allowed values: document, eventsource, fetch, font, image, manifest, media, other, script, stylesheet, texttrack, websocket, xhr.
BlockResources *string `json:"block_resources" api:"block_resources"`
// Comma-separated list of URL patterns to block (e.g., “analytics,tracking,advertisement”).
BlockUrls *string `json:"block_urls" api:"block_urls"`
// Delay in seconds before capturing the screenshot. Default: 0.
Delay *float64 `json:"delay" api:"delay"`
// Define when to capture. Allowed values: domcontentloaded, load, networkidle0, networkidle2.
WaitUntil []string `json:"wait_until" api:"wait_until"`
// Wait for a specific element to appear before taking the screenshot.
WaitForSelector *string `json:"wait_for_selector" api:"wait_for_selector"`
// Specify a proxy server to route your request through.
Proxy *string `json:"proxy" api:"proxy"`
// AWS S3 secret access key.
S3SecretKey *string `json:"s3_secret_key" api:"s3_secret_key"`
// AWS S3 access key ID.
S3AccessKeyID *string `json:"s3_access_key_id" api:"s3_access_key_id"`
// The S3 bucket name where the screenshot will be uploaded.
S3Bucket *string `json:"s3_bucket" api:"s3_bucket"`
// The filename for the S3 object (auto-generated if not provided).
S3ObjectKey *string `json:"s3_object_key" api:"s3_object_key"`
// AWS S3 region for storage.
S3Region *string `json:"s3_region" api:"s3_region"`
// Leave this field empty for AWS S3. Only specify a value if required. S3-compatible storage services are supported, for example, use https://<accountId>.r2.cloudflarestorage.com for Cloudflare R2.
StorageEndpoint *string `json:"storage_endpoint" api:"storage_endpoint"`
// Use S3 storage for screenshots. The S3 URL will be returned in the response. Default: false.
S3URL *bool `json:"s3_url" api:"s3_url"`
// 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"`
}
CaptureParams holds the parameters of Capture (GET / POST /v1/capture). Required fields are plain values; optional fields are pointers (use capturekit.String, capturekit.Float, capturekit.Bool) or nil slices and maps.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a reusable, concurrency-safe CaptureKit API client.
func NewClient ¶
func NewClient(apiKey string, options *ClientOptions) (*Client, error)
NewClient creates a client. An empty apiKey falls back to the CAPTUREKIT_API_KEY environment variable.
func (*Client) Analyze ¶
func (c *Client) Analyze(ctx context.Context, params *AnalyzeParams, options ...RequestOption) (*Response, error)
Analyze — Analyze (AI). AI Content API analyzes any webpage and returns AI insights summary, value proposition, features, categories, use cases, and optional contact signals. Credit cost: 1 credit per call.
GET / POST /v1/analyze
func (*Client) Capture ¶
func (c *Client) Capture(ctx context.Context, params *CaptureParams, options ...RequestOption) (*Response, error)
Capture — Capture (Screenshot). Browser-like Screenshot API that captures webpages as PNG/JPEG/WebP or PDF for previews, QA, reporting, monitoring, and archiving no headless setup. Credit cost: 1 credit per call.
GET / POST /v1/capture
func (*Client) Content ¶
func (c *Client) Content(ctx context.Context, params *ContentParams, options ...RequestOption) (*Response, error)
Content — Content. CaptureKit Content API extracts structured webpage data, metadata, links, HTML/Markdown: in one request for SEO, monitoring, indexing and automation. Credit cost: 1 credit per call.
GET / POST /v1/content
func (*Client) Jobs ¶
func (c *Client) Jobs(ctx context.Context, params *JobsParams, options ...RequestOption) (*Response, error)
Jobs — Jobs. Poll the status, progress (0–100) and result of a job started with is_async=true. Polling is free. Poll until status is terminal: CompletedJob, Error, NotFound or BadRequest.
GET /v1/jobs/{id}
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 CaptureKit account.
GET /v1/usage
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.
func (*Client) WebsiteCrawler ¶
func (c *Client) WebsiteCrawler(ctx context.Context, params *WebsiteCrawlerParams, options ...RequestOption) (*Response, error)
WebsiteCrawler — Website Crawler. Website Crawler API fetches raw HTML from any webpage in request mode (no rendering) for fast scraping, audits, monitoring, and link/metadata extraction. Credit cost: 1 credit per call.
GET / POST /v1/website/crawler
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 ContentParams ¶
type ContentParams struct {
// The URL of the webpage to capture.
URL string `json:"url" api:"url,required"`
// Include the raw HTML of the webpage in the response. Default: false.
IncludeHTML *bool `json:"include_html" api:"include_html"`
// Include the Markdown of the webpage in the response. Default: false.
IncludeMarkdown *bool `json:"include_markdown" api:"include_markdown"`
// Include the sitemap of the website in the response. Default: false.
IncludeSitemap *bool `json:"include_sitemap" api:"include_sitemap"`
// Use Defuddle to clean and extract the main content from web pages. This popular library removes unnecessary elements like comments, sidebars, headers, footers, and other non-essential elements, leaving only the primary content. When enabled, the HTML response will be processed through Defuddle befo…
UseDefuddle *bool `json:"use_defuddle" api:"use_defuddle"`
// A comma-separated list of elements to hide before capturing (e.g., ads, popups).
RemoveSelectors *string `json:"remove_selectors" api:"remove_selectors"`
// Automatically remove cookie banners before capturing. Default: false.
RemoveCookieBanners *bool `json:"remove_cookie_banners" api:"remove_cookie_banners"`
// Automatically remove ads before capturing. Default: false.
RemoveAds *bool `json:"remove_ads" api:"remove_ads"`
// Comma-separated list of resource types to block (e.g., “image,stylesheet,font”). Allowed values: document, eventsource, fetch, font, image, manifest, media, other, script, stylesheet, texttrack, websocket, xhr.
BlockResources *string `json:"block_resources" api:"block_resources"`
// Comma-separated list of URL patterns to block (e.g., “analytics,tracking,advertisement”).
BlockUrls *string `json:"block_urls" api:"block_urls"`
// Delay in seconds before capturing the screenshot. Default: 0.
Delay *float64 `json:"delay" api:"delay"`
// Define when to capture. Allowed values: domcontentloaded, load, networkidle0, networkidle2.
WaitUntil []string `json:"wait_until" api:"wait_until"`
// Wait for a specific element to appear before taking the screenshot.
WaitForSelector *string `json:"wait_for_selector" api:"wait_for_selector"`
// Specify a proxy server to route your request through.
Proxy *string `json:"proxy" api:"proxy"`
// Cache the response. Default: false.
Cache *bool `json:"cache" api:"cache"`
// Cache the response for a custom TTL (in seconds). Default: 2592000.
CacheTTL *float64 `json:"cache_ttl" api:"cache_ttl"`
// 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"`
}
ContentParams holds the parameters of Content (GET / POST /v1/content). Required fields are plain values; optional fields are pointers (use capturekit.String, capturekit.Float, capturekit.Bool) or nil slices and maps.
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 {
// The job_id returned by an endpoint called with is_async=true.
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 capturekit.String, capturekit.Float, capturekit.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 capture. Provide at least engine or path.
Engine *string `json:"engine" api:"engine"`
// Specific endpoint to check, for example /v1/capture. 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 capturekit.String, capturekit.Float, capturekit.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 WaitForJobOptions ¶
type WaitForJobOptions struct {
Interval time.Duration
Timeout time.Duration
OnProgress func(job map[string]any)
}
WaitForJobOptions configures WaitForJob. The zero value polls after 3 s, then 1.5x longer each time up to 60 s, for up to 12 hours.
type WebsiteCrawlerParams ¶
type WebsiteCrawlerParams struct {
// A website URL with either the http or https protocol.
Query string `json:"query" api:"query,required"`
// If set to false, do not follow redirects. Default: true.
AllowRedirects *bool `json:"allow_redirects" api:"allow_redirects"`
// If set to true, the response will be the HTML source of the page. Default: false.
ReturnPageSource *bool `json:"return_page_source" api:"return_page_source"`
// 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"`
}
WebsiteCrawlerParams holds the parameters of WebsiteCrawler (GET / POST /v1/website/crawler). Required fields are plain values; optional fields are pointers (use capturekit.String, capturekit.Float, capturekit.Bool) or nil slices and maps.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
binary
command
|
|
|
json
command
|
|
|
request
command
|
|
|
wait-for-job
command
|