> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mitu.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mitu.ai/_mcp/server.

# Cancel a subscription

POST https://api.mitu.ai/v1/subscriptions/{id}/cancel

Cancel a subscription.

Reference: https://docs.mitu.ai/api-reference/subscriptions/cancel-subscription

## Authentication

- `x-api-key` header (required) — Account API key used to authenticate server-side requests. Use the credentials issued for the same environment as the API base URL.

## Servers

- `https://api.mitu.ai` (Production, default)
- `https://sandbox-api.mitu.ai` (Sandbox)

## Request

### Path parameters

- `id` (string, required) — Unique identifier of the resource.

## Response

### 200

Subscription cancelled successfully.

- `message` (string, required)
- `data` (Subscription, required)

## Errors

### 400 Bad Request Error

The request is invalid and could not be processed.

- `message` (string, required) — Human-readable description of the error.

### 401 Unauthorized Error

Authentication failed because the API key is missing or invalid.

- `message` (string, required) — Human-readable description of the error.

### 403 Forbidden Error

The authenticated account is not allowed to perform this action.

- `message` (string, required) — Human-readable description of the error.

### 404 Not Found Error

The requested resource could not be found.

- `message` (string, required) — Human-readable description of the error.

### 409 Conflict Error

The request conflicts with the current state of the resource.

- `message` (string, required) — Human-readable description of the error.

### 422 Unprocessable Entity Error

One or more request fields are invalid.

- `message` (string, required)
- `errors` (list of ValidationErrorDetail, required)

### 429 Too Many Requests Error

Too many requests were sent in a short period.

- `message` (string, required) — Human-readable description of the error.

### 500 Internal Server Error

An unexpected error occurred while processing the request.

- `message` (string, required) — Human-readable description of the error.

## Types

### Subscription

- `id` (string, optional)
- `url` (PayUrl, optional) — The two ways to pay one resource. `checkout` is the page a person opens; `agent` is the 402-protected route an AI agent calls. They are not interchangeable — an agent given the checkout URL receives HTML instead of a payment challenge.
- `subscription_plan_id` (string, optional)
- `status` (enum, optional)
  - Allowed values: `active`, `past_due`, `paused`, `cancelled`, `expired`
- `subscriber_id` (string, optional, nullable)
- `subscriber_type` (enum, optional)
  - Allowed values: `agent`, `user`
- `payment_method` (enum, optional)
  - Allowed values: `mpp_crypto`, `mpp_spt`
- `current_period_start` (datetime, optional)
- `current_period_end` (datetime, optional)
- `next_billing_at` (datetime, optional, nullable)
- `started_at` (datetime, optional, nullable)
- `cancelled_at` (datetime, optional, nullable)
- `ended_at` (datetime, optional, nullable)
- `created_at` (datetime, optional)
- `updated_at` (datetime, optional)

### ValidationErrorDetail

- `field` (string, required) — Field that failed validation.
- `message` (string, required) — Description of the validation problem.

### PayUrl

The two ways to pay one resource. `checkout` is the page a person opens; `agent` is the 402-protected route an AI agent calls. They are not interchangeable — an agent given the checkout URL receives HTML instead of a payment challenge.

- `checkout` (string, required) — The hosted checkout a person opens.
- `agent` (string, required) — The route an AI agent pays programmatically.

## Examples

**Response**

```json
{
  "message": "Subscription retrieved successfully",
  "data": {
    "id": "sub_9c4t6z2vn8kq",
    "subscription_plan_id": "plan_3j8w2q7xr1md",
    "status": "active",
    "subscriber_id": "agt_5m1p8w3ldx7b",
    "subscriber_type": "agent",
    "payment_method": "mpp_crypto",
    "current_period_start": "2026-09-01T00:00:00.000Z",
    "current_period_end": "2026-10-01T00:00:00.000Z",
    "next_billing_at": "2026-10-01T00:00:00.000Z",
    "started_at": "2026-09-01T00:00:00.000Z",
    "cancelled_at": null,
    "ended_at": null,
    "created_at": "2026-09-01T00:00:00.000Z",
    "updated_at": "2026-09-01T00:00:00.000Z"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.mitu.ai/v1/subscriptions/id/cancel"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.mitu.ai/v1/subscriptions/id/cancel';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.mitu.ai/v1/subscriptions/id/cancel"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.mitu.ai/v1/subscriptions/id/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.mitu.ai/v1/subscriptions/id/cancel")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.mitu.ai/v1/subscriptions/id/cancel', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.mitu.ai/v1/subscriptions/id/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.mitu.ai/v1/subscriptions/id/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```