Quick Start

Drop-in OpenAI-API compatible endpoint & Stable Diffusion API

My API KeysAssistant ApplicationsRP Applications

Chat Completions (OpenAI Compatible)

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 import requests import json # Ensure you have your API key stored securely, e.g., in an environment variable # ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY" url = "https://api.arliai.com/v1/chat/completions" payload = json.dumps({ "model": "TEXT_GENERATION_MODEL", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}, {"role": "assistant", "content": "Hi!, how can I help you today?"}, {"role": "user", "content": "Say hello!"} ], "repetition_penalty": 1.1, "temperature": 0.7, "top_p": 0.9, "top_k": 40, "max_tokens": 1024, "stream": False }) headers = { 'Content-Type': 'application/json', 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key } response = requests.request("POST", url, headers=headers, data=payload) print(response.json())

NOTE: Some models might not accept system prompts. Replace YOUR_ARLIAI_API_KEY with your actual key.

Completions (OpenAI Compatible)

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 import requests import json # Ensure you have your API key stored securely # ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY" url = "https://api.arliai.com/v1/completions" payload = json.dumps({ "model": "TEXT_GENERATION_MODEL", "prompt": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are an assistant AI.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHello there!<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", "repetition_penalty": 1.1, "temperature": 0.7, "top_p": 0.9, "top_k": 40, "max_tokens": 1024, "stream": False }) headers = { 'Content-Type': 'application/json', 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key } response = requests.request("POST", url, headers=headers, data=payload) print(response.json())

NOTE: Make sure to use the suggested prompt format for each model when using completions. Example shown is Llama 3 Instruct format. Replace YOUR_ARLIAI_API_KEY with your actual key.

Text-to-Image Generation (SDNext API)

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 import requests import json import base64 # Needed if you want to decode the resulting image # Ensure you have your API key stored securely # ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY" # IMAGE_GENERATION_MODEL = "IMAGE_GENERATION_MODEL" # Or your preferred model url = "https://api.arliai.com/sdapi/v1/txt2img" payload = json.dumps({ "prompt": "A photo of an astronaut riding a horse on the moon", "negative_prompt": "ugly, blurry, low quality", "steps": 30, "sampler_name": "DPM++ 2M Karras", "width": 1024, "height": 1024, "sd_model_checkpoint": IMAGE_GENERATION_MODEL, # Required "seed": -1, "cfg_scale": 7 }) headers = { 'Content-Type': 'application/json', 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key } response = requests.request("POST", url, headers=headers, data=payload) response_data = response.json() # Example: Process the first image if it exists if 'images' in response_data and len(response_data['images']) > 0: image_data = base64.b64decode(response_data['images'][0]) with open("generated_image.png", "wb") as f: f.write(image_data) print("Image saved as generated_image.png") else: print("Error or no image received:", response_data)

NOTE: Send parameters as JSON in the request body. The sd_model_checkpoint and prompt fields are required. The generated image(s) will be returned in the images array as base64 encoded strings. Max steps is 40. Replace YOUR_ARLIAI_API_KEY and model names as needed.

Image-to-Image Generation (SDNext API)

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 import requests import json import base64 # Needed for encoding init_image and decoding result # Function to encode image to base64 def encode_image_to_base64(filepath): with open(filepath, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8') # Ensure you have your API key stored securely # ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY" # IMAGE_GENERATION_MODEL = "IMAGE_GENERATION_MODEL" # Or your preferred model # INPUT_IMAGE_PATH = "path/to/your/input_image.png" url = "https://api.arliai.com/sdapi/v1/img2img" # Encode your initial image to base64 # init_image_base64 = encode_image_to_base64(INPUT_IMAGE_PATH) init_image_base64 = "YOUR_BASE64_ENCODED_IMAGE_STRING_HERE" # Replace with actual base64 data payload = json.dumps({ "init_images": [init_image_base64], # Required: Array of base64 strings "prompt": "Make the horse blue", "negative_prompt": "ugly, blurry, low quality, text, watermark", "steps": 30, "sampler_name": "DPM++ 2M Karras", "width": 1024, # Should ideally match init_image dimensions or be adjusted "height": 1024, "sd_model_checkpoint": IMAGE_GENERATION_MODEL, # Required "seed": -1, "cfg_scale": 7, "denoising_strength": 0.75 # Controls how much the init_image is changed }) headers = { 'Content-Type': 'application/json', 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key } response = requests.request("POST", url, headers=headers, data=payload) response_data = response.json() # Example: Process the first image if it exists if 'images' in response_data and len(response_data['images']) > 0: image_data = base64.b64decode(response_data['images'][0]) with open("generated_img2img.png", "wb") as f: f.write(image_data) print("Image saved as generated_img2img.png") else: print("Error or no image received:", response_data)

NOTE: The sd_model_checkpoint, prompt, and init_images fields are required. init_images must be an array containing at least one base64 encoded string of your initial image. Max steps is 40. Replace placeholders with actual data.

Upscale Image (SDNext API)

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 import requests import json import base64 # Needed for encoding input image and decoding result # Function to encode image to base64 def encode_image_to_base64(filepath): with open(filepath, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8') # Ensure you have your API key stored securely # ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY" # INPUT_IMAGE_PATH = "path/to/your/low_res_image.png" url = "https://api.arliai.com/sdapi/v1/extra-single-image" # Matches SdapiV1Controller # Encode your image to base64 # image_base64 = encode_image_to_base64(INPUT_IMAGE_PATH) image_base64 = "YOUR_BASE64_ENCODED_IMAGE_STRING_HERE" # Replace with actual base64 data payload = json.dumps({ "image": image_base64, # Required: base64 string of the image to upscale "upscaler_1": "R-ESRGAN 4x+", # Example upscaler model "upscaling_resize": 2 # Upscale factor (e.g., 2x) }) headers = { 'Content-Type': 'application/json', 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key } response = requests.request("POST", url, headers=headers, data=payload) response_data = response.json() # Example: Process the upscaled image if it exists if 'image' in response_data: # Upscale endpoint returns 'image' not 'images' array image_data = base64.b64decode(response_data['image']) with open("upscaled_image.png", "wb") as f: f.write(image_data) print("Upscaled image saved as upscaled_image.png") else: print("Error or no image received:", response_data)

NOTE: The image field is required and must contain the base64 encoded string of the image you want to upscale. The upscaled image is returned in the image field (not an array) as a base64 encoded string. Replace placeholders with actual data.