API2Convert Rust SDK
Official Rust SDK for the API2Convert file-conversion API.
One call uploads (or references a URL), starts the job, polls it to completion and hands you the
result. It is one of the official API2Convert SDKs (PHP, Python, Java, Node.js, Go, Ruby, Rust) that
implement the same language-agnostic contract (docs/SDK_CONTRACT.md) and
version together.
- Blocking / synchronous API (like the Python, Go, Java, Ruby and PHP SDKs).
- Lean dependencies —
reqwest,serde_json,hmac,sha2. - Secure by construction — secret headers never cross a redirect, uploads use the per-job token
(never the account key), and no secret ever appears in an error. See
SECURITY.md.
Install
[]
= "10"
Requires Rust 1.86+ (set by the reqwest dependency tree).
Quickstart
use Api2Convert;
The API key also comes from the API2CONVERT_API_KEY environment variable:
let client = from_env?;
Inputs
convert accepts a local path, a remote URL, in-memory bytes, or a streaming reader. A string
starting with http:// / https:// is treated as a URL (sent as a remote input); anything else is a
local path.
client.convert?; // remote URL
client.convert?; // local path
client.convert?; // bytes
client.convert?; // stream
Conversion options
Target-specific options are a separate map from the SDK controls, so an API option key can never collide with an SDK argument:
use ;
let result = client.convert_with?;
let bytes = result.contents?;
Discover the valid options for a target:
let options = client.options?;
Download password
A password given at conversion time is remembered on the result and applied automatically:
use ;
let result = client.convert_with?;
result.save?; // password applied automatically
Async (start now, download later / via webhook)
use ;
let job = client.convert_async_with?;
println!;
Verify the webhook delivery in your handler (pass the raw request body and the X-Oc-Signature
header):
use Api2Convert;
let event = webhooks.construct_event?;
println!;
Cloud storage
Read an input straight from your own cloud storage (S3, Azure, FTP, Google Cloud) and/or deliver the result back into a bucket. Each per-provider input constructor carries that provider's keys verbatim — flat and lowercase, exactly as the API expects.
use ;
// Input from S3: import the source from a bucket, convert it, save the result locally.
let client = new?;
let input = amazon_s3;
let result = client.convert_cloud?;
result.save?;
Deliver the output to a bucket instead with a generic OutputTarget on the output_target control.
When an output target is set the conversion delivers straight to your storage and produces no
local file, so convert returns the completed job without downloading:
use ;
let target = of
.parameter
.parameter
.credential
.credential;
client.convert_with?;
Credentials ride in the plaintext request body but are redacted everywhere the SDK could surface them
— Debug output and error text mask the whole credentials object to [REDACTED] — and are never
printed.
Errors
Every fallible call returns Result<_, Api2ConvertError>. Match it to react to specific conditions:
use ;
match client.convert
HTTP-error variants expose status(), request_id() (the X-Request-Id) and body().
Full lifecycle control
convert is built on the jobs() resource, which you can drive directly:
use Api2Convert;
use json;
let job = client.jobs.create?;
client.jobs.upload?;
client.jobs.start?;
let job = client.jobs.wait?;
let outputs = client.jobs.outputs?;
Other resources: conversions(), presets(), stats(), contracts().
Configuration
use Duration;
use Api2Convert;
let client = builder
.api_key
.timeout
.max_retries
.poll_interval
.poll_timeout
.build?;
| Knob | Default | Notes |
|---|---|---|
base_url |
https://api.api2convert.com/v2 |
trailing / trimmed |
timeout |
30s | JSON requests; min 1s |
max_retries |
2 | transient failures |
poll_interval |
1s | floored to 500ms |
poll_max_interval |
5s | backoff ceiling |
poll_timeout |
300s | capped at 14400s (4h) |
max_download_bytes |
0 (unlimited) | cap downloaded size |
Examples
One runnable example per documented guide lives in examples/. Each
reads the key from API2CONVERT_API_KEY (and honors API2CONVERT_BASE_URL):
API2CONVERT_API_KEY=<key> cargo
| Example | Guide |
|---|---|
quickstart |
Convert a remote JPG to PNG, fetch the job, download |
convert-files |
Browse the conversions catalog, then convert |
uploading-files |
Upload a local file and convert it |
job-lifecycle |
Drive create → add input → start → wait → outputs |
add-watermark |
Stamp a PNG watermark onto a PDF |
create-thumbnails |
Render a PDF page as a PNG thumbnail |
compress-files |
Compress a JPG |
create-archives |
Pack two files into a ZIP |
create-hashes |
Compute the SHA-256 of a ZIP |
extract-assets |
Extract embedded assets from a DOCX |
file-analysis |
Extract a JPG's metadata as JSON |
compare-files |
SSIM-diff two images |
capture-website |
Screenshot a web page to PNG |
audio-operations |
Transcode WAV to AAC |
image-operations |
Resize a JPG |
webhooks |
Start an async conversion with a callback |
presets |
List saved conversion presets |
statistics |
Fetch monthly usage statistics |
rate-limits |
Inspect the account contract / limits |
authentication |
Verify the key by listing jobs |
Testing
API2CONVERT_API_KEY=<key> cargo
The live conformance suite is the executable twin of the examples above: one live test per guide runs the same operation against the real API and asserts success, plus two negative tests (an unknown target is a typed validation error; a bad key is typed and never leaked).
It runs automatically against the real API on every release tag (see
.github/workflows/live-conformance.yml), so a published version is always
verified end to end.
License
MIT © Qaamgo Media GmbH.