Official Content
  • This documentation is valid for:

Deprecated: Replaced by Chat API.

Globant Enterprise AI Proxy API stands as a transparent proxy for businesses to easily connect to various AI models across different providers, all through a single point of access. With the robust capabilities of Globant Enterprise AI Proxy, there is no need to juggle multiple SDKs or APIs because you can access any supported LLM with a single SDK.

Seamless Access to LLMs

  • One SDK, Multiple Models: with the OpenAI SDK as your single interface, gain immediate access to a myriad of supported LLMs, including those from OpenAI, Azure, Amazon, and Google.
  • Transparent Proxy: operates seamlessly in the background, automatically routing your requests to the designated AI models, and without the need for code changes on your end.

Simplified API Requests

  • Streamlined Authentication: Globant Enterprise AI Proxy applies specific API Tokens, eliminating the requirement of individual API keys for each AI provider.
  • Universal Request Formatting: keep your API request format consistent, regardless of the underlying AI model that is accessed.

Key Advantages

  • Cost and Performance Monitoring: get insights into each model's performance and cost-efficiency without having to integrate multiple monitoring solutions.
  • Future-Proof: as we continually add support for more LLMs, your integration remains intact, saving you future development time.

By leveraging the Globant Enterprise AI Proxy API, organizations substantially simplify their AI model management with the possibility to focus on business outcomes. Our transparent proxy capabilities enable you to continue scaling and innovating, free from the complex management of multiple AI providers.

How to use it

To integrate the use of Globant Enterprise AI HTTP Proxy, no changes are required at the programming level. Modifications simply imply alterations to two elements in each request:

  1. The BaseURL used to invoke AI providers must reference the Globant Enterprise AI component. The URL format to be used is:

    "https://api.saia.ai/proxy/{AIProviderName}/{hostRelativeProviderURL}"
  2. The Authorization header present in each request must be replaced with the Globant Enterprise AI API Token (SAIA_APITOKEN) provided beforehand (without the need to specify the provider invoked).

The request and response received from the call will be the same as when the provider is invoked directly.

Samples:

  1. If the original URL invoked was:

    "https://api.openai.com/v1/chat/completions"

    To use Globant Enterprise AI HTTP Proxy, it should be invoked as:

    "https://api.saia.ai/proxy/openai/v1/chat/completions"
  2. For the original URL:

    "https://api.replicate.com/v1/predictions"

    Using Globant Enterprise AI HTTP Proxy, it should be:

    "https://api.saia.ai/proxy/replicate/v1/predictions"
  3. cURL specification for OpenAI (traditional):
    curl https://api.openai.com/v1/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $OPENAI_API_KEY" \
          -d '{
            "model": "gpt-3.5-turbo",
            "messages": [{"role": "user", "content": "Hello!"}]
             }'
    Using Globant Enterprise AI Proxy:
    curl https://api.saia.ai/proxy/openai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: $SAIA_APITOKEN" \
          -d '{
            "model": "gpt-3.5-turbo",
            "messages": [{"role": "user", "content": "Hello!"}]
             }'
    Similarly to call the embeddings model you can use
    curl https://api.saia.ai/proxy/openai/v1/embeddings \
          -H "Content-Type: application/json" \
          -H "Authorization: $SAIA_APITOKEN" \
          -d '{
            "model": "text-embedding-3-small",
            "input": [
              "Hi there"
            ]
           }'

By following the above steps, you can easily integrate Globant Enterprise AI HTTP Proxy into your application and manage your AI models.

How to integrate Globant Enterprise AI with third-party SDKs

cURL

curl https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

To process the result programatically, take the following as a reference

response = json.loads(result.content) # Assuming the result is the POST result
reply = response.get('choices')[0].get('message').get('content')

OpenAI SDK for Python

from openai import OpenAI

api_key = "$(SAIA_API_KEY)"
api_base = "https://api.saia.ai/proxy/openai/v1"

openai = OpenAI(api_key=api_key, base_url=api_base)

completion = openai.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])

print(completion.choices[0].message.content)

OpenAI SDK for TypeScript

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: SAIA_APITOKEN,
  basePath: "https://api.saia.ai/proxy/openai/v1",  
});
const openai = new OpenAIApi(configuration);

async function main() {
  const chatCompletion = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    messages: [{role: "user", content: "Hello world"}],
  });
  
  console.log(chatCompletion.data.choices[0].message);
}

main();

LangChain

typescript
 const model = new OpenAI({
    temperature: options?.llm?.temperature || DefaultLLM.TEMPERATURE, // increase temperature to get more creative answers
    verbose: options?.llm?.verbose || DefaultLLM.VERBOSE,
    cache: options?.llm?.cache || DefaultLLM.CACHE,
    modelName: options?.llm?.modelName || DefaultLLM.MODEL_NAME,
  },
   {
      basePath: process.env.SAIA_API_BASE_URL,
      apiKey: process.env.SAIA_API_KEY
    }
  );

How to call DALL-E-2 and DALL-E-3 to generate images

DALL-E-2 - cURL ​

curl --location 'https://api.saia.ai/proxy/openai/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: $SAIA_APITOKEN" \
-d '{
    "model": "dall-e-2", 
    "prompt": "a halloween pumpkin",
    "size": "1024x1024"
}'

DALL-E-3 - cURL ​

curl --location 'https://api.saia.ai/proxy/openai/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: $SAIA_APITOKEN" \
-d'{
    "model": "dall-e-3",
    "quality": "hd", 
    "prompt": "a halloween pumpkin",
    "size": "1792x1024" 
}'

The result is expected to be returned as an Url following, for example:

response = json.loads(result.content) # Assuming the result is the POST result
image_url = response.get('data')[0].get('url')

There are no specificities in the generation of requests to the Globant Enterprise AI Proxy, as compared to the direct requests to OpenAI. Therefore, it might prove useful to query the official documents of OpenAI for further details: Image generation.

How to call GPT-4 to interpret images

cURL

curl https://api.saia.ai/proxy/openai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: $SAIA_APITOKEN" \
  -d '{
    "model": "gpt-4-vision-preview",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Describe the content of this image."
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "IMAGE_URL"
            }
          }
        ]
      }
    ],
    "max_tokens": 300
  }'
Make sure to replace "IMAGE_URL" with the URL of the image you want to process.

There are no specificities as to image interpretation using GPT-4 in the Globant Enterprise AI Proxy API, as compared to doing it directly in OpenAI. Therefore, it might prove useful to query the OpenAI documents available at Vision.

Last update: November 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant