Replit prompt

Third-Party API Integration

Connect to a third-party API with authentication, error handling, rate limiting, and response caching.

Write a Node.js script that integrates with the {{api_name}} API.

## API: {{api_name}}
## API Docs: {{api_docs}}
## What to do: {{integration_purpose}}
## Output: {{output}}

### Integration Requirements

**Authentication**
{{auth_type}} authentication.
Read credentials from environment variables (never hardcode).
Handle token refresh if applicable.

**API Client Setup**
Use axios or node-fetch with base URL and default headers.
Set timeout: 30 seconds.
Include User-Agent header with your app name.

**Implement These Operations:**
{{operations}}

For each operation:
- Function with typed parameters
- Input validation before API call
- Handle HTTP errors: check response.status before parsing
- Parse response and return typed result
- Log request + response time (not sensitive data)

**Error Handling**
```javascript
try {
  const result = await apiCall(params);
  return { success: true, data: result };
} catch (error) {
  if (error.response) {
    // API returned error response
    return { success: false, error: error.response.data, status: error.response.status };
  }
  // Network/timeout error
  return { success: false, error: error.message, status: null };
}
```

**Rate Limiting**
Track request count per window.
Add delay between requests if approaching limit.
Exponential backoff on 429 responses.

**Caching**
Cache GET responses in memory Map with TTL.
Cache key: endpoint + serialized params.

**Output**
Save results to: {{output}}.
Log summary: total processed, successes, failures.

Fill in: {{api_name}}, {{api_docs}}, {{integration_purpose}}, {{output}}, {{auth_type}}, {{operations}}. In Loopy you fill these in a form and copy the finished prompt in one click.