Developers
Full API guide
Run the complete flow with projects, generations, progress checks, downloads, and webhooks. Get setup details, API behavior, responses, and workflows.
This guide expands on the quickstart and walks through most of the Diffio SDK surface. You will create projects, run generations, track progress, download results, list resources, and set up webhooks so your app can react to status changes. If you want the shortest path, start with the Quickstart.
Prerequisites
Before you start, have these ready.
- A Diffio API key with read and write permissions.
- A speech focused audio file, for example sample.wav.
- Python 3.8 or later, or Node 18 or later.
Workflow overview
Projects hold your media. Each project can have one or more generations, and you can download each result.
Polling works for quick tests. For production, use webhooks so Diffio can notify you when a generation completes. See the Webhooks guide.
Using the Diffio SDK
Follow these steps in order, and add each block to the same file. You will create a project, run a generation, wait for completion, and download the restored audio.
- 1
Create an API key
Create an API key in the developer dashboard and store it as a secret. Pass the key on every request using the Authorization header (X-Api-Key and Xi-Api-Key also work).
.envDIFFIO_API_KEY=diffio_live_...TipStore your API key as a managed secret instead of committing it to source control.
- 2
Install the SDK
Install the Diffio Python or Node SDK, then load your API key from an environment file.
Pythonpip install diffio python-dotenvSDK source codeBrowse the SDK repositories on GitHub: diffio-js and diffio-python .
NoteUse Node 18 or later so fetch is available without extra packages.
- 3
Configure the client
Create a file named
full_guide.pyorfull_guide.mjs. Then initialize the client and set global request options like timeouts and retries.Pythonfrom dotenv import load_dotenvfrom diffio import DiffioClient, RequestOptionsimport osload_dotenv()client = DiffioClient( apiKey=os.getenv("DIFFIO_API_KEY"), requestOptions=RequestOptions( timeoutInSeconds=60, maxRetries=2, ),)Per call overridesEvery SDK call accepts
requestOptionsso you can override timeouts, retries, headers, or the API key for a single request. - 4
Create a project
Create a project for your media file. The SDK uploads the file as part of project creation. You can attach optional metadata through
params.Pythonfile_path = "sample.wav"project = client.create_project( filePath=file_path, fileFormat="wav", params={ "source": "full-guide", "notes": "First upload from docs", },) - 5
Create a generation
Start a generation with the model you want. Use
samplingorparamsfor model specific settings.Pythongeneration = client.generations.create( apiProjectId=project.apiProjectId, model="diffio-3.5", sampling={"preset": "balanced"}, params={"tag": "docs"},) - 6
Wait for completion
Poll until the generation completes. The wait helper returns the full progress object.
Pythonprogress = client.generations.wait_for_complete( generationId=generation.generationId, apiProjectId=project.apiProjectId, pollInterval=3.0, timeout=900.0, showProgress=True,)print("Final status:", progress.status)ShortcutYou can combine creation and polling with
client.generations.create_and_waitin Python orclient.generations.createAndWaitin Node. - 7
Download results
Fetch the download URL, then save the restored audio and transcript JSON. Signed URLs expire, so request a new URL if needed.
Pythonclient.generations.download( generationId=generation.generationId, apiProjectId=project.apiProjectId, downloadFilePath="restored.mp3", downloadType="mp3",)client.generations.download( generationId=generation.generationId, apiProjectId=project.apiProjectId, downloadFilePath="transcript.json", downloadType="transcript",)TroubleshootingIf you receive
401Unauthorized, treated as auth error. or403Forbidden, treated as permission error., confirm the API key is valid and has read and write permissions. A402Payment required, billing issue such as paymentFailed. API usage can be blocked until billing is updated. error indicates a billing issue such as a spend limit or apaymentFailedbilling hold. API usage can be blocked until billing is updated. A409Conflict, treated as not ready yet. error indicates the generation is not complete yet, poll progress and retry the download.
Manage projects and generations
Use list endpoints to build dashboards, resume work, or review past generations.
- 1
List projects
Pythonprojects = client.projects.list()for project in projects.projects: print(project.apiProjectId, project.status, project.originalFileName) - 2
List generations in a project
Pythongenerations = client.projects.list_generations( apiProjectId=project.apiProjectId,)for generation in generations.generations: print(generation.generationId, generation.status, generation.modelKey)
Account, keys, and usage
Agent keys and scoped keys can read account settings, manage API keys, and inspect usage when their scopes allow it.
- 1
Read account settings
Pythonsettings = client.account.get_settings()print(settings.account.get("billingPolicy")) - 2
Manage API keys
Pythoncreated_key = client.api_keys.create( label="worker-key", scopes=["projects:read", "projects:write", "generations:read", "generations:write"],)keys = client.api_keys.list()print(created_key.keyId, len(keys.keys)) - 3
Read usage summary
Pythonusage = client.usage.summary()print(usage.usage, usage.billing)
Restore audio in one call
The audio isolation helper creates the project, starts a generation, waits for completion, and downloads the restored audio in one call.
- 1
Restore in one call
Pythonfrom dotenv import load_dotenvfrom diffio import DiffioClientimport osload_dotenv()client = DiffioClient(apiKey=os.getenv("DIFFIO_API_KEY"))file_path = "sample.wav"audio_bytes, info = client.audio_isolation.restore_audio( filePath=file_path, model="diffio-3.5", downloadType="mp3",)if info["error"]: raise SystemExit(info["error"])with open("restored-one-call.mp3", "wb") as handle: handle.write(audio_bytes)MetadataThe helper returns a metadata object with status, errors, and download info you can log or store alongside the result.
Use webhooks for status updates
Webhooks let Diffio notify your service when a generation changes status. This is a condensed walkthrough. For full details, see the Webhooks guide.
- 1
Create a webhook endpoint
Follow the webhook creation steps in the docs, then open the developer dashboard to add your endpoint URL and choose events. Save the signing secret for verification.
Endpoint scopeEach API key owns its own webhook endpoints and signing secrets.
Pythonresult = client.webhooks.configure( mode="live", url="https://example.com/webhooks/diffio", eventTypes=["generation.completed", "generation.failed"], apiKeyId=os.getenv("DIFFIO_API_KEY_ID"),)print(result.webhook) - 2
Verify webhook signatures
Use the Diffio SDK helpers to verify signatures against the raw request body, not a parsed JSON object.
Pythonfrom fastapi import FastAPI, Request, HTTPExceptionfrom diffio import DiffioClientimport osapp = FastAPI()client = DiffioClient(apiKey=os.environ["DIFFIO_API_KEY"])@app.post("/webhooks/diffio")async def diffio_webhook(request: Request): payload = await request.body() try: event = client.webhooks.verify_signature( payload=payload, headers=request.headers, secret=os.environ["DIFFIO_WEBHOOK_SECRET"], ) except Exception: raise HTTPException(status_code=400, detail="Invalid signature") print("Webhook received", event.eventType) return {"ok": True} - 3
Send a test event
Use an Agent key or a scoped key with
webhooks:writeto send a test event and confirm delivery in the portal. If you use an Agent key, pass the targetapiKeyId.Pythonfrom dotenv import load_dotenvfrom diffio import DiffioClientimport osload_dotenv()client = DiffioClient(apiKey=os.getenv("DIFFIO_WEBHOOK_KEY"))result = client.webhooks.send_test_event( eventType="generation.completed", mode="live", apiKeyId=os.getenv("DIFFIO_API_KEY_ID"),)print(result.svixMessageId) - 4
Handle webhook events
When you receive
generation.completed, fetch the download URL and queue any heavy work.Pythonfrom dotenv import load_dotenvfrom diffio import DiffioClientimport osload_dotenv()client = DiffioClient(apiKey=os.getenv("DIFFIO_API_KEY"))def handle_event(event): if event.eventType != "generation.completed": return download = client.generations.get_download( generationId=event.generationId, apiProjectId=event.apiProjectId, downloadType="audio", ) print("Download URL:", download.downloadUrl)Respond quicklyReturn a
200Success, treated as complete. response fast and push heavy work to a queue or background job.
