1import requests
2import json
3
4# Ensure you have your API key stored securely, e.g., in an environment variable
5# ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY"
6
7url = "https://api.arliai.com/v1/chat/completions"
8
9payload = json.dumps({
10 "model": "TEXT_GENERATION_MODEL",
11 "messages": [
12 {"role": "system", "content": "You are a helpful assistant."},
13 {"role": "user", "content": "Hello!"},
14 {"role": "assistant", "content": "Hi!, how can I help you today?"},
15 {"role": "user", "content": "Say hello!"}
16 ],
17 "repetition_penalty": 1.1,
18 "temperature": 0.7,
19 "top_p": 0.9,
20 "top_k": 40,
21 "max_completion_tokens": 1024,
22 "stream": False
23})
24headers = {
25 'Content-Type': 'application/json',
26 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key
27}
28
29response = requests.request("POST", url, headers=headers, data=payload)
30print(response.json())NOTE: Some models might not accept system prompts. Replace YOUR_ARLIAI_API_KEY with your actual key.
1import requests
2import json
3
4# Ensure you have your API key stored securely
5# ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY"
6
7url = "https://api.arliai.com/v1/completions"
8
9payload = json.dumps({
10 "model": "TEXT_GENERATION_MODEL",
11 "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",
12 "repetition_penalty": 1.1,
13 "temperature": 0.7,
14 "top_p": 0.9,
15 "top_k": 40,
16 "max_completion_tokens": 1024,
17 "stream": False
18})
19headers = {
20 'Content-Type': 'application/json',
21 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key
22}
23
24response = requests.request("POST", url, headers=headers, data=payload)
25print(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.
1import requests
2import json
3import base64 # Needed if you want to decode the resulting image
4
5# Ensure you have your API key stored securely
6# ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY"
7# IMAGE_GENERATION_MODEL = "IMAGE_GENERATION_MODEL" # Or your preferred model
8
9url = "https://api.arliai.com/sdapi/v1/txt2img"
10
11payload = json.dumps({
12 "prompt": "A photo of an astronaut riding a horse on the moon",
13 "negative_prompt": "ugly, blurry, low quality",
14 "steps": 30,
15 "sampler_name": "DPM++ 2M Karras",
16 "width": 1024,
17 "height": 1024,
18 "sd_model_checkpoint": IMAGE_GENERATION_MODEL, # Required
19 "seed": -1,
20 "cfg_scale": 7
21})
22headers = {
23 'Content-Type': 'application/json',
24 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key
25}
26
27response = requests.request("POST", url, headers=headers, data=payload)
28response_data = response.json()
29
30# Example: Process the first image if it exists
31if 'images' in response_data and len(response_data['images']) > 0:
32 image_data = base64.b64decode(response_data['images'][0])
33 with open("generated_image.png", "wb") as f:
34 f.write(image_data)
35 print("Image saved as generated_image.png")
36else:
37 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.
1import requests
2import json
3import base64 # Needed for encoding init_image and decoding result
4
5# Function to encode image to base64
6def encode_image_to_base64(filepath):
7 with open(filepath, "rb") as image_file:
8 return base64.b64encode(image_file.read()).decode('utf-8')
9
10# Ensure you have your API key stored securely
11# ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY"
12# IMAGE_GENERATION_MODEL = "IMAGE_GENERATION_MODEL" # Or your preferred model
13# INPUT_IMAGE_PATH = "path/to/your/input_image.png"
14
15url = "https://api.arliai.com/sdapi/v1/img2img"
16
17# Encode your initial image to base64
18# init_image_base64 = encode_image_to_base64(INPUT_IMAGE_PATH)
19init_image_base64 = "YOUR_BASE64_ENCODED_IMAGE_STRING_HERE" # Replace with actual base64 data
20
21payload = json.dumps({
22 "init_images": [init_image_base64], # Required: Array of base64 strings
23 "prompt": "Make the horse blue",
24 "negative_prompt": "ugly, blurry, low quality, text, watermark",
25 "steps": 30,
26 "sampler_name": "DPM++ 2M Karras",
27 "width": 1024, # Should ideally match init_image dimensions or be adjusted
28 "height": 1024,
29 "sd_model_checkpoint": IMAGE_GENERATION_MODEL, # Required
30 "seed": -1,
31 "cfg_scale": 7,
32 "denoising_strength": 0.75 # Controls how much the init_image is changed
33})
34headers = {
35 'Content-Type': 'application/json',
36 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key
37}
38
39response = requests.request("POST", url, headers=headers, data=payload)
40response_data = response.json()
41
42# Example: Process the first image if it exists
43if 'images' in response_data and len(response_data['images']) > 0:
44 image_data = base64.b64decode(response_data['images'][0])
45 with open("generated_img2img.png", "wb") as f:
46 f.write(image_data)
47 print("Image saved as generated_img2img.png")
48else:
49 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.
1import requests
2import json
3import base64 # Needed for encoding input image and decoding result
4
5# Function to encode image to base64
6def encode_image_to_base64(filepath):
7 with open(filepath, "rb") as image_file:
8 return base64.b64encode(image_file.read()).decode('utf-8')
9
10# Ensure you have your API key stored securely
11# ARLIAI_API_KEY = "YOUR_ARLIAI_API_KEY"
12# INPUT_IMAGE_PATH = "path/to/your/low_res_image.png"
13
14url = "https://api.arliai.com/sdapi/v1/extra-single-image" # Matches SdapiV1Controller
15
16# Encode your image to base64
17# image_base64 = encode_image_to_base64(INPUT_IMAGE_PATH)
18image_base64 = "YOUR_BASE64_ENCODED_IMAGE_STRING_HERE" # Replace with actual base64 data
19
20payload = json.dumps({
21 "image": image_base64, # Required: base64 string of the image to upscale
22 "upscaler_1": "R-ESRGAN 4x+", # Example upscaler model
23 "upscaling_resize": 2 # Upscale factor (e.g., 2x)
24})
25headers = {
26 'Content-Type': 'application/json',
27 'Authorization': f"Bearer {ARLIAI_API_KEY}" # Replace with your actual API key
28}
29
30response = requests.request("POST", url, headers=headers, data=payload)
31response_data = response.json()
32
33# Example: Process the upscaled image if it exists
34if 'image' in response_data: # Upscale endpoint returns 'image' not 'images' array
35 image_data = base64.b64decode(response_data['image'])
36 with open("upscaled_image.png", "wb") as f:
37 f.write(image_data)
38 print("Upscaled image saved as upscaled_image.png")
39else:
40 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.