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, text-davinci-003, text-davinci-002, text-curie-001, text-babbage-001, text-ada-001.
  • 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-0613, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-0301, gpt-4, 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 “message” 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.
  • 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-0613, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-0301, gpt-4, 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.
  • functions – An array of function objects, to define the available functions which can be called by the AI. Check required format in the example below.
  • function_call – “Auto” is default. If you want to force the model to call a specific function you can do so by setting function_call: {“name”: ““}. You can also force the model to generate a user-facing message by setting function_call: “none”. Note that the default behavior (function_call: “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
    • function_call: The model decided to call a function
    • 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(
    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-0613",
    "messages" => $messages,
    "functions" => $functions,
    "function_call" => "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 function_call parameter, execute our function
if (isset($reply->function_call) && !empty($reply->function_call)) {
    $function_call = $reply->function_call;
    //check if your function name is called by the AI
    if ($function_call->name === 'send_email') {
        //do the stuff from your function, in this case, send an email
        $subject = $function_call->arguments->subject;
        $message = $function_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. Editing text using the AI editor

This API node will edit text based on your instructions. You can translate, paraphrase/spin, summarize, merge, remove or add parts of the text that you send to the AI for processing. 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/edit

Sample Call:

# Add your API key, replace the prompt and add optional parameters
curl "https://aiomaticapi.com/apis/ai/v1/edit?apikey=APIKEY&instruction=translate%20to%20German&input=Hello%20I%20am%20here"

Result:

{
  "remainingtokens": "12000",
  "result": "Hallo ich bin hier",
}

API parameters:

  • apikey*required – add your API key for the call – be sure to have a valid subscription for the call to work
  • instruction*required – add the instruction based on which the AI should edit the text you send for processing – for best results, be sure to urlencode the instruction so it is received correctly by the API. Be sure to be as precise as possible when writing your instruction
  • input – Send the text which you need to be processed by the AI editor. If no input is provided, the API will write its own content based on the instruction you send to it.
  • model – Select the model you wish to use when editing textual content. Available models are: text-davinci-edit-001.
  • 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. For paraphrasing/translating or other similar tasks, we recommend setting temperature to 0. 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.

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 AI edited 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.

4. 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-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.

5. 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.
  • image_size – Select the image size which should be generated. Supported values are: 256×256, 512×512, 1024×1024.

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.