This API provides AI-powered image generation using Replicate's Flux model. It supports both authenticated access with the service's built-in token and user-provided Replicate API tokens.
https://your-val-town-url.web.val.run
Use the service's built-in Replicate token by providing the service's AUTH_TOKEN:
curl -H "Authorization: Bearer YOUR_SERVICE_AUTH_TOKEN" \ "https://your-val-town-url.web.val.run/generate?prompt=a%20beautiful%20sunset"
Provide your own Replicate API token to bypass service authentication. This allows you to use your own Replicate credits and quotas.
Generate an image and redirect to the image URL.
Endpoint: GET /generate
Parameters:
prompt(required): Text description of the image to generatereplicate_token(optional): Your Replicate API token
Authentication Options:
- With service token: Include
Authorization: Bearer YOUR_SERVICE_AUTH_TOKENheader - With user token: Include
replicate_tokenparameter (no Authorization header needed)
Examples:
Using service authentication:
curl -H "Authorization: Bearer YOUR_SERVICE_AUTH_TOKEN" \ "https://your-val-town-url.web.val.run/generate?prompt=a%20cat%20wearing%20sunglasses"
Using your own Replicate token:
curl "https://your-val-town-url.web.val.run/generate?prompt=a%20cat%20wearing%20sunglasses&replicate_token=r8_YOUR_REPLICATE_TOKEN"
Response:
- Status: 302 (Redirect)
- Location header contains the generated image URL
Generate an image and return JSON with image details.
Endpoint: POST /generate
Request Body:
{ "prompt": "a beautiful landscape", "replicate_token": "r8_YOUR_REPLICATE_TOKEN" // optional }
Authentication Options:
- With service token: Include
Authorization: Bearer YOUR_SERVICE_AUTH_TOKENheader - With user token: Include
replicate_tokenin request body (no Authorization header needed) - With user token (header): Include
X-Replicate-Token: r8_YOUR_REPLICATE_TOKENheader
Examples:
Using service authentication:
curl -X POST \ -H "Authorization: Bearer YOUR_SERVICE_AUTH_TOKEN" \ -H "Content-Type: application/json" \ -d '{"prompt": "a futuristic city"}' \ https://your-val-town-url.web.val.run/generate
Using your own Replicate token (in body):
curl -X POST \ -H "Content-Type: application/json" \ -d '{"prompt": "a futuristic city", "replicate_token": "r8_YOUR_REPLICATE_TOKEN"}' \ https://your-val-town-url.web.val.run/generate
Using your own Replicate token (in header):
curl -X POST \ -H "Content-Type: application/json" \ -H "X-Replicate-Token: r8_YOUR_REPLICATE_TOKEN" \ -d '{"prompt": "a futuristic city"}' \ https://your-val-town-url.web.val.run/generate
Response:
{ "id": "generated_image_1234567890.png", "imageUrl": "https://your-val-town-url.web.val.run/image/generated_image_1234567890.png" }
Get a previously generated image.
Endpoint: GET /image/{imageId}
Parameters:
imageId: The image ID returned from the generate endpoint
Authentication: None required for image retrieval
Example:
curl https://your-val-town-url.web.val.run/image/generated_image_1234567890.png
Response:
- Content-Type: image/png
- Binary image data
When multiple token sources are provided, the API uses this priority order:
X-Replicate-Tokenheaderreplicate_tokenin request body (POST only)replicate_tokenquery parameter (GET only)- Service's built-in
REPLICATE_API_TOKEN(default)
{ "error": "Missing 'prompt' query parameter" }
Unauthorized access 🚫
Not Found
or
Image not found
{ "error": "Failed to generate image", "details": "Specific error message" }
- Sign up at replicate.com
- Go to your account settings
- Generate an API token
- The token will start with
r8_
- Use the built-in authentication to control access
- Monitor usage through your service logs
- Manage costs through your Replicate account
- Use your own Replicate token to:
- Avoid service rate limits
- Use your own Replicate credits
- Have direct control over API usage
- Bypass service authentication requirements
Rate limits depend on the Replicate token being used:
- Service token: Subject to the service owner's Replicate plan
- User token: Subject to your own Replicate plan and limits
This service uses the black-forest-labs/flux-schnell model on Replicate, which:
- Generates high-quality images
- Supports various artistic styles
- Outputs PNG format images
- Typically takes 2-10 seconds to generate
// Using service authentication
const response = await fetch('https://your-val-town-url.web.val.run/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_SERVICE_AUTH_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'a magical forest with glowing mushrooms'
})
});
const result = await response.json();
console.log('Generated image:', result.imageUrl);
// Using your own Replicate token
const responseWithUserToken = await fetch('https://your-val-town-url.web.val.run/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Replicate-Token': 'r8_YOUR_REPLICATE_TOKEN'
},
body: JSON.stringify({
prompt: 'a magical forest with glowing mushrooms'
})
});
const resultWithUserToken = await responseWithUserToken.json();
console.log('Generated image:', resultWithUserToken.imageUrl);
import requests # Using service authentication response = requests.post( 'https://your-val-town-url.web.val.run/generate', headers={ 'Authorization': 'Bearer YOUR_SERVICE_AUTH_TOKEN', 'Content-Type': 'application/json' }, json={ 'prompt': 'a serene mountain landscape' } ) result = response.json() print(f"Generated image: {result['imageUrl']}") # Using your own Replicate token response_with_user_token = requests.post( 'https://your-val-town-url.web.val.run/generate', headers={ 'Content-Type': 'application/json', 'X-Replicate-Token': 'r8_YOUR_REPLICATE_TOKEN' }, json={ 'prompt': 'a serene mountain landscape' } ) result_with_user_token = response_with_user_token.json() print(f"Generated image: {result_with_user_token['imageUrl']}")
- Keep your Replicate API tokens secure
- Don't expose tokens in client-side code
- Use environment variables for token storage
- The service stores generated images temporarily in blob storage
- Images are accessible via direct URL without authentication
- "Unauthorized access": Check your Authorization header or provide a valid replicate_token
- "Missing 'prompt' parameter": Ensure you include a prompt in your request
- "Replicate API error": Check your Replicate token validity and account limits
- "Prediction timed out": The image generation took too long; try again with a simpler prompt
- Check the service logs for detailed error messages
- Verify your Replicate token at replicate.com
- Ensure your prompt is descriptive but not overly complex
- Check your Replicate account for usage limits and billing status