Dograh

Voice Agent SDK: Build Voice Agents in Python or TypeScript

Voice Agent SDK: Build Voice Agents in Python or TypeScript
TutorialDecember 1, 2026·9 min read

Voice Agent SDK: Build Voice Agents in Python or TypeScript

Abhishek Kumar
Abhishek Kumar·Co-founder, Dograh AI

Co-founder of Dograh, building the future of open-source voice AI agents. Own your voice AI stack.

A voice agent SDK wraps a voice platform's API in typed methods, so your code can build agents, save drafts and place calls. For developers who want open code, Dograh, the open-source AI voice agent platform, ships dograh-sdk for Python and @dograh/sdk for TypeScript, which work with a self-hosted install or Dograh Cloud.

Key Takeaways

  • A platform SDK configures agents the platform runs, unlike a framework you host.
  • save_workflow saves a draft, so callers hear the old version until you publish.
  • Read call results through Dograh's Runs API with the same dgr_ key.

Here we build a voice agent from code, step by step, in Dograh. We explain what an SDK does and walk through installing both packages, adding a key, building and saving an agent and placing a test call, and we end on reading runs and moving to production.

What you need before you start

These steps follow the published Dograh docs and the SDK READMEs. Run them on a trial server before production. Every SDK sample below comes from those pages, with only the phone number changed.

  • Python 3.10 or newer for the Python package, or Node.js with npm for the TypeScript one.
  • A Dograh account on Dograh Cloud, or a self-hosted install you can reach over HTTPS.
  • A phone provider connected under Telephony, such as Twilio, Telnyx or Plivo, for the test call in Step 6.
  • A phone you can answer during the test.

What a voice agent SDK does

A voice agent SDK turns an API into methods your code calls. SDKs differ in what those methods control, and they come in two kinds.

Framework SDKs put your code inside the call. OpenAI's voice agents guide describes two architectures for its own SDK, speech-to-speech for "Speech, reasoning, and tool use in one session", and a chained pipeline for "Control over each speech and text stage". Either way, your process runs the audio loop, so you also host it, scale it and connect it to a carrier. Our comparison of voice AI frameworks covers that side.

Platform SDKs configure agents that a platform runs. Your code creates or edits an agent, saves it, starts a call and reads the result, while the platform handles the pipeline, the carrier and the call history. The same agent is still visible in a dashboard, so a teammate who does not write code can open it and change a prompt.

Dograh's two packages are platform SDKs. They suit a team that wants agents in version control or generated from its own data, without running the audio loop itself.

Step 1: Install dograh-sdk or @dograh/sdk

Install the package for your language. The Python package is dograh-sdk on PyPI, and the TypeScript one is @dograh/sdk on npm. Both install lines are below.

pip install dograh-sdk
npm install @dograh/sdk

What this does: The first line installs the Python client, which needs Python 3.10 or newer. The second installs the TypeScript client into your Node.js project. You only need the one for your language.

Both packages are generated from the same backend OpenAPI spec, so they expose the same methods, in snake_case for Python and camelCase for TypeScript, as Dograh's SDK introduction explains. A sample in one language translates line by line into the other.

Check: pip show dograh-sdk or npm ls @dograh/sdk prints the installed version.

Step 2: Create an API key and set the base URL

Every SDK call carries an API key. In the dashboard, open Developers in the sidebar, click Create New API Key, name it and click Create Key. The key starts with dgr_ and appears only once, so copy it straight into your secrets store. Our guide to keeping voice AI API keys safe covers storage and rotation.

Both SDKs read the key and the address from environment variables. The block below follows the SDK README's environment section, with the key shown as dgr_... because that is the real prefix.

export DOGRAH_API_URL=https://api.dograh.com
export DOGRAH_API_KEY=dgr_...

What this does: It sets DOGRAH_API_URL to Dograh Cloud's API address and DOGRAH_API_KEY to your key. The client adds /api/v1 to the address and sends the key as the X-API-Key header on every request.

On a self-hosted install, use your own address instead. On the server itself that is http://localhost:8000, the SDK's default. On a remote server it is the public HTTPS address, such as https://voice.yourcompany.com, and our guide to putting your own domain with HTTPS on a self-hosted install sets that up.

Check: client.list_workflows() in Python, or await client.listWorkflows() in TypeScript, returns your agents with their IDs and names.

Dograh

Open Source Alternative to Vapi / Retell

Self-hosted voice agent platform — no per-minute fees

dograh-hq/dograh

Star on GitHub

Step 3: Create the agent and note its ID

The SDK saves onto an agent that already exists, so create one in the dashboard first. Open Voice Agents and click Create Agent. On Dograh Cloud, and on a self-hosted install connected to a free Dograh account, new agents start in the Agent Builder. You can also start from a blank canvas.

Choose Blank Canvas if your code will write every node, since the SDK replaces the agent's nodes and edges when it saves. The agent's ID is the number at the end of the editor's address, /workflow/123, and the samples below use 123.

Check: the agent appears in Voice Agents, and list_workflows returns it with the same ID.

Step 4: Build the agent in code and save a draft

Now write the agent itself. The SDK mirrors the canvas, so you add nodes with add(), join them with edge() and save with save_workflow. The Python sample below comes from Dograh's guide to build an agent with the SDK. Note the type on each node, the condition on each edge and the workflow_id it saves to.

from dograh_sdk import DograhClient, Workflow

with DograhClient(api_key="YOUR_API_KEY") as client:
    wf = Workflow(client=client, name="loan_qualification")

    greeting = wf.add(
        type="startCall",
        name="greeting",
        prompt="You are Sarah from Acme Loans. Greet the caller warmly.",
    )
    qualify = wf.add(
        type="agentNode",
        name="qualify",
        prompt="Ask about loan amount, purpose, and monthly income.",
    )
    done = wf.add(
        type="endCall",
        name="done",
        prompt="Thank them and end the call politely.",
    )

    wf.edge(greeting, qualify, label="interested", condition="Caller wants to continue.")
    wf.edge(qualify, done, label="done", condition="All qualification questions answered.")

    client.save_workflow(workflow_id=123, workflow=wf)

What this does: It builds a three-node loan qualification agent, a startCall greeting, an agentNode that asks the questions and an endCall close, joined by two edges whose condition text tells the agent when to move on. Then it saves the whole thing to agent 123 as a new draft.

The TypeScript version is the same agent with await on each add and an options object on each edge.

import { DograhClient, Workflow } from "@dograh/sdk";

const client = new DograhClient({ apiKey: "YOUR_API_KEY" });
const wf = new Workflow({ client, name: "loan_qualification" });

const greeting = await wf.add({
    type: "startCall",
    name: "greeting",
    prompt: "You are Sarah from Acme Loans. Greet the caller warmly.",
});
const qualify = await wf.add({
    type: "agentNode",
    name: "qualify",
    prompt: "Ask about loan amount, purpose, and monthly income.",
});
const done = await wf.add({
    type: "endCall",
    name: "done",
    prompt: "Thank them and end the call politely.",
});

wf.edge(greeting, qualify, { label: "interested", condition: "Caller wants to continue." });
wf.edge(qualify, done, { label: "done", condition: "All qualification questions answered." });

await client.saveWorkflow(123, wf);

What this does: It saves the same draft from TypeScript. Each add is awaited because the SDK fetches that node type's spec from the backend before it accepts the fields.

That spec fetch is the useful part. The SDK checks every node against the backend's node-spec catalog as you call add(), and the README lists what it stops there, an unknown field such as a typo, a required field that is missing or empty, a value of the wrong type and an option outside the allowed list. The server runs its own checks on save for anything the SDK lets through. To see which node types and fields exist, call client.list_node_types().

Check: the agent in the dashboard shows a new draft with the three nodes, while the published version is unchanged.

Step 5: Edit the agent and publish it

Changes from code follow the same draft rule. Load the agent, change it, then save, as in the edit sample from the build guide.

wf = client.load_workflow(workflow_id=123)
wf.name = "loan_qualification_v2"
client.save_workflow(workflow_id=123, workflow=wf)

What this does: It loads agent 123 into an editable Workflow, renames it and saves the change as another draft. The same pattern edits a prompt or adds a node.

The published version keeps serving calls until you publish the draft. Open the agent in the dashboard and click Publish once the test call in the next step sounds right. Our guide to embedding a voice agent in a SaaS product shows the REST route for publishing when a whole fleet of agents changes from code.

A two-level shelf. Code on a laptop saves a draft agent onto the top shelf, and that draft takes a test call on the developer's own phone. The published agent on the bottom shelf keeps answering callers. A Publish lever beside the shelf moves the draft down, and the new version becomes the live one.
A save from a script leaves callers on the version they already hear, so a half-finished edit stays off the live line. The flip side is that nothing new reaches them until someone hears the test and makes the last click.

Check: after publishing, the editor shows the new version as the live one.

Join the Dograh Community

Dograh is an OSS alternative to Vapi. Join our Slack community for queries, releases, best practices & community interactions.

Step 6: Place a test call from code

Call your own phone with the draft. The sample below comes from Dograh's guide to place an outbound call, with a reserved fictional US number in place of the docs' example. Swap in your own mobile number, written with + and the country code.

from dograh_sdk import DograhClient
from dograh_sdk._generated_models import InitiateCallRequest

with DograhClient(api_key="YOUR_API_KEY") as client:
    client.test_phone_call(
        body=InitiateCallRequest(
            workflow_id=123,
            phone_number="+14155550123",
        )
    )

What this does: It asks Dograh to ring phone_number from agent 123, through the phone provider connected to your account. It is the same request as the Phone Call button in the editor.

In TypeScript the call is await client.testPhoneCall({ body: { workflow_id: 123, phone_number: "+14155550123" } }). This is a test call, and it runs the agent's draft, so you hear the changes from Step 4 before anyone else does. For many calls at once, use Campaigns rather than a loop over test calls, since campaigns handle pacing and retries.

Check: your phone rings and the agent greets you as Sarah from Acme Loans.

Step 7: Read the run with the same key

Every call creates a run, with its status, transcript, recording link and the details the agent gathered. The SDKs cover building and calling, and runs are read through the Runs API with the same key. The two requests below are written from that documented method, path and header.

curl -H "X-API-Key: dgr_..." https://api.dograh.com/api/v1/workflow/123/runs
curl -H "X-API-Key: dgr_..." https://api.dograh.com/api/v1/workflow/123/runs/456

What this does: The first lists every run of agent 123, test calls and live calls alike. The second fetches run 456 in full, including recording_url, transcript_url and the gathered context.

From Python or TypeScript, send the same request with the HTTP client you already use. On a self-hosted install, replace https://api.dograh.com with your own address.

Check: the list includes the test call from Step 6, and its detail shows the transcript.

Before you ship it

Move live calls to the production trigger. A test call runs the draft, while production traffic should call the published agent through its API trigger. Our guide to trigger voice agent calls from an API covers that route and how to pass per-call details.

Keep the key on your server. Build scripts and backends can hold it, while browser code and mobile apps should call your own backend instead. Use one key per environment, so a leaked staging key never touches production agents.

Read the code before you depend on it. Both packages sit in Dograh's main repository, the Python SDK's source and the TypeScript SDK's source, under the BSD 2-Clause license. If you would rather have a coding agent write these calls, Dograh's MCP server lets Claude and other coding agents drive the same operations.

Glossary

Platform SDK
An SDK that configures agents a hosted or self-hosted platform runs, as opposed to a framework SDK whose code runs the audio loop itself.
Draft version
An unpublished version of an agent. save_workflow writes one, test calls run it, and live callers keep hearing the published version until you publish.
Node-spec catalog
The backend's list of node types and their fields. The SDK fetches it and checks every add() call against it before saving.
X-API-Key header
The HTTP header that carries a Dograh API key on every request. The SDKs add it for you, and REST calls set it directly.

Frequently Asked Questions

Get started with Dograh

Build, deploy, and scale AI agents with Dograh. Join the community of developers building the future.