Skip to main content

Before you begin

Direct API access is enabled per workspace. Contact Thoughtly support to request access for your workspace. Create an API token in Settings → Developer with calls:write and calls:read permissions. Set it as THOUGHTLY_API_KEY in your server environment. Choose a number you are authorized to call, in E.164 format, such as +14155550100. The Python example uses the requests package.

Place a call

The two required fields are to and prompt. Create a key for this call and save it before sending the request:
Reuse the same key and request for retries. Within 24 hours, this returns the existing call’s current state, with Idempotency-Replayed: true in the response. After 24 hours, reusing the key can create a new call. To place another call, even to the same number, run unset THOUGHTLY_CALL_KEY and create a new key.
A successful request returns 202 Accepted with the call ID and a queued status. Acceptance means the call is queued, not that the recipient answered. When your workspace has no phone numbers, the call uses the same shared number as Call me. If you have a default outbound number, that number is used; if it cannot place direct calls, the API returns 400 instead of choosing another number. With one available number and no default, it is selected automatically; with several and no default, set a default or provide from. See Phone numbers.

Get the result

Use the returned ID to retrieve the current status, transcript, summary, recording URL, and voicemail result. Some artifacts may become available after the call ends. Set CALL_ID to the id returned by the create request:
created_at is when the request was accepted. started_at is null until the voice session starts; ended_at is set when a terminal outcome is recorded. Answering-machine detection is best effort. A carrier can mistake voicemail for a person, so voicemail can be null even when a mailbox answered. You can also receive a signed webhook when the call finishes.

Customize the call

Add options only when you need them. For example, choose a voice and leave a message if the recipient’s voicemail answers:
With leave_message, the assistant waits for answering-machine detection before processing the recipient’s first words. If the carrier reports an inconclusive or unrecognized result, or sends no result within max_wait_seconds plus three seconds, the conversation continues with buffered audio. When the assistant speaks first, audio from before its greeting starts can be discarded; if interruptions during the first message are disabled, speech during the protected opening is also discarded. A voicemail greeting can also be treated as a caller if the carrier mistakenly identifies the mailbox as a person. By default, the assistant speaks first in English, callers can interrupt, the call rings for up to 30 seconds, the maximum call duration is 10 minutes, and the agent hangs up when voicemail is detected. The workspace’s call-duration limit may shorten the requested maximum. The voicemail result is null unless a voicemail result has been recorded. See Create a call for language, transcription, interruption, timeout, and webhook options. Reuse the same idempotency key and request body when retrying a call; generate a new key for each new call. Marin is available only to workspaces with access to OpenAI Live and requires the auto transcriber. Choosing another transcriber with Marin returns 400 VALIDATION_ERROR before dialing. Use List voices to see whether Marin is available.

Troubleshooting

  • 401 or 403: Check that your token is valid and has the required scopes. A 403 can also mean the recipient is suppressed, outbound calling is disabled, the workspace has insufficient credits, or business verification is required for an international call; address the reported condition before retrying.
  • 400 when placing a call: If the error says Answering-machine detection is unavailable for this workspace, contact support. Check that from or the default is an available outbound number, or set a default when several numbers are available. If a Telnyx carrier number is missing its webhook public key, add the key with a carrier import.
  • 202 with a queued call: The request was accepted; use the call ID or a webhook to learn the outcome.
  • 429: The workspace has reached its limit for direct calls that are active or waiting. Retry after an existing direct call finishes; no new call was created.
  • unknown call status: The carrier may have received the call, but its result could not yet be confirmed. Continue checking the same call ID; do not create a new call to retry it. If no terminal carrier event arrives by the maximum duration plus the ring timeout and 15 minutes, the call is marked failed and its completion webhook is sent.
  • 503: Direct calling is unavailable can mean access has not been enabled for your workspace; contact support. For a dispatch error, check the call ID or retry the identical request with the same idempotency key. If you did not supply a key and the error includes retry_idempotency_key, use that value in the Idempotency-Key header for the retry; it expires after 24 hours. Otherwise, without a key, retry only if the error says the call was not placed. If a queued call reaches the dial worker more than five minutes after creation, it is marked failed rather than dialed late.
  • A timeout or temporary error: Retry the identical request with the same idempotency key. A different body with that key returns 409.