Best practices

New algorithms

circle-info

Important: Non-Breaking Changes

Haut.AI may add new algorithms to the output of the v4/.../results method at any time without prior notice. Adding new algorithms to the response is not considered a breaking change.

circle-exclamation

This approach allows us to continuously improve our analysis capabilities and provide you with new features without requiring immediate updates to your integration.

Code Examples

Python Example

import requests

# API endpoint with variables
company_id = "your-company-id"
batch_id = "your-batch-id"
url = f"https://saas.haut.ai/v4/companies/{company_id}/batches/{batch_id}/results"

headers = {
    "Authorization": f"Bearer {your_token}"
}

response = requests.get(url, headers=headers)
results = response.json()

# Safe parsing: only extract the algorithms you need
# This won't break if new algorithms are added
def extract_needed_algorithms(results):
    """
    Extract only the specific algorithms your application uses.
    Gracefully handles missing or new algorithms.
    """
    extracted_data = {}

    # Example: Extract only specific algorithms
    algorithms_needed = ['acne_inflammation', 'wrinkles', 'pigmentation']

    for algo in algorithms_needed:
        if algo in results:
            extracted_data[algo] = results[algo]
        else:
            # Handle missing algorithm gracefully
            extracted_data[algo] = None
            print(f"Warning: {algo} not found in results")

    return extracted_data

# Use the function
my_data = extract_needed_algorithms(results)

# Alternative: Use dict.get() for safe access
acne_data = results.get('acne_inflammation', {})
wrinkles_data = results.get('wrinkles', {})

# Process only what you need, ignore everything else
if acne_data:
    severity = acne_data.get('severity')
    print(f"Acne severity: {severity}")

JavaScript Example

TypeScript Example (with type safety)

Key Takeaways

  1. Use safe access patterns: dict.get() in Python, optional chaining (?.) in JavaScript

  2. Define only what you need: Don't create rigid schemas that include all possible fields

  3. Handle missing data: Always have fallback values or error handling

  4. Iterate dynamically: If you need to process all algorithms, iterate over keys rather than hardcoding

  5. Log warnings, not errors: If an expected algorithm is missing, log it for monitoring but don't crash

Last updated

Was this helpful?