Spaces:
Configuration error
Configuration error
File size: 4,832 Bytes
753dbc7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | # CC Site Maker API Documentation
This document explains how to interact with the CC Site Maker API programmatically using HTTP requests, without needing to use the browser interface.
## External AI API Endpoint
The application provides an external API endpoint that allows you to generate HTML content by sending a prompt to the AI.
### Endpoint
```
POST /api/external/ask-ai
```
### Headers
| Header Name | Required | Description |
| ------------ | -------- | --------------------------------- |
| Content-Type | Yes | Must be set to `application/json` |
| X-API-Key | Yes | Your API key for authentication |
### Request Body
```json
{
"prompt": "Create a landing page for a coffee shop",
"html": "<!DOCTYPE html>...", // Optional: Current HTML to modify
"previousPrompt": "Make me a website", // Optional: Previous prompt for context
"provider": "auto" // Optional: AI provider (default is "auto")
}
```
| Parameter | Type | Required | Description |
| -------------- | ------ | -------- | ---------------------------------------------------- |
| prompt | string | Yes | The instruction for what you want the AI to generate |
| html | string | No | Optional current HTML to modify or build upon |
| previousPrompt | string | No | Optional previous prompt to maintain context |
| provider | string | No | AI provider to use (auto, novita, etc.) |
### Response
The response will be streamed as plain text. The complete response will be an HTML document.
### Rate Limits
- 60 requests per minute per API key
### Example Usage
#### JavaScript/Node.js
```javascript
async function generateHTML(prompt, apiKey) {
const response = await fetch(
'https://your-app-domain.com/api/external/ask-ai',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey
},
body: JSON.stringify({
prompt: prompt
})
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Failed to generate HTML');
}
// For streamed responses
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let result = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
result += decoder.decode(value, { stream: true });
}
return result;
}
// Example usage
generateHTML('Create a landing page for a coffee shop', 'your-api-key-here')
.then((html) => {
console.log(html);
// Save to file or process further
})
.catch((error) => {
console.error('Error generating HTML:', error);
});
```
#### Python
```python
import requests
def generate_html(prompt, api_key):
url = 'https://your-app-domain.com/api/external/ask-ai'
headers = {
'Content-Type': 'application/json',
'X-API-Key': api_key
}
data = {
'prompt': prompt
}
# For streaming response
response = requests.post(url, json=data, headers=headers, stream=True)
if response.status_code != 200:
try:
error_data = response.json()
raise Exception(error_data.get('message', 'Failed to generate HTML'))
except:
response.raise_for_status()
result = ''
for chunk in response.iter_content(chunk_size=1024, decode_unicode=True):
if chunk:
result += chunk
return result
# Example usage
try:
html = generate_html('Create a landing page for a coffee shop', 'your-api-key-here')
print(html)
# Save to file or process further
except Exception as e:
print(f'Error generating HTML: {e}')
```
#### cURL
```bash
curl -X POST 'https://your-app-domain.com/api/external/ask-ai' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: your-api-key-here' \
-d '{
"prompt": "Create a landing page for a coffee shop"
}'
```
## Obtaining an API Key
To obtain an API key, you need to:
1. Log in to the application
2. Navigate to your account settings
3. Generate a new API key
## Error Handling
The API may return the following error responses:
| Status Code | Description |
| ----------- | --------------------------------------------------------- |
| 400 | Bad request (missing required fields or context too long) |
| 401 | Unauthorized (missing or invalid API key) |
| 429 | Rate limit exceeded |
| 500 | Server error |
Each error response includes a JSON object with an `ok` field set to `false` and a `message` field describing the error.
|