import httpx class TogetherImageAPI: headers = { 'sec-ch-ua-platform': '"macOS"', 'Authorization': 'Bearer 869f5ecd80fc6482ccb99f37179cb2c162879925224ae9d91caffc35d9b534b3', 'Referer': 'https://api.together.ai/playground/image/black-forest-labs/FLUX.1-dev', 'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"', 'sec-ch-ua-mobile': '?0', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36', 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json', } def __init__(self): self.name = "TogetherImageAPI" self.url = "https://api.together.ai/inferences" def get_model_list(self): models = [ "black-forest-labs/FLUX.1-dev", ] return models async def generate(self, json_data): print(json_data) model = json_data['modelId'] prompt = json_data['prompt'] negative_prompt = json_data.get('negative_prompt', '') width = json_data.get('width', 1024) height = json_data.get('height', 768) steps = json_data.get('steps', 28) data = { 'model': model, 'prompt': prompt, 'negative_prompt': negative_prompt, 'width': width, 'height': height, 'steps': steps, 'n': 1, 'response_format': 'b64_json', 'stop': [], } async with httpx.AsyncClient() as client: response = await client.post("https://api.together.ai/inference", json=json_data) if response.status_code == 200: return response.json() else: raise Exception(f"Error: {response.status_code} - {response.text}")