Skip to main content
PATCH
https://api.keywordsai.co
/
api
/
request-logs
/
{unique_id}
import requests

unique_id = "log_abc123..."  # Replace with actual log ID
url = f"https://api.keywordsai.co/api/request-logs/{unique_id}/"

headers = {
    "Authorization": f"Bearer {YOUR_KEYWORDS_AI_API_KEY}",
    "Content-Type": "application/json"
}

data = {
    "metadata": {
        "user_feedback": "helpful",
        "quality_rating": 5
    },
    "custom_identifier": "ticket_12345"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())
{
  "id": "log_abc123...",
  "unique_id": "log_abc123...",
  "organization_id": "org_xyz789",
  "environment": "prod",
  "timestamp": "2025-12-26T10:30:00Z",
  "start_time": "2025-12-26T10:29:58Z",
  "log_type": "chat",
  "model": "gpt-4o-mini",
  "cost": 0.000705,
  "latency": 1.234,
  "status": "success",
  "custom_identifier": "ticket_12345",
  "metadata": {
    "user_feedback": "helpful",
    "quality_rating": 5,
    "previous_metadata_key": "previous_value"
  },
  "input": "[{\"role\":\"user\",\"content\":\"Hello\"}]",
  "output": "{\"role\":\"assistant\",\"content\":\"Hi there!\"}",
  // ... rest of log fields
}
The Update Log endpoint allows you to modify specific fields of a single log. This is useful for adding annotations, updating metadata, or correcting information.
For updating multiple logs at once, use the Batch Update endpoint.

Updatable fields

The following fields can be updated:
  • metadata - Custom metadata properties
  • custom_identifier - Custom identifier
  • blurred - Privacy flag to blur log content

Core log data is immutable

Fields like input, output, log_type, model, usage, cost, latency, and other telemetry fields cannot be modified to maintain data integrity.

Path parameters

unique_id
string
required
The unique ID of the log to update. You can get this from the List Logs endpoint.

Body parameters

metadata
object
Update the log’s metadata with custom properties. This can be used for tagging, categorization, or adding context.
{
  "metadata": {
    "user_feedback": "helpful",
    "quality_rating": 5,
    "reviewed": true,
    "reviewer": "[email protected]"
  }
}
custom_identifier
string
Update the log’s custom identifier. Useful for linking logs to external systems.
{
  "custom_identifier": "ticket_12345_resolved"
}
blurred
boolean
Set whether the log content should be blurred for privacy reasons.
{
  "blurred": true
}

Response

Returns the complete updated log object (same structure as the Get Log endpoint).
import requests

unique_id = "log_abc123..."  # Replace with actual log ID
url = f"https://api.keywordsai.co/api/request-logs/{unique_id}/"

headers = {
    "Authorization": f"Bearer {YOUR_KEYWORDS_AI_API_KEY}",
    "Content-Type": "application/json"
}

data = {
    "metadata": {
        "user_feedback": "helpful",
        "quality_rating": 5
    },
    "custom_identifier": "ticket_12345"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())
{
  "id": "log_abc123...",
  "unique_id": "log_abc123...",
  "organization_id": "org_xyz789",
  "environment": "prod",
  "timestamp": "2025-12-26T10:30:00Z",
  "start_time": "2025-12-26T10:29:58Z",
  "log_type": "chat",
  "model": "gpt-4o-mini",
  "cost": 0.000705,
  "latency": 1.234,
  "status": "success",
  "custom_identifier": "ticket_12345",
  "metadata": {
    "user_feedback": "helpful",
    "quality_rating": 5,
    "previous_metadata_key": "previous_value"
  },
  "input": "[{\"role\":\"user\",\"content\":\"Hello\"}]",
  "output": "{\"role\":\"assistant\",\"content\":\"Hi there!\"}",
  // ... rest of log fields
}

Use Cases

# Add thumbs up/down feedback to a log
import requests

def add_feedback(log_id, is_positive, api_key):
    url = f"https://api.keywordsai.co/api/request-logs/{log_id}/"
    
    response = requests.patch(
        url,
        headers={"Authorization": f"Bearer {api_key}"},
        json={
            "metadata": {
                "user_feedback": "positive" if is_positive else "negative",
                "feedback_timestamp": datetime.now().isoformat()
            }
        }
    )
    return response.json()

# Usage
add_feedback("log_abc123", True, YOUR_API_KEY)
# Flag logs that need human review
import requests

def mark_for_review(log_id, reason, priority, api_key):
    url = f"https://api.keywordsai.co/api/request-logs/{log_id}/"
    
    response = requests.patch(
        url,
        headers={"Authorization": f"Bearer {api_key}"},
        json={
            "metadata": {
                "needs_review": True,
                "review_reason": reason,
                "review_priority": priority,
                "flagged_at": datetime.now().isoformat()
            }
        }
    )
    return response.json()

# Usage
mark_for_review(
    "log_abc123",
    "Potential PII in response",
    "high",
    YOUR_API_KEY
)
# Blur logs containing sensitive information
import requests

def blur_log(log_id, reason, api_key):
    url = f"https://api.keywordsai.co/api/request-logs/{log_id}/"
    
    response = requests.patch(
        url,
        headers={"Authorization": f"Bearer {api_key}"},
        json={
            "blurred": True,
            "metadata": {
                "blur_reason": reason,
                "blurred_at": datetime.now().isoformat()
            }
        }
    )
    return response.json()

# Usage
blur_log("log_abc123", "Contains PII", YOUR_API_KEY)
# Tag logs with A/B test or experiment information
import requests

def tag_experiment(log_id, experiment_name, variant, api_key):
    url = f"https://api.keywordsai.co/api/request-logs/{log_id}/"
    
    response = requests.patch(
        url,
        headers={"Authorization": f"Bearer {api_key}"},
        json={
            "metadata": {
                "experiment": experiment_name,
                "variant": variant,
                "experiment_tagged_at": datetime.now().isoformat()
            }
        }
    )
    return response.json()

# Usage
tag_experiment(
    "log_abc123",
    "prompt_optimization_v2",
    "variant_b",
    YOUR_API_KEY
)

Metadata Best Practices

Organizing metadata

  1. Use consistent keys: Establish naming conventions across your organization
  2. Add timestamps: Include _at or _timestamp fields for tracking when metadata was added
  3. Namespace related fields: Use prefixes like review_, feedback_, experiment_ to group related fields
  4. Keep it queryable: Use simple data types (strings, numbers, booleans) for fields you’ll filter on
  5. Document your schema: Maintain documentation of your metadata structure

Error Responses

{
  "detail": "Log not found"
}
{
  "error": "Cannot update immutable field",
  "detail": "The field 'cost' cannot be modified"
}