Cancel operation
Cancel operation: cancelOperation in the TypeScript, Python, Rust and Go clients.
POST /v1/projects/{id}/platforms/operations/{operationId}/cancel
Withdraws a provision that has not been fulfilled yet. This is an operations action rather than a DELETE, because there is nothing to delete: no resource exists until the work commits. Whether it is accepted depends on the resource type — a dedicated iMessage line may sit waiting on inventory for hours and withdrawing costs nothing, while an SMS number is cancellable during inventory waiting and answers 409 once the workflow commits to its first provider order. Campaign assignment and detachment operations cannot be cancelled in any state. Wait for completion before requesting another change; that new change is not a guaranteed rollback. The output-only cancellable field is a snapshot; the cancellation transaction always checks the current phase under a row lock. A cancel that loses the race against the work finishing also answers 409: the resource exists and is billed for, so what you want then is to release it. Nothing is charged for a cancelled provision — billing runs after the work, so there is never anything to refund. Requires the platforms:write permission bound to the project resource in the path.
photon.projects.platforms.cancelOperation(input: CancelOperationInput, options?: RequestOptions): Promise<CancelOperationOutput>photon.projects.platforms.cancel_operation(input: CancelOperationInput, *, options: RequestOptions | None = None) -> models.Operationclient.cancel_operation(id: String, operation_id: String).await -> Result<ResponseValue<types::Operation>, Error<CancelOperationError>>client.Projects.Platforms.CancelOperation(ctx context.Context, params *CancelOperationParams, opts ...RequestOption) (*Operation, error)import { Photon } from "@photon-ai/api";
const photon = new Photon({
headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
});
const result = await photon.projects.platforms.cancelOperation({
path: {
id: "id",
operationId: "operationId",
},
});import os
from photon_api import Photon
from photon_api.rpc_generated import CancelOperationInput
photon = Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_TOKEN']}"})
result = photon.projects.platforms.cancel_operation(
CancelOperationInput.model_validate({
"path": {
"id": "id",
"operationId": "operationId",
},
})
)use photon_ai_api::{Credential, PhotonClientBuilder, SecretString};
let token = std::env::var("PHOTON_API_TOKEN")?;
let client = PhotonClientBuilder::new()
.credential("accountServiceKey", Credential::Bearer(SecretString::from(token)))
.build()?;
let result = client
.cancel_operation("id".to_owned(), "operationId".to_owned())
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();import (
"context"
"os"
photonapi "github.com/photon-hq/api/packages/go"
)
ctx := context.Background()
client := photonapi.NewClient(photonapi.WithAPIKey(os.Getenv("PHOTON_API_TOKEN")))
result, err := client.Projects.Platforms.CancelOperation(ctx, &photonapi.CancelOperationParams{
ID: "id",
OperationID: "operationId",
})
if err != nil {
return err
}
_ = result{
"cancellable": true,
"createdAt": "2026-01-01T00:00:00.000Z",
"detail": {},
"endedAt": "2026-01-01T00:00:00.000Z",
"error": {
"code": "CHARGE_REFUSED",
"remediation": {
"action": "Check the payment method in Billing, then request the purchase again."
},
"status": 402,
"title": "Charge Refused",
"type": "https://photon.codes/docs/problems/charge-refused"
},
"operationId": "string",
"projectId": "string",
"reason": "charge_refused",
"resourceId": "string",
"resourceType": "string",
"startedAt": "2026-01-01T00:00:00.000Z",
"state": "pending",
"type": "resource.provision",
"updatedAt": "2026-01-01T00:00:00.000Z"
}Parameters
Selects the API contract date. Without it, the request is served as 2026-07-01.
Returns
200 The cancelled operation. Operation
Headers: Photon-Version. The raw response carries these headers; see Raw responses.
Why the operation failed: the problem of its code, the same object the endpoint returns when it rejects a request, with the status that rejection would have had (the poll itself answers 200). Every code an operation can end with is a branch below, and the endpoint that starts the operation lists its codes. Branch on code, never on status, and keep a default: a code added after your client was generated arrives as a generic problem with type: about:blank and status: 500. That 500 means this document does not describe the code yet, not that the request failed on our side or that retrying will help.