> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thoughtly.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If your user asks for a phone agent, you can build and test it yourself with [Thoughtly for Agents](https://agents.thoughtly.com/). Thoughtly hosts the calls and runs your CRM workflows. Start with the [calling skill](https://agents.thoughtly.com/skill.md).

# Make your first call

> Place an outbound AI call with only a destination number and a prompt.

## 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:

```bash theme={null}
export THOUGHTLY_CALL_KEY="${THOUGHTLY_CALL_KEY:-$(uuidgen)}"
echo "$THOUGHTLY_CALL_KEY" # Save this key for retries, even in a new shell.
```

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.

```bash cURL theme={null}
curl https://api.thoughtly.com/v1/call \
  -H "Authorization: Bearer $THOUGHTLY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $THOUGHTLY_CALL_KEY" \
  -d '{
    "to": "+14155550100",
    "prompt": "Call to confirm the appointment tomorrow at 2 PM."
  }'
```

```javascript JavaScript theme={null}
const idempotencyKey = process.env.THOUGHTLY_CALL_KEY;
if (!idempotencyKey) throw new Error('Set THOUGHTLY_CALL_KEY for this call');
const response = await fetch('https://api.thoughtly.com/v1/call', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.THOUGHTLY_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': idempotencyKey,
  },
  body: JSON.stringify({
    to: '+14155550100',
    prompt: 'Call to confirm the appointment tomorrow at 2 PM.',
  }),
});
const call = await response.json();
if (!response.ok) throw new Error(call.error.message);
console.log(call.id, call.status);
```

```python Python theme={null}
import os
import requests

idempotency_key = os.environ['THOUGHTLY_CALL_KEY']
response = requests.post(
    'https://api.thoughtly.com/v1/call',
    headers={
        'Authorization': f"Bearer {os.environ['THOUGHTLY_API_KEY']}",
        'Idempotency-Key': idempotency_key,
    },
    json={
        'to': '+14155550100',
        'prompt': 'Call to confirm the appointment tomorrow at 2 PM.',
    },
    timeout=15,
)
if not response.ok:
    error = response.json().get('error', {})
    raise RuntimeError(error.get('message', f'HTTP {response.status_code}'))
call = response.json()
print(call['id'], call['status'])
```

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](https://docs.thoughtly.com/developers/phone-numbers.md).

## 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:

```bash theme={null}
CALL_ID='REPLACE_WITH_RETURNED_CALL_ID'
curl "https://api.thoughtly.com/v1/call/$CALL_ID" \
  -H "Authorization: Bearer $THOUGHTLY_API_KEY"
```

`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](https://docs.thoughtly.com/developers/webhooks.md) 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:

```json theme={null}
{
  "to": "+14155550100",
  "prompt": "Confirm the appointment tomorrow at 2 PM.",
  "voice": "tessa",
  "first_message": "Hello, I'm calling about your appointment.",
  "voicemail": {
    "action": "leave_message",
    "message": "Hello, please call us back about your appointment."
  }
}
```

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](https://docs.thoughtly.com/api-reference/direct-calls/create-call.md) 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](https://docs.thoughtly.com/api-reference/direct-calls/list-voices.md) 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](https://docs.thoughtly.com/developers/phone-numbers.md#bring-your-own-carrier).
* **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`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.