---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress#article
headline: Modify Calls In Progress
description: Learn how to use Twilio Programmable Voice to modify live phone calls and manage call states.
url: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress
inLanguage: en
dateModified: 2026-10-08T15:07:09.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Modify Calls In Progress

Learn to modify live phone calls and change active call execution with Twilio Programmable Voice. To update an active Call resource, send a `POST` request with a Twilio SDK. You can use this guide to send automated notifications, create self-service automation, build inbound and outbound call centers, implement AI or ML transcription, and manage active call sessions.

To learn more about the `Call` resource and state management parameters used in this guide, see [Related reference documentation][].

[All Advanced Programmable Voice features guides](/docs/voice/guides/by-feature-product#advanced-programmable-voice-features)

To control the flow of a Twilio phone call, pass [TwiML][] documents to Twilio through its SDKs. The typical workflow involves passing instruction sets in TwiML documents from your app to Twilio in two ways:

1. Change instructions to Twilio during a call through the `action` parameters of verbs like [`<Gather>`][] and [`<Record>`][].
2. Request a different TwiML document from Twilio with the [`<Redirect>`][] verb.

To change a live phone call outside of the normal Twilio request-response cycle, make a request to the `Call` resource.

## Complete the prerequisites

### Complete the Twilio prerequisites

* [Create a Twilio account][].
* In the *Twilio Console*, create a [compliance profile][1c-comply-docs], then [buy a voice-enabled phone number][1c-buy-tn].
* In the *legacy Console*, [buy a voice-enabled phone number][lc-buy-tn]. Only Messaging-enabled phone numbers need a compliance profile.

### Complete the language prerequisites

Select your programming language and complete the prerequisites:

## Python

* [Install Python 3.3 or later][install-py].
* Install [Flask][] and the [Twilio Python Helper Library][tw-py]. Using [pip][], run the following command:
  ```bash
  pip install flask twilio
  ```
* Install and set up [ngrok][].

## Node.js

* [Install Node.js 20 or later][install-node].
* Install [Express][] with [body-parser][], and the [Twilio Node.js helper library][tw-node]:
  ```bash
  npm install twilio express
  ```
* Install and set up [ngrok][].

## PHP

* [Install PHP 7.2 or later][install-php].
* Install the [Composer][] dependency manager [globally][Composer-global].
* Install the [Twilio PHP Helper Library][tw-php]:
  ```bash
  composer require twilio/sdk
  ```
* Install and set up [ngrok][].

## C# or .NET

* [Install .NET 6 or later][install-net].
* Install the [Twilio C# Helper Library][tw-net].
* Install and set up [ngrok][].

## Java

* [Install Java 8 or later][install-java].
* Install the [Twilio Java Helper Library][tw-java].
* Install [Gradle][install-gradle] or [Maven][install-maven].
* Install and set up [ngrok][].

## Ruby

* [Install Ruby 2.6 or later][install-rb].
* Install [Sinatra][] and the [Twilio Ruby Helper Library][tw-rb]:
  ```bash
  gem install sinatra rackup puma twilio-ruby
  ```
* Install and set up [ngrok][].

### Get credentials and set as environment variables

Extract your credentials from your Twilio account then save these credentials as environment variables.

## Twilio Console

1. Go to the [Twilio Console][1c]. The **Let's get building** page appears.
2. Click **API keys and Auth tokens**. The **API keys & auth tokens** page appears with the **Auth Tokens** tab selected.
3. Scroll to your **Account SID**.
4. Click the copy button next to your **Account SID**.
5. Run the following command, replacing `YOUR_ACCOUNT_SID` with *your* Account SID.

   ## macOS Terminal

   ```bash
   export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
   ```

   ## Windows command line

   ```bash
   setx TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
   ```

   ## PowerShell

   ```bash
   [System.Environment]::SetEnvironmentVariable("TWILIO_ACCOUNT_SID", "YOUR_ACCOUNT_SID", "User")
   ```

   This command creates an environment variable on your development system for your account SID.
6. [Create an API key](/docs/iam/api-keys/keys-in-console) and copy its **SID** and **Secret**.
7. Run the following commands, replacing `YOUR_API_KEY` with your API key SID and `YOUR_API_SECRET` with your API key secret.

   ## macOS Terminal

   ```bash
   export TWILIO_API_KEY=YOUR_API_KEY
   export TWILIO_API_SECRET=YOUR_API_SECRET
   ```

   ## Windows command line

   ```bash
   setx TWILIO_API_KEY=YOUR_API_KEY
   setx TWILIO_API_SECRET=YOUR_API_SECRET
   ```

   ## PowerShell

   ```bash
   [System.Environment]::SetEnvironmentVariable("TWILIO_API_KEY", "YOUR_API_KEY", "User")
   [System.Environment]::SetEnvironmentVariable("TWILIO_API_SECRET", "YOUR_API_SECRET", "User")
   ```

   These commands create environment variables on your development system for your API key SID and secret.

## macOS Terminal

```bash
export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
```

## Windows command line

```bash
setx TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
```

## PowerShell

```bash
[System.Environment]::SetEnvironmentVariable("TWILIO_ACCOUNT_SID", "YOUR_ACCOUNT_SID", "User")
```

## macOS Terminal

```bash
export TWILIO_API_KEY=YOUR_API_KEY
export TWILIO_API_SECRET=YOUR_API_SECRET
```

## Windows command line

```bash
setx TWILIO_API_KEY=YOUR_API_KEY
setx TWILIO_API_SECRET=YOUR_API_SECRET
```

## PowerShell

```bash
[System.Environment]::SetEnvironmentVariable("TWILIO_API_KEY", "YOUR_API_KEY", "User")
[System.Environment]::SetEnvironmentVariable("TWILIO_API_SECRET", "YOUR_API_SECRET", "User")
```

## Legacy Console

1. Go to the [Twilio Console][lc]. The **Get Started with Twilio** page appears.
2. Scroll to the **Account Info** block.
3. Click the copy button next to your **Account SID**.
4. Run the following command, replacing `YOUR_ACCOUNT_SID` with *your* Account SID.

   ## macOS Terminal

   ```bash
   export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
   ```

   ## Windows command line

   ```bash
   set TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
   ```

   ## PowerShell

   ```bash
   $Env:TWILIO_ACCOUNT_SID="YOUR_ACCOUNT_SID"
   ```
5. [Create an API key](/docs/iam/api-keys/keys-in-console) and copy its **SID** and **Secret**.
6. Run the following commands, replacing `YOUR_API_KEY` with your API key SID and `YOUR_API_SECRET` with your API key secret.

   ## macOS Terminal

   ```bash
   export TWILIO_API_KEY=YOUR_API_KEY
   export TWILIO_API_SECRET=YOUR_API_SECRET
   ```

   ## Windows command line

   ```bash
   set TWILIO_API_KEY=YOUR_API_KEY
   set TWILIO_API_SECRET=YOUR_API_SECRET
   ```

   ## PowerShell

   ```bash
   $Env:TWILIO_API_KEY="YOUR_API_KEY"
   $Env:TWILIO_API_SECRET="YOUR_API_SECRET"
   ```

   These commands create environment variables on your development system for your API key SID and secret.

## macOS Terminal

```bash
export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
```

## Windows command line

```bash
set TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
```

## PowerShell

```bash
$Env:TWILIO_ACCOUNT_SID="YOUR_ACCOUNT_SID"
```

## macOS Terminal

```bash
export TWILIO_API_KEY=YOUR_API_KEY
export TWILIO_API_SECRET=YOUR_API_SECRET
```

## Windows command line

```bash
set TWILIO_API_KEY=YOUR_API_KEY
set TWILIO_API_SECRET=YOUR_API_SECRET
```

## PowerShell

```bash
$Env:TWILIO_API_KEY="YOUR_API_KEY"
$Env:TWILIO_API_SECRET="YOUR_API_SECRET"
```

[1c-buy-tn]: https://1console.twilio.com/go?to=/account/__account__/us1/senders-hub/list/phone-numbers/inventory

[lc-buy-tn]: https://console.twilio.com/us1/develop/phone-numbers/manage/search

[Create a Twilio account]: https://www.twilio.com/try-twilio

[Express]: https://expressjs.com

[Flask]: http://flask.pocoo.org

[Composer]: https://getcomposer.org/doc/00-intro.md

[Composer-global]: https://getcomposer.org/doc/00-intro.md#globally

[Sinatra]: http://www.sinatrarb.com

[install-gradle]: https://gradle.org/install

[install-maven]: https://maven.apache.org/install.html

[install-java]: https://www.oracle.com/java/technologies/downloads

[install-node]: https://nodejs.org

[install-php]: http://php.net/manual/en/install.php

[install-py]: https://www.python.org/downloads

[install-rb]: https://www.ruby-lang.org/en/documentation/installation

[install-net]: https://dotnet.microsoft.com/en-us/download

[ngrok]: https://ngrok.com/docs/getting-started

[pip]: https://pip.pypa.io/en/latest

[tw-java]: https://github.com/twilio/twilio-java

[tw-net]: https://github.com/twilio/twilio-csharp

[tw-node]: https://github.com/twilio/twilio-node

[tw-php]: https://github.com/twilio/twilio-php

[tw-py]: https://github.com/twilio/twilio-python

[tw-rb]: https://github.com/twilio/twilio-ruby

[1c-comply-docs]: /docs/trust-hub/registrations/regulatory-compliance

[lc]: https://console.twilio.com

[1c]: https://1console.twilio.com/go?to=/account/__account__

[body-parser]: https://github.com/expressjs/body-parser

## Modify an in-progress Twilio phone call

The `Call` resource request requires the `CallSid` of the ongoing call. To get the `CallSid`, choose one of the following two options:

1. Check the `sid` property in the response from Twilio for an outgoing call request.
2. Check the `CallSid` attribute in TwiML document that Twilio sends to your app acting on an incoming call.

### Update the call instructions

To update a live phone call, pass the [`update` parameter with your `Call` resource request][update-call]. This request instructs Twilio to make an immediate change the TwiML document that Twilio is using in a phone call.

## Python

Python only requires the Twilio Python helper library as noted in the [prerequisites][lang-prereq].

Change an in-progress Call with updated TwiML instructions

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = os.environ["TWILIO_API_KEY"]
api_secret = os.environ["TWILIO_API_SECRET"]
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
client = Client(api_key, api_secret, account_sid)

call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
    twiml="<Response><Say>Ahoy there</Say></Response>"
)

print(call.sid)
```

## Node.js

Beyond Express and the Twilio Node.js helper library as noted in the [prerequisites][lang-prereq], Node.js requires the [body-parser][] middleware.

Change an in-progress Call with updated TwiML instructions

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;
const client = twilio(apiKey, apiSecret, { accountSid: accountSid });

async function updateCall() {
  const call = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({ twiml: "<Response><Say>Ahoy there</Say></Response>" });

  console.log(call.sid);
}

updateCall();
```

## PHP

PHP only requires the Twilio PHP helper library as noted in the [prerequisites][lang-prereq].

Change an in-progress Call with updated TwiML instructions

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
$apiKey = $_ENV["TWILIO_API_KEY"];
$apiSecret = $_ENV["TWILIO_API_SECRET"];
$sid = $_ENV["TWILIO_ACCOUNT_SID"];
$twilio = new Client($apiKey, $apiSecret, $sid);

$call = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(["twiml" => "<Response><Say>Ahoy there</Say></Response>"]);

print $call->sid;
```

## C# or .NET

C# requires the .NET 6 framework and the Twilio C# helper library as noted in the [prerequisites][lang-prereq].

Change an in-progress Call with updated TwiML instructions

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID at twilio.com/console
        // Provision API Keys at twilio.com/console/runtime/api-keys
        // and set the environment variables. See http://twil.io/secure
        // For local testing, you can use your Account SID and Auth token
        string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY");
        string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET");
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");

        TwilioClient.Init(apiKey, apiSecret, accountSid);

        var call = await CallResource.UpdateAsync(
            twiml: new Twilio.Types.Twiml("<Response><Say>Ahoy there</Say></Response>"),
            pathSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(call.Sid);
    }
}
```

## Java

Java requires Gradle or Maven and the Twilio Java helper library as noted in the [prerequisites][lang-prereq].

Change an in-progress Call with updated TwiML instructions

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.type.Twiml;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
    // Find your Account SID at twilio.com/console
    // Provision API Keys at twilio.com/console/runtime/api-keys
    // and set the environment variables. See http://twil.io/secure
    // For local testing, you can use your Account SID and Auth token
    public static final String API_KEY = System.getenv("TWILIO_API_KEY");
    public static final String API_SECRET = System.getenv("TWILIO_API_SECRET");
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");

    public static void main(String[] args) {
        Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
        Call call = Call.updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                        .setTwiml(new com.twilio.type.Twiml("<Response><Say>Ahoy there</Say></Response>"))
                        .update();

        System.out.println(call.getSid());
    }
}
```

## Ruby

Ruby requires Sinatra and the Twilio Ruby helper library as noted in the [prerequisites][lang-prereq].

Change an in-progress Call with updated TwiML instructions

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = ENV['TWILIO_API_KEY']
api_secret = ENV['TWILIO_API_SECRET']
account_sid = ENV['TWILIO_ACCOUNT_SID']
@client = Twilio::REST::Client.new(api_key, api_secret, account_sid)

call = @client
       .api
       .v2010
       .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
       .update(twiml: '<Response><Say>Ahoy there</Say></Response>')

puts call.sid
```

#### View the example response

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "answered_by": null,
  "api_version": "2010-04-01",
  "caller_name": null,
  "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
  "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
  "direction": "inbound",
  "duration": "15",
  "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
  "forwarded_from": "+141586753093",
  "from": "+14158675308",
  "from_formatted": "(415) 867-5308",
  "group_sid": null,
  "parent_call_sid": null,
  "phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "price": "-0.03000",
  "price_unit": "USD",
  "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
  "status": "completed",
  "subresource_uris": {
    "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
    "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
    "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
    "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
    "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
    "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
    "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
    "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
    "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
  },
  "to": "+14158675309",
  "to_formatted": "(415) 867-5309",
  "trunk_sid": null,
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
  "queue_time": "1000"
}
```

### Redirect the Call to another URL

You can choose to redirect a `Call` to another URL that responds with your requested TwiML.

## Python

Python only requires the Twilio Python helper library as noted in the [prerequisites][lang-prereq].

Redirect an in progress Call to another URL

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = os.environ["TWILIO_API_KEY"]
api_secret = os.environ["TWILIO_API_SECRET"]
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
client = Client(api_key, api_secret, account_sid)

call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
    method="POST", url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)
```

## Node.js

Beyond Express and the Twilio Node.js helper library as noted in the [prerequisites][lang-prereq], Node.js requires the [body-parser][] middleware.

Redirect an in progress Call to another URL

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;
const client = twilio(apiKey, apiSecret, { accountSid: accountSid });

async function updateCall() {
  const call = await client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update({
    method: "POST",
    url: "http://demo.twilio.com/docs/voice.xml",
  });

  console.log(call.sid);
}

updateCall();
```

## PHP

PHP only requires the Twilio PHP helper library as noted in the [prerequisites][lang-prereq].

Redirect an in progress Call to another URL

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
$apiKey = $_ENV["TWILIO_API_KEY"];
$apiSecret = $_ENV["TWILIO_API_SECRET"];
$sid = $_ENV["TWILIO_ACCOUNT_SID"];
$twilio = new Client($apiKey, $apiSecret, $sid);

$call = $twilio->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")->update([
    "method" => "POST",
    "url" => "http://demo.twilio.com/docs/voice.xml",
]);

print $call->sid;
```

## C# or .NET

C# requires the .NET 6 framework and the Twilio C# helper library as noted in the [prerequisites][lang-prereq].

Redirect an in progress Call to another URL

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID at twilio.com/console
        // Provision API Keys at twilio.com/console/runtime/api-keys
        // and set the environment variables. See http://twil.io/secure
        // For local testing, you can use your Account SID and Auth token
        string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY");
        string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET");
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");

        TwilioClient.Init(apiKey, apiSecret, accountSid);

        var call = await CallResource.UpdateAsync(
            method: Twilio.Http.HttpMethod.Post,
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            pathSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(call.Sid);
    }
}
```

## Java

Java requires Gradle or Maven and the Twilio Java helper library as noted in the [prerequisites][lang-prereq].

Redirect an in progress Call to another URL

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
import com.twilio.http.HttpMethod;

public class Example {
    // Find your Account SID at twilio.com/console
    // Provision API Keys at twilio.com/console/runtime/api-keys
    // and set the environment variables. See http://twil.io/secure
    // For local testing, you can use your Account SID and Auth token
    public static final String API_KEY = System.getenv("TWILIO_API_KEY");
    public static final String API_SECRET = System.getenv("TWILIO_API_SECRET");
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");

    public static void main(String[] args) {
        Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
        Call call = Call.updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                        .setMethod(HttpMethod.POST)
                        .setUrl(URI.create("http://demo.twilio.com/docs/voice.xml"))
                        .update();

        System.out.println(call.getSid());
    }
}
```

## Ruby

Ruby requires Sinatra and the Twilio Ruby helper library as noted in the [prerequisites][lang-prereq].

Redirect an in progress Call to another URL

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = ENV['TWILIO_API_KEY']
api_secret = ENV['TWILIO_API_SECRET']
account_sid = ENV['TWILIO_ACCOUNT_SID']
@client = Twilio::REST::Client.new(api_key, api_secret, account_sid)

call = @client
       .api
       .v2010
       .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
       .update(
         method: 'POST',
         url: 'http://demo.twilio.com/docs/voice.xml'
       )

puts call.sid
```

#### View the example response

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "answered_by": null,
  "api_version": "2010-04-01",
  "caller_name": null,
  "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
  "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
  "direction": "inbound",
  "duration": "15",
  "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
  "forwarded_from": "+141586753093",
  "from": "+14158675308",
  "from_formatted": "(415) 867-5308",
  "group_sid": null,
  "parent_call_sid": null,
  "phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "price": "-0.03000",
  "price_unit": "USD",
  "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
  "status": "completed",
  "subresource_uris": {
    "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
    "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
    "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
    "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
    "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
    "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
    "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
    "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
    "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
  },
  "to": "+14158675309",
  "to_formatted": "(415) 867-5309",
  "trunk_sid": null,
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
  "queue_time": "1000"
}
```

## Hanging up a call in progress

When Twilio encounters a [`<Hangup>`][] verb or runs out of TwiML documents to process, Twilio ends your phone call. To end a phone call by your choice, pass a `completed` status to a `CallSid` in progress.

## Python

Python only requires the Twilio Python helper library as noted in the [prerequisites][lang-prereq].

Terminate a Running Call

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = os.environ["TWILIO_API_KEY"]
api_secret = os.environ["TWILIO_API_SECRET"]
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
client = Client(api_key, api_secret, account_sid)

call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
    status="completed"
)

print(call.to)
```

## Node.js

Beyond Express and the Twilio Node.js helper library as noted in the [prerequisites][lang-prereq], Node.js requires the [body-parser][] middleware.

Terminate a Running Call

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;
const client = twilio(apiKey, apiSecret, { accountSid: accountSid });

async function updateCall() {
  const call = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({ status: "completed" });

  console.log(call.to);
}

updateCall();
```

## PHP

PHP only requires the Twilio PHP helper library as noted in the [prerequisites][lang-prereq].

Terminate a Running Call

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID at twilio.com/console
// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See http://twil.io/secure
// For local testing, you can use your Account SID and Auth token
$apiKey = $_ENV["TWILIO_API_KEY"];
$apiSecret = $_ENV["TWILIO_API_SECRET"];
$sid = $_ENV["TWILIO_ACCOUNT_SID"];
$twilio = new Client($apiKey, $apiSecret, $sid);

$call = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(["status" => "completed"]);

print $call->to;
```

## C# or .NET

C# requires the .NET 6 framework and the Twilio C# helper library as noted in the [prerequisites][lang-prereq].

Terminate a Running Call

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID at twilio.com/console
        // Provision API Keys at twilio.com/console/runtime/api-keys
        // and set the environment variables. See http://twil.io/secure
        // For local testing, you can use your Account SID and Auth token
        string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY");
        string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET");
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");

        TwilioClient.Init(apiKey, apiSecret, accountSid);

        var call = await CallResource.UpdateAsync(
            status: CallResource.UpdateStatusEnum.Completed,
            pathSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(call.To);
    }
}
```

## Java

Java requires Gradle or Maven and the Twilio Java helper library as noted in the [prerequisites][lang-prereq].

Terminate a Running Call

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
    // Find your Account SID at twilio.com/console
    // Provision API Keys at twilio.com/console/runtime/api-keys
    // and set the environment variables. See http://twil.io/secure
    // For local testing, you can use your Account SID and Auth token
    public static final String API_KEY = System.getenv("TWILIO_API_KEY");
    public static final String API_SECRET = System.getenv("TWILIO_API_SECRET");
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");

    public static void main(String[] args) {
        Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
        Call call = Call.updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").setStatus(Call.UpdateStatus.COMPLETED).update();

        System.out.println(call.getTo());
    }
}
```

## Ruby

Ruby requires Sinatra and the Twilio Ruby helper library as noted in the [prerequisites][lang-prereq].

Terminate a Running Call

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
# For local testing, you can use your Account SID and Auth token
api_key = ENV['TWILIO_API_KEY']
api_secret = ENV['TWILIO_API_SECRET']
account_sid = ENV['TWILIO_ACCOUNT_SID']
@client = Twilio::REST::Client.new(api_key, api_secret, account_sid)

call = @client
       .api
       .v2010
       .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
       .update(status: 'completed')

puts call.to
```

#### View the example response

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "answered_by": null,
  "api_version": "2010-04-01",
  "caller_name": null,
  "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
  "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
  "direction": "inbound",
  "duration": "15",
  "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
  "forwarded_from": "+141586753093",
  "from": "+14158675308",
  "from_formatted": "(415) 867-5308",
  "group_sid": null,
  "parent_call_sid": null,
  "phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "price": "-0.03000",
  "price_unit": "USD",
  "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
  "status": "completed",
  "subresource_uris": {
    "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
    "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
    "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
    "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
    "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
    "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
    "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
    "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
    "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
  },
  "to": "+14158675309",
  "to_formatted": "(415) 867-5309",
  "trunk_sid": null,
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
  "queue_time": "1000"
}
```

## Use cases for modifying live calls with Twilio Programmable Voice

This guide teaches the basics required for the following use cases:

### Notifications with Twilio Programmable Voice

You can use this guide to dynamically manage automated broadcast or alert calls while they are in progress. For example, you can programmatically redirect a notification call to a live agent queue if a customer requests immediate assistance, or terminate a call early once an urgent message has been acknowledged.
To learn more advanced features that you can use with notifications, see [Voice notifications][].

### Create self-service automation with Twilio Programmable Voice

Together with your IVR workflows, you can use this guide to interrupt automated self-service paths based on real-time events. Seamlessly break a caller out of an automated data-gathering script if they request a human agent, or modify the call's direction dynamically when a backend database updates during the session.
To learn more advanced features that you can use with self-service automation, see [Voice self-service automation][].

### Build inbound call centers with Twilio Programmable Voice

You can use this guide to implement essential call center features like warm transfers, supervisor barge-ins, and call holds. Modify active calls to pull customers out of queues as agents become available, bridge multiple parties together, or redirect callers to different departments based on live agent availability.
To learn more advanced features that you can use with inbound call centers, see [Voice inbound call centers][].

### Implement AI or ML transcription with Twilio Programmable Voice

Together with Twilio live audio streaming, you can use this guide to control transcription services dynamically during a conversation. Programmatically start or stop transcription streams to protect user privacy when sensitive information is being spoken, or inject new routing rules into a call based on live keywords detected by your transcription engine.
To learn more advanced features that you can use with AI or ML transcription, see [Voice AI and ML transcription][].

### Build AI agents with Twilio Programmable Voice

You can use this guide to manage interactions between human callers and autonomous voice bots in real time. Create human-in-the-loop takeover mechanisms that instantly intercept an active call and redirect it to a human supervisor if the AI agent detects frustration or encounters a complex request.
To learn more advanced features that you can use with AI agents, see [Voice AI agents][].

### Build outbound call centers with Twilio Programmable Voice

You can use this guide to optimize live outbound interactions and agent utilization. Instantly modify the path of an outbound call to play a prerecorded message the moment an answering machine is detected, or dynamically shift active outbound legs between agent tiers based on shifting campaign priorities.
To learn more advanced features that you can use with outbound call centers, see [Voice outbound call centers][].

### Build sales dialers with Twilio Programmable Voice

You can use this guide to power advanced click-to-talk workflows and lead response systems. Initiate a call to a sales representative first, and then dynamically modify that call in progress to dial and bridge the prospect the exact moment the agent goes off-hook and is ready to talk.
To learn more advanced features that you can use with sales dialers, see [Voice sales dialers][].

### Build call tracking with Twilio Programmable Voice

You can use this guide to control proxy routing and number masking on active lines. Modify live call parameters to dynamically mask phone numbers for privacy, track campaign attribution data mid-flight, or update routing metrics as a call moves through various marketing touchpoints.
To learn more advanced features that you can use with call tracking, see [Voice call tracking][].

## Result

After following this guide, you can programmatically modify live phone calls using Twilio Programmable Voice and the Twilio SDKs. You will have built code that can dynamically update call directions or explicitly update the call status to complete active sessions on your account.

## Next steps

Explore the following guides to build on what you've learned in this guide:

* [Make outbound phone calls][]: Learn how to spin up completely new outbound calls from your web app.
* [Respond to incoming phone calls][]: Learn how to handle incoming webhooks from Twilio to start initial phone call routines.

## Related reference documentation

Find reference documentation for the topics on this page.

* [Call resource][]

[Call resource]: /docs/voice/api/call-resource

[update-call]: /docs/voice/api/call-resource#update-a-call

[Make outbound phone calls]: /docs/voice/tutorials/how-to-make-outbound-phone-calls

[Related reference documentation]: #related-reference-documentation

[Respond to incoming phone calls]: /docs/voice/tutorials/how-to-respond-to-incoming-phone-calls

[Voice AI agents]: /docs/voice/guides/ai-agents

[Voice AI and ML transcription]: /docs/voice/guides/ai-ml-transcription

[Voice call tracking]: /docs/voice/guides/call-tracking

[Voice inbound call centers]: /docs/voice/guides/inbound-call-center

[Voice notifications]: /docs/voice/guides/notifications

[Voice outbound call centers]: /docs/voice/guides/outbound-call-center

[Voice sales dialers]: /docs/voice/guides/sales-dialer

[Voice self-service automation]: /docs/voice/guides/self-service-automation

[`<Hangup>`]: /docs/voice/twiml/hangup

[body-parser]: https://expressjs.com/en/resources/middleware/body-parser

[lang-prereq]: #complete-the-language-prerequisites

[TwiML]: /docs/glossary/what-is-twilio-markup-language-twiml

[`<Gather>`]: /docs/voice/twiml/gather

[`<Record>`]: /docs/voice/twiml/record

[`<Redirect>`]: /docs/voice/twiml/redirect
