Quick Start

Welcome to the quick-start! Below are the top integrations we support, with quick directions on getting up and running with popular methods.

Basic Usage Example

bash

$
 

 

Full Documentation

AiomaticAPI is designed to simplify AI content creation. A few things to consider before we get started:

  • Each request might take longer periods of time to be completed, statement especially valid for the image creation API. Remember to set your request timeout to 120 seconds or greater to ensure that you receive the content of all AI generated content we send.
  • If you exceed your monthly API credit count, the API will respond with an error, prompting you that you are rate limited.
  • The server is set to the UTC timezone, call counts will be reset monthly based on this time zone.
  • Each request will return a JSON string containing the AI generated content, in the ‘result’ field. Also, the responses will contain the remaining API credit count, in the ‘remainingtokens’ field.

Generating AI Text and Images

Learn below how to use the endpoints of AiomaticAPI, to generate text and images based on your needs. If you are interested in usage costs for enpoints and models, please check the pricing page.

Check the available API nodes below:

1. Generating text using the AI writer

This API node will generate text based on your requirements. You do not need to install on your server anything, the API will handle everything for you. Just call it and you will get the AI generated text in the API response. Note that both GET and POST requests are supported, if you have a large prompt that you need to send to the AI writer, use POST requests!

API Endpoint:
https://aiomaticapi.com/apis/ai/v1/text

Sample Call:

# Add your API key, replace the prompt and add optional parameters
curl "https://aiomaticapi.com/apis/ai/v1/text?apikey=APIKEY&prompt=write%20me%20a%20short%20letter"

Result:

{
  "remainingtokens": "12000",
  "finish_reason": "stop",
  "result": "Dear [name],\n\nI hope this letter finds you doing well. I wanted to reach out and let you know how much I appreciate all the help you've given me lately.(rest of the AI generated content)...",
}

API parameters:

  • apikey*required – add your API key for the call – be sure to have a valid subscription for the call to work
  • prompt*required – add the prompt based on which the AI should generate text – for best results, be sure to urlencode the prompt so it is received correctly by the API.
  • model – Select the model you wish to use when creating textual content. Available models are: gpt-3.5-turbo-instruct.
  • temperature – Advanced parameter (optional). What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. We generally recommend altering this or top_p but not both.
  • top_p – Advanced parameter (optional). An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
  • presence_penalty – Advanced parameter (optional). Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics.
  • frequency_penalty – Advanced parameter (optional). Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.

API result:

– In case of success: a JSON with the following content:

  • remainingtokens – The number of API tokens remaining for your API key.
  • finish_reason – Why did the AI stop generating content. The possible values for finish_reason are:
    • stop: API returned complete message, or a message terminated by one of the stop sequences provided via the stop parameter
    • length: Incomplete model output due to max_tokens parameter or token limit
    • content_filter: Omitted content due to a flag from our content filters
  • result – The AI generated text.

– In case of error: a JSON with the following content:

  • remainingtokens – The number of API calls remaining for your API key. In case of error, this might display 0. In case of errors, the used token count will not be increased.
  • error – The error message containing the reason of the failure.

2. ChatGPT/GPT-4 models usage

This API node will generate a response from the famous ChatGPT model (gpt-3.5-turbo, gpt-3.5-turbo-16k, gpt-3.5-turbo-0125, gpt-3.5-turbo-1106, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-0301, gpt-4, gpt-4-1106-preview, gpt-4-0125-preview, gpt-4-turbo-preview, gpt-4-turbo, gpt-4-turbo-2024-04-09, gpt-4-vision-preview, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0314, gpt-4-32k-0613 are the models supported at the moment). Just call it and you will get the AI generated text in the API response. Note that both GET and POST requests are supported, if you have a large prompt that you need to send to the AI writer, use POST requests!

API Endpoint:
https://aiomaticapi.com/apis/ai/v1/chat

Sample Call:

# Add your API key, replace the prompt and add optional parameters
curl "https://aiomaticapi.com/apis/ai/v1/chat?apikey=APIKEY&messages=write%20me%20a%20short%20letter"

Result:

{
  "remainingtokens": "12000",
  "finish_reason": "stop",
  "result": "{"role":"assistant","content":"\n\nDear [Name],(rest of the AI generated content)..."}",
}

API parameters:

  • apikey*required – add your API key for the call – be sure to have a valid subscription for the call to work
  • messages*required – if you make a GET request, simply add the prompt based on which the AI should generate text. If you make a POST request, be sure to add the following array in the POST request, in the “messages” parameter: array(“role” => “user”, “content” => “YOUR_INPUT”). You can add an array of multiple messages, the possible roles are: “user”, “assistant” or “system”. You should add pretraining prompts in the first message, with the role “system”, afterwards add multiple “user” and “assistant” messages in the sent array. If you want to use vision, you need to use a different format in the “messages” parameter (in this case, only POST requests are supported): array(“role” => “user”, “content” => array(array(“type” => “text”, “text” => “YOUR_INPUT”), array(“type” => “image_url”, “image_url” => “IMAGE_URL_FOR_VISION”)))
  • model – Select the model you wish to use when creating textual content. Available models are: gpt-3.5-turbo, gpt-3.5-turbo-16k, gpt-3.5-turbo-0125, gpt-3.5-turbo-1106, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-0301, gpt-4, gpt-4-1106-preview, gpt-4-0125-preview, gpt-4-turbo-preview, gpt-4-turbo, gpt-4-turbo-2024-04-09, gpt-4-vision-preview, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0314, gpt-4-32k-0613.
  • temperature – Advanced parameter (optional). What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. We generally recommend altering this or top_p but not both.
  • top_p – Advanced parameter (optional). An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
  • presence_penalty – Advanced parameter (optional). Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics.
  • frequency_penalty – Advanced parameter (optional). Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.
  • tools – An array of function objects, to define the available functions which can be called by the AI. Check required format in the example below.
  • tool_choice – “auto” is default. If you want to force the model to call a specific function you can do so by setting tool_choice: {“name”: ““}. You can also force the model to generate a user-facing message by setting tool_choice: “none”. Note that the default behavior (tool_choice: “auto”) is for the model to decide on its own whether to call a function and if so which function to call.

API result:

– In case of success: a JSON with the following content:

  • remainingtokens – The number of API tokens remaining for your API key.
  • finish_reason – Why did the AI stop generating content. The possible values for finish_reason are:
    • stop: API returned complete message, or a message terminated by one of the stop sequences provided via the stop parameter
    • length: Incomplete model output due to max_tokens parameter or token limit
    • tool_calls: The model decided to call one or multiple functions
    • content_filter: Omitted content due to a flag from our content filters
  • result – The AI generated text, in the following JSON encoded format: {“role”:”assistant”,”content”:”THE_AI_RESPONSE”}.

– In case of error: a JSON with the following content:

  • remainingtokens – The number of API calls remaining for your API key. In case of error, this might display 0. In case of errors, the used token count will not be increased.
  • error – The error message containing the reason of the failure.

Extra feature: Function Execution

Utilize the Function Calling capability of AiomaticAPI to empower developers in expanding the AI writer’s potential. By enabling custom function execution from your code base, this feature seamlessly integrates AI-generated content with various practical actions like email sending, file creation, database writing, and more. The following comprehensive documentation offers a detailed, step-by-step guide on leveraging AiomaticAPI’s Function Calling feature to its fullest potential.
Prerequisites:
Before you proceed, ensure that you have the following prerequisites in place:

  1. Latest Version of Turbo or GPT-4:
    • To use the Function Calling feature, you need the latest version of Turbo (gpt-3.5-turbo-0613 or higher) or GPT-4 (gpt-4-0613 or higher). Please verify that your AI model is up-to-date, especially if you are using Azure with deployments of models that might not be the latest ones.

Setting Up Function Calling:
Use the below code structure to enable function calling in AiomaticAPI:

$messages = array(array("role" => "user", "content" => "What's the weather like in Boston?"));
$functions = array(
    'type' => 'function', 
    'function' => 
        array(
            "name" => "get_current_weather",
            "description" => "Get the current weather in a given location",
            "parameters" => array(
                "type" => "object",
                "properties" => array(
                    "location" => array(
                        "type" => "string",
                        "description" => "The city and state, e.g. San Francisco, CA",
                    ),
                    "unit" => array("type" => "string", "enum" => array("celsius", "fahrenheit")),
                ),
                "required" => array("location"),
            ),
        ),
);

$data = array(
    "model" => "gpt-3.5-turbo-1106",
    "messages" => $messages,
    "tools" => $functions,
    "tool_choice" => "auto", // auto is default, but we'll be explicit
);

Interpreting results and executing functions based on AI responses:

//check the AI reply, if it contains the tool_calls parameter, execute our function
if (isset($reply->tool_calls) && !empty($reply->tool_calls)) 
{
    foreach($reply->tool_calls as $tool_call)
    {
        //check if your function name is called by the AI
        if ($tool_call->name === 'send_email') 
        {
            //do the stuff from your function, in this case, send an email
            $subject = $tool_call->arguments->subject;
            $message = $tool_call->arguments->message;
            mail("admin@yoursite.com", $subject, $message);
        }
    }
}

Note that in case a function is called by the AI, a textual response will not be returned by it. So, please handle this case also, you might need to set up a default textual response for chatbots, in case functions are called by the AI.


3. Getting Embeddings data using the API

Text embeddings measure the relatedness of text strings. Embeddings are commonly used for: Search (where results are ranked by relevance to a query string), Clustering (where text strings are grouped by similarity), Recommendations (where items with related text strings are recommended), Anomaly detection (where outliers with little relatedness are identified), Diversity measurement (where similarity distributions are analyzed), Classification (where text strings are classified by their most similar label). In the Aiomatic plugin, they are used to give additional context to the AI content writer, based on the input/prompt of the user. Note that both GET and POST requests are supported, if you have a large instructions or input texts that you need to send to the AI writer, use POST requests!

API Endpoint:
https://aiomaticapi.com/apis/ai/v1/embeddings

Sample Call:

# Add your API key, replace the prompt and add optional parameters
curl "https://aiomaticapi.com/apis/ai/v1/embeddings?apikey=APIKEY&input=I%20have%20a%20white%20dog&model=text-embedding-ada-002"

Result:

{
  "remainingtokens": "12000",
  "result": [{"object":"embedding","index":0,"embedding":[-0.025966445,0.0040175244,...]}],
}

API parameters:

  • apikey*required – add your API key for the call – be sure to have a valid subscription for the call to work
  • input*required – add the text for which you want to generate the embeddings data.
  • model – Select the model you wish to use when creating the embeddings. Available models are: text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002.

API result:

– In case of success: a JSON with the following content:

  • remainingtokens – The number of API tokens remaining for your API key.
  • result – The embeddings data, in the following format: [{“object”:”embedding”,”index”:0,”embedding”:[-0.025966445,0.0040175244,…]}]

– In case of error: a JSON with the following content:

  • remainingtokens – The number of API calls remaining for your API key. In case of error, this might display 0. In case of errors, the used token count will not be increased.
  • error – The error message containing the reason of the failure.

4. Generating images using the AI

This API node will generate images based on your requirements. Just call it and you will get the AI generated image in the API response. Note that both GET and POST requests are supported, if you have a large prompt that you need to send to the AI writer, use POST requests!

API Endpoint:
https://aiomaticapi.com/apis/ai/v1/image

Sample Call:

# Add your API key, replace the prompt and add optional parameters
curl "https://aiomaticapi.com/apis/ai/v1/image?apikey=APIKEY&prompt=an%20image%20of%20a%20bright%20and%20sunny%20day"

Result:

{
  "remainingtokens": "12000",
  "result": "URL_OF_THE_GENERATED_IMAGE",
}

API parameters:

  • apikey*required – add your API key for the call – be sure to have a valid subscription for the call to work.
  • prompt*required – add the prompt based on which the AI should generate an image – for best results, be sure to urlencode the prompt so it is received correctly by the API.
  • model – set the image generator model to be used. Supported values are: dall-e-2, dall-e-3, dall-e-3-hd. The default value for the model is: dall-e-2.
  • image_size – select the image size which should be generated. Supported values for Dall-E 2 are: 256×256, 512×512, 1024×1024. Supported values for Dall-E 3 and Dall-E 3 HD are: 1024×1024, 1792×1024, 1024×1792.
  • style – the style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3 or dall-e-3-hd.

API result:

– In case of success: a JSON with the following content:

  • remainingtokens – The number of API tokens remaining for your API key.
  • result – The URL of the AI generated image.

– In case of error: a JSON with the following content:

  • remainingtokens – The number of API calls remaining for your API key. In case of error, this might display 0. In case of errors, the used token count will not be increased.
  • error – The error message containing the reason of the failure.

What’s next?

Check also this WordPress plugin which is using this API (just add your API key in it’s settings, and you are ready to generate AI content:

There’s a lot more that you can configure and tune in AiomaticAPI to handle the needs of your application. Be sure to read about all the options it exposes and how to get the most out of this API.