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

> ## Agent Instructions
> Use Stable documentation by default. Honor an explicit Beta request or a URL under /docs/beta/. If the requested version conflicts with the installed CLI package or API origin, clarify the target before writing integration code.
> Pages under /docs/beta/ document Beta; other product pages document Stable. Keep the CLI package, commands, API origin, and credentials within the selected version. State the documentation version in your answer.
> For MCP search, always pass version: Stable or version: Beta. Unfiltered search mixes both versions. For filesystem reads, keep Beta queries under /beta/ and exclude /beta/ from Stable queries; discover paths before reading them.
> The public docs base is https://photon.codes/docs. Convert MCP page paths to public URLs under that base, preserving /beta/ when present. Read https://photon.codes/docs/skill.md for version selection and https://photon.codes/docs/llms.txt for the version indexes.

# Change plan

> Change plan: changePlan in the TypeScript, Python and Rust clients.

`POST /v1/organizations/{organizationId}/billing/projects/{projectId}/purchase`

Purchases or changes the selected project's plan for the supplied category and planCode. A 202 response means the change is pending: poll the returned operation URL and honor Retry-After until it succeeds or fails. A 200 response means the idempotency key resolved to an operation that is already terminal; inspect that result rather than assuming success from the status code alone. Supply the required Idempotency-Key header. Supply both organizationId and projectId to select the project within its organization.

<Tabs>
  <Tab title="TypeScript">
    ```typescript TypeScript theme={null}
    photon.organizations.billing.changePlan(input: ChangePlanInput, options?: RequestOptions): Promise<ChangePlanOutput>
    ```
  </Tab>

  <Tab title="Python">
    ```python Python theme={null}
    photon.organizations.billing.change_plan(input: ChangePlanInput) -> models.TerminalBillingOperation | models.PendingBillingOperation
    ```
  </Tab>

  <Tab title="Rust">
    ```rust Rust theme={null}
    client.change_plan(idempotency_key: String, organization_id: String, project_id: String, body: &types::ChangePlanRequest).await -> Result<ResponseValue<ChangePlanResponse>, Error<ChangePlanError>>
    ```
  </Tab>
</Tabs>

<RequestExample>
  ```typescript TypeScript theme={null}
  import { Photon } from "@photon-ai/api";

  const photon = new Photon({
    headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
  });
  const result = await photon.organizations.billing.changePlan({
    path: {
      organizationId: "organizationId",
      projectId: "projectId",
    },
    headers: {
      idempotencyKey: "idempotencyKey",
    },
    body: {
      category: "category",
      planCode: "planCode",
    },
  });
  ```

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

  from photon_api import Photon
  from photon_api.rpc_generated import ChangePlanInput

  photon = Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_TOKEN']}"})
  result = photon.organizations.billing.change_plan(
      ChangePlanInput.model_validate({
          "path": {
              "organizationId": "organizationId",
              "projectId": "projectId",
          },
          "headers": {
              "Idempotency-Key": "idempotencyKey",
          },
          "body": {
              "category": "category",
              "planCode": "planCode",
          },
      })
  )
  ```

  ```rust Rust theme={null}
  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
      .change_plan(
          "idempotencyKey".to_owned(),
          "organizationId".to_owned(),
          "projectId".to_owned(),
          &serde_json::from_value(serde_json::json!({
              "category": "category",
              "planCode": "planCode",
          }))?,
      )
      .await
      .map_err(|error| format!("{error:?}"))?
      .into_inner();
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "failure": null,
    "kind": "change_plan",
    "operationId": "string",
    "resolvedAt": null,
    "result": {
      "effectiveAt": null,
      "type": "version",
      "version": "string"
    },
    "status": "succeeded",
    "submittedAt": null
  }
  ```

  ```json 202 theme={null}
  {
    "failure": null,
    "kind": "change_plan",
    "operationId": "string",
    "resolvedAt": null,
    "result": null,
    "status": "pending",
    "submittedAt": null
  }
  ```
</ResponseExample>

## Parameters

<ParamField header="Idempotency-Key" type={"string"} required>
  Identifies one logical mutation across retries.
</ParamField>

<ParamField path="organizationId" type={"string"} required />

<ParamField path="projectId" type={"string"} required>
  The project being billed.
</ParamField>

## Body

<ParamField body="category" type={"string"} required>
  Category slug, e.g. analytics or messaging.
</ParamField>

<ParamField body="planCode" type={"string"} required>
  Plan to subscribe to, e.g. analytics\_pro.
</ParamField>

## Returns

**`200`** The idempotency key resolved to an operation that is already terminal. TerminalBillingOperation

**One of: SucceededBillingOperation**

<ResponseField name="failure" type={"null"} required />

<ResponseField name="kind" type={"BillingOperationKind"} required />

<ResponseField name="operationId" type={"string"} required>
  Stable handle for this provisioning action.
</ResponseField>

<ResponseField name="resolvedAt" type={"string | null"} required />

<ResponseField name="result" type={"BillingOperationResult"} required />

<ResponseField name="status" type={"\"succeeded\""} required>
  Terminal. The result is authoritative.
</ResponseField>

<ResponseField name="submittedAt" type={"string | null"} required />

**One of: FailedBillingOperation**

<ResponseField name="failure" type={"BillingOperationFailure"} required />

<ResponseField name="kind" type={"BillingOperationKind"} required />

<ResponseField name="operationId" type={"string"} required>
  Stable handle for this provisioning action.
</ResponseField>

<ResponseField name="resolvedAt" type={"string | null"} required />

<ResponseField name="result" type={"null"} required />

<ResponseField name="status" type={"\"failed\""} required>
  Terminal. Failure contains a stable code and retryability.
</ResponseField>

<ResponseField name="submittedAt" type={"string | null"} required />

**`202`** Plan change accepted. Poll the returned operation until it succeeds or fails. PendingBillingOperation

Headers: `Location`. The raw response carries these headers; see [Raw responses](/docs/beta/api-client/raw-responses).

<ResponseField name="failure" type={"null"} required />

<ResponseField name="kind" type={"BillingOperationKind"} required />

<ResponseField name="operationId" type={"string"} required>
  Stable handle for this provisioning action.
</ResponseField>

<ResponseField name="resolvedAt" type={"null"} required />

<ResponseField name="result" type={"null"} required />

<ResponseField name="status" type={"\"pending\""} required>
  Accepted and still executing. Poll the operation route.
</ResponseField>

<ResponseField name="submittedAt" type={"string | null"} required />


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