Adapting API Strategies to Dynamic AI Trend
Tags: ai, api, opensource, webdev
Published: 2023-10-01 12:15:18

In today's rapidly evolving technological landscape, Artificial Intelligence (AI) is getting a lot of attention. Everywhere you look on social media, there are new AI startups, prompt engineering tools, and Large Language Model (LLM) solutions. And it's not surprising because AI feels almost like magic! For instance, **ChatGPT**, really got everyone excited. It got 100 million users in just 2 months after it became publicly available, making it super popular, super fast.

Now, everyone's wondering: what does this AI wave mean for me, my work, and my products? More specifically, how does it impact those who are at the forefront of building digital products and applications using APIs? This article explores what the AI trend means for those of us making digital tools using APIs.

## APIs make AI accessible to all

Major companies have been quick to establish dedicated AI research labs, recruiting data scientists to craft AI models. But what about smaller entities without the massive computing resources and GPUs for an AI research lab? Are they to just observe as larger firms capitalize on the AI revolution? The answer is no. For many AI applications, particularly those centered around natural language, there's no need for a special AI research lab. Instead, existing public AI models LLMs, can be utilized. This means that developers don't need to be AI experts they just need to be proficient with APIs. Through prompt engineering, fine-tuning, and embeddings, these models can be customized to serve specific requirements.

The magic word here is "APIs." APIs encapsulate the complexities of their contents, making AI models accessible to all developers, regardless of their expertise in AI. This separation of concerns ensures that while a select few data scientists create AI models and package them as APIs, a larger pool of developers can integrate these models into their applications, crafting "smart" solutions proficient in natural language processing. The outcome is that APIs level the playing field, granting access to powerful AI models for developers of all company sizes.

![Call AI Services via API](https://static.apiseven.com/uploads/2023/09/25/thtbey1w_Adapting%20API%20Strategies%20to%20Dynamic%20AI%20Trend%20%281%29.png)

## AI and API patterns for modern applications

APIs are key in linking your product to everything else. They're great at connecting different software components. When we talk about AI, this connection is even more crucial because AI needs to work with different data sources and tools to be useful. Modern applications consistently leverage both AI and APIs. While AI imparts "smartness" to applications, enabling them to comprehend human language and intent, APIs facilitate data access and system connections. These technologies aren't just parallel entities and their combined use can be synergistic. There are three primary patterns for their integration:

### Pattern 1: Call AI services via API

AI models, like [OpenAI ChatGPT](https://platform.openai.com/docs/api-reference), are often packaged as APIs. Through these APIs, developers can trigger the AI, sending prompts as input allowing developers to integrate AI into their applications seamlessly. A commonly used architecture for building a new AI app also utilizes two OpenAI API endpoints like [Vector Embeddings](https://platform.openai.com/docs/guides/embeddings) and [Chat Completion](https://platform.openai.com/docs/api-reference/chat) as you see in the diagram below:

![Powering ChatGPT via API](https://static.apiseven.com/uploads/2023/09/25/NaGZj9QG_Adapting%20API%20Strategies%20to%20Dynamic%20AI%20Trend%20%282%29.png)

This method first creates [vector embeddings](https://platform.openai.com/docs/guides/embeddings) through OpenAI API for each input document (text, image, CSV, PDF, or other types of structured/unstructured data), then indexes generated embeddings for fast retrieval and save them into storage like vector databases for fast retrieval and these documents are presented to ChatGPT along with a user’s question as a prompt. With this added custom knowledge, ChatGPT can respond intelligently to user queries.

### Pattern 2: AI services call APIs

The output from an AI model in response to a prompt is typically textual. To translate these "ideas" into actionable outcomes, AI services need to call APIs. These APIs can initiate actions in the real or digital world, such as making payments, booking an appointment, sending messages, or adjusting room temperatures. In essence, APIs act as the hands of an AI service, enabling it to interact with its environment. A good example of it can be [ChatGPT custom plugins](https://openai.com/blog/chatgpt-plugins). This [article](https://api7.ai/blog/chatgpt-custom-plugin-for-api-gateway) explains how to build a custom plugin for API Gateway using APISIX. Because APISIX can be in the front of APIs to route AI requests to the intended backend API services. We can implement easily security measures like authentication, authorization, and rate limiting or cache similar responses from APIs and it allows us to gather valuable insights about API usage, performance, and potential issues.

### Pattern 3: AI connects APIs

Years ago, to make two software systems or APIs communicate, the only option was manual coding. software engineers would craft complex and fragile code sequences. This task was solely for developers, and every modification meant more coding, leading to a tangled web of interconnecting codes.

With the advent of generative AI, interacting with an Integration Platform as a Service (iPaaS) could be as straightforward as making a request in a chat. If you want data from one platform to synchronize with another, you don't need to understand the technicalities. You just need to specify your requirements. For instance, you might say, "Sync customer lead scores from Marketo to Salesforce." or ask AI to move data from one API to another. The AI will then handle the process, test its compatibility, and fix any issues autonomously. The APIs used in your integrations are always changing and this sometimes can cause problems. AI can monitor the health of your data integrations and keep fixing the errors or simply send alert notifications in natural language if an entry in an API request or response requires attention.

## Safeguarding API usage

With AI's capability to call APIs that initiate actions in the real or digital world, it's critical to implement safeguards. This safeguarding, ideally implemented at the [API management](https://api7.ai/) system level, is required to ensure the responsible and secure use of AI. This [post](https://api7.ai/blog/api-gateway-for-chatgpt-plugins) explores how API Gateway can be beneficial for ChatGPT plugin developers to **expose, secure, manage, and monitor** their API endpoints.

## In conclusion

APIs provide the perfect building blocks for AI-driven software development. The combination of APIs and AI technologies is vital for developing powerful applications. The three identified patterns—applications integrating AI functionality through APIs and AI services invoking APIs for actions—offer a roadmap for leveraging AI in application development. As the AI landscape continues to evolve, the focus on APIs and the strategies for its integration will become even more important.

## Related resources

[API Gateway For ChatGPT Plugins](https://api7.ai/blog/api-gateway-for-chatgpt-plugins)
[Building a ChatGPT custom plugin for API Gateway](https://api7.ai/blog/chatgpt-custom-plugin-for-api-gateway)

### Community

🙋 [Join the Apache APISIX Community](https://apisix.apache.org/docs/general/join/)

🐦 [Follow us on Twitter](https://twitter.com/ApacheAPISIX)

📝 [Find us on Slack](https://join.slack.com/t/the-asf/shared_invite/zt-vlfbf7ch-HkbNHiU_uDlcH_RvaHv9gQ)

💁 [How to contribute page](https://apisix.apache.org/docs/general/how-to-contribute/)

### About the author

Visit my blog: [www.iambobur.com](https://www.iambobur.com/)