> This page is for Voice AI Platform.

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

# Rate Chat

POST https://api.hams.ai/ai-agents/{agent_id}/chat/{call_id}/rate
Content-Type: application/json

Reference: https://docs.hams.ai/platform/reference/ai-agents-chat/rate-chat-ai-agents-agent-id-chat-call-id-rate-post

## Authentication

- `X-Secret-Key` header (required) — A secret API key (`sk_...`) for server-to-server calls. The entity is derived from the key.

## Request

### Path parameters

- `call_id` (string, required)
- `agent_id` (string, required)

### Body (application/json)

This endpoint expects a RateChatIn.

- `call_rating` (integer, required) — Rating (0-5)
- `call_rating_comment` (string, optional, nullable) — Optional feedback comment

## Response

### 200

Successful Response

- `any`

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "call_rating": 1
}
```

**SDK Code**

```python
import requests

url = "https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate"

payload = { "call_rating": 1 }
headers = {
    "X-Secret-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate';
const options = {
  method: 'POST',
  headers: {'X-Secret-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"call_rating":1}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate"

	payload := strings.NewReader("{\n  \"call_rating\": 1\n}")

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

	req.Header.Add("X-Secret-Key", "<apiKey>")
	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
require 'uri'
require 'net/http'

url = URI("https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate")

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

request = Net::HTTP::Post.new(url)
request["X-Secret-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"call_rating\": 1\n}"

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.hams.ai/ai-agents/agent_id/chat/call_id/rate")
  .header("X-Secret-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"call_rating\": 1\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate', [
  'body' => '{
  "call_rating": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Secret-Key' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Secret-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"call_rating\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Secret-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["call_rating": 1] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.hams.ai/ai-agents/agent_id/chat/call_id/rate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```