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

# Update a user

PATCH https://api.respan.ai/api/users/{customer_identifier}/
Content-Type: application/json

Users are created automatically from usage. Use this endpoint to set budgets or update profile fields after creation.

Reference: https://www.respan.ai/docs/apis/users/update-user

## Authentication

- `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \<RESPAN\_API\_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan\_params.credential\_override in the request body, not in this authentication field.
- `Authorization` header (bearer token, required) — Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead.

## Request

### Path parameters

- `customer_identifier` (string, required) — Your unique identifier for this user.

### Query parameters

- `environment` (enum, optional) — Optional environment filter. If omitted, the backend uses the environment implied by your auth context when applicable.
  - Allowed values: `prod`, `test`

### Body (application/json)

This endpoint expects an object.

- `email` (string, optional, nullable) — User email address.
- `name` (string, optional, nullable) — User display name.
- `metadata` (ApiUsersCustomerIdentifierPatchRequestBodyContentApplicationJsonSchemaMetadata, optional) — Custom key-value metadata.
- `period_budget` (double, optional, nullable) — Spending budget per period in USD.
- `budget_duration` (enum, optional) — Budget renewal period.
  - Allowed values: `daily`, `weekly`, `monthly`
- `total_budget` (double, optional, nullable) — Total lifetime spending budget in USD.
- `period_start` (datetime, optional) — Optional custom budget period start.
- `period_end` (datetime, optional, nullable) — Optional custom budget period end.
- `markup_percentage` (double, optional) — Markup percentage applied to usage reports for this user.

## Response

### 200

Updated user details.

- `id` (string, optional) — User identifier.
- `name` (string, optional, nullable) — User display name.
- `email` (string, optional, nullable) — User email address.
- `customer_identifier` (string, optional) — Your unique identifier for the user.
- `environment` (enum, optional) — User environment.
  - Allowed values: `prod`, `test`
- `total_budget` (double, optional, nullable) — Lifetime spending budget in USD.
- `period_budget` (double, optional, nullable) — Current period budget in USD.
- `organization_name` (string, optional, nullable) — Owning organization name.
- `total_period_usage` (double, optional) — Usage in the current budget period in USD.
- `period_start` (datetime, optional) — Start of the current budget period.
- `period_end` (datetime, optional, nullable) — End of the current budget period.
- `budget_duration` (enum, optional) — Budget renewal period.
  - Allowed values: `daily`, `weekly`, `monthly`
- `updated_at` (datetime, optional) — Last update timestamp.

## Errors

### 400 Bad Request Error

Validation Error

- `map from string to ApiUsersCustomerIdentifierPatchResponsesContentApplicationJsonSchema`

### 403 Forbidden Error

The API key is missing, invalid or expired.

- `detail` (string, required)

### 404 Not Found Error

Not Found

- `detail` (string, optional)

### 429 Too Many Requests Error

Rate Limited

- `detail` (string, optional)

### 500 Internal Server Error

Internal Server Error

- `detail` (string, optional)

## Types

### ApiUsersCustomerIdentifierPatchRequestBodyContentApplicationJsonSchemaMetadata

Custom key-value metadata.

### ApiUsersCustomerIdentifierPatchResponsesContentApplicationJsonSchema

## Examples

**Request**

```json
{
  "name": "Alice",
  "period_budget": 200,
  "budget_duration": "monthly"
}
```

**Response**

```json
{
  "id": "user_123",
  "name": "Alice",
  "email": "john@example.com",
  "customer_identifier": "user_123",
  "environment": "prod",
  "total_budget": 1000,
  "period_budget": 200,
  "organization_name": "Acme Inc",
  "total_period_usage": 45.67,
  "period_start": "2025-12-01T00:00:00Z",
  "period_end": null,
  "budget_duration": "monthly",
  "updated_at": "2025-12-29T10:30:00Z"
}
```

**SDK Code**

```python Users_updateUser_example
import requests

url = "https://api.respan.ai/api/users/customer_identifier/"

querystring = {"environment":"prod"}

payload = {
    "name": "Alice",
    "period_budget": 200,
    "budget_duration": "monthly"
}
headers = {
    "Authorization": "Bearer <respanApiKey>",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript Users_updateUser_example
const url = 'https://api.respan.ai/api/users/customer_identifier/?environment=prod';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <respanApiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"Alice","period_budget":200,"budget_duration":"monthly"}'
};

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

```go Users_updateUser_example
package main

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

func main() {

	url := "https://api.respan.ai/api/users/customer_identifier/?environment=prod"

	payload := strings.NewReader("{\n  \"name\": \"Alice\",\n  \"period_budget\": 200,\n  \"budget_duration\": \"monthly\"\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Authorization", "Bearer <respanApiKey>")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

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

url = URI("https://api.respan.ai/api/users/customer_identifier/?environment=prod")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <respanApiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Alice\",\n  \"period_budget\": 200,\n  \"budget_duration\": \"monthly\"\n}"

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

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

HttpResponse<String> response = Unirest.patch("https://api.respan.ai/api/users/customer_identifier/?environment=prod")
  .header("Authorization", "Bearer <respanApiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Alice\",\n  \"period_budget\": 200,\n  \"budget_duration\": \"monthly\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.respan.ai/api/users/customer_identifier/?environment=prod', [
  'body' => '{
  "name": "Alice",
  "period_budget": 200,
  "budget_duration": "monthly"
}',
  'headers' => [
    'Authorization' => 'Bearer <respanApiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Users_updateUser_example
using RestSharp;

var client = new RestClient("https://api.respan.ai/api/users/customer_identifier/?environment=prod");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <respanApiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Alice\",\n  \"period_budget\": 200,\n  \"budget_duration\": \"monthly\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Users_updateUser_example
import Foundation

let headers = [
  "Authorization": "Bearer <respanApiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Alice",
  "period_budget": 200,
  "budget_duration": "monthly"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/users/customer_identifier/?environment=prod")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```