Python
Using the requests library.

Chat / vision call

import requests

BASE_URL = "https://api.celestialization.com/api"
API_KEY = "YOUR_API_KEY"


def text_with_optional_image(prompt: str, image_url: str = "") -> str:
    url = f"{BASE_URL}/text-with-image.php"
    payload = {
        "prompt": prompt,
        "image_url": image_url,
        "apikey": API_KEY,
    }

    response = requests.post(url, json=payload, timeout=60)
    response.raise_for_status()
    data = response.json()

    # Safely read the assistant message
    choices = data.get("choices") or []
    if not choices:
        raise RuntimeError("No choices returned from API")

    return choices[0]["message"]["content"]


if __name__ == "__main__":
    print(text_with_optional_image("hi how are you"))
    print(text_with_optional_image(
        "what is in this image?",
        "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg",
    ))

Image generation call

def generate_image(prompt: str) -> str:
    url = f"{BASE_URL}/image.php"
    payload = {
        "prompt": prompt,
        "image_url": "",
        "apikey": API_KEY,
    }

    response = requests.post(url, json=payload, timeout=60)
    response.raise_for_status()
    data = response.json()

    images = data.get("data") or []
    if not images:
        raise RuntimeError("No images returned from API")

    return images[0]["url"]


if __name__ == "__main__":
    image_url = generate_image("generate an image of an apple")
    print("Image URL:", image_url)
C#
Using HttpClient and System.Text.Json.

Chat / vision call

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class CelestializationClient
{
    private const string BaseUrl = "https://api.celestialization.com/api";
    private readonly string _apiKey;
    private readonly HttpClient _http;

    public CelestializationClient(string apiKey, HttpClient? httpClient = null)
    {
        _apiKey = apiKey;
        _http = httpClient ?? new HttpClient();
    }

    public async Task<string> TextWithOptionalImageAsync(string prompt, string imageUrl = "")
    {
        var url = $"{BaseUrl}/text-with-image.php";

        var payload = new
        {
            prompt = prompt,
            image_url = imageUrl,
            apikey = _apiKey
        };

        var json = JsonSerializer.Serialize(payload);
        using var content = new StringContent(json, Encoding.UTF8, "application/json");
        using var response = await _http.PostAsync(url, content);
        response.EnsureSuccessStatusCode();

        var responseJson = await response.Content.ReadAsStringAsync();
        using var doc = JsonDocument.Parse(responseJson);

        var choices = doc.RootElement.GetProperty("choices");
        if (choices.GetArrayLength() == 0)
            throw new InvalidOperationException("No choices returned from API.");

        var first = choices[0];
        return first.GetProperty("message").GetProperty("content").GetString() ?? string.Empty;
    }
}

Image generation call

public async Task<string> GenerateImageAsync(string prompt)
{
    var url = $"{BaseUrl}/image.php";

    var payload = new
    {
        prompt = prompt,
        image_url = "",
        apikey = _apiKey
    };

    var json = JsonSerializer.Serialize(payload);
    using var content = new StringContent(json, Encoding.UTF8, "application/json");
    using var response = await _http.PostAsync(url, content);
    response.EnsureSuccessStatusCode();

    var responseJson = await response.Content.ReadAsStringAsync();
    using var doc = JsonDocument.Parse(responseJson);

    var data = doc.RootElement.GetProperty("data");
    if (data.GetArrayLength() == 0)
        throw new InvalidOperationException("No images returned from API.");

    return data[0].GetProperty("url").GetString() ?? string.Empty;
}
Java
Using HttpClient from Java 11+.

Chat / vision call

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class CelestializationClient {
    private static final String BASE_URL = "https://api.celestialization.com/api";
    private final String apiKey;
    private final HttpClient http;

    public CelestializationClient(String apiKey) {
        this.apiKey = apiKey;
        this.http = HttpClient.newHttpClient();
    }

    public String textWithOptionalImage(String prompt, String imageUrl) throws Exception {
        String url = BASE_URL + "/text-with-image.php";

        String json = String.format(
            "{ "prompt": %1$s, "image_url": %2$s, "apikey": %3$s }",
            quote(prompt),
            quote(imageUrl == null ? "" : imageUrl),
            quote(apiKey)
        );

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(url))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response =
            http.send(request, HttpResponse.BodyHandlers.ofString());

        if (response.statusCode() >= 400) {
            throw new RuntimeException("API error: " + response.statusCode() + " " + response.body());
        }

        // For production, use a JSON library; here we return the raw JSON for simplicity.
        return response.body();
    }

    private static String quote(String value) {
        return """ + value.replace("\", "\\").replace(""", "\"") + """;
    }
}

In real applications, parse the JSON using your preferred library (Jackson, Gson, etc.) and extract choices[0].message.content.

Image generation call

public String generateImage(String prompt) throws Exception {
    String url = BASE_URL + "/image.php";

    String json = String.format(
        "{ "prompt": %1$s, "image_url": %2$s, "apikey": %3$s }",
        quote(prompt),
        quote(""),
        quote(apiKey)
    );

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build();

    HttpResponse<String> response =
        http.send(request, HttpResponse.BodyHandlers.ofString());

    if (response.statusCode() >= 400) {
        throw new RuntimeException("API error: " + response.statusCode() + " " + response.body());
    }

    return response.body();
}
PHP
Using native curl.

Chat / vision call

<?php

function call_text_with_optional_image(string $prompt, string $imageUrl = ''): string
{
    $url = 'https://api.celestialization.com/api/text-with-image.php';

    $payload = [
        'prompt'    => $prompt,
        'image_url' => $imageUrl,
        'apikey'    => 'YOUR_API_KEY',
    ];

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
        CURLOPT_POSTFIELDS     => json_encode($payload),
    ]);

    $response = curl_exec($ch);
    if ($response === false) {
        throw new RuntimeException('Curl error: ' . curl_error($ch));
    }

    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($status >= 400) {
        throw new RuntimeException("API error: $status - $response");
    }

    $data = json_decode($response, true);
    if (empty($data['choices'][0]['message']['content'])) {
        throw new RuntimeException('No choices returned from API');
    }

    return $data['choices'][0]['message']['content'];
}

Image generation call

function generate_image(string $prompt): string
{
    $url = 'https://api.celestialization.com/api/image.php';

    $payload = [
        'prompt'    => $prompt,
        'image_url' => '',
        'apikey'    => 'YOUR_API_KEY',
    ];

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
        CURLOPT_POSTFIELDS     => json_encode($payload),
    ]);

    $response = curl_exec($ch);
    if ($response === false) {
        throw new RuntimeException('Curl error: ' . curl_error($ch));
    }

    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($status >= 400) {
        throw new RuntimeException("API error: $status - $response");
    }

    $data = json_decode($response, true);
    if (empty($data['data'][0]['url'])) {
        throw new RuntimeException('No image URL returned from API');
    }

    return $data['data'][0]['url'];
}

$imageUrl = generate_image('generate an image of an apple');
echo "Image URL: " . $imageUrl . PHP_EOL;