Spaces:
Configuration error
Configuration error
|
Download API_DOCUMENTATION.md from carefullycraftedtree/cc_site_maker: direct link, hf CLI and curl.
- Browser
- Download file 4.83 kB
-
https://huggingface.co/spaces/carefullycraftedtree/cc_site_maker/resolve/main/API_DOCUMENTATION.md
- Command line
-
hf download hf://spaces/carefullycraftedtree/cc_site_maker/API_DOCUMENTATION.md
-
curl -L -o API_DOCUMENTATION.md https://huggingface.co/spaces/carefullycraftedtree/cc_site_maker/resolve/main/API_DOCUMENTATION.md
4.83 kB
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
{
"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
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
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
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:
- Log in to the application
- Navigate to your account settings
- 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.