Generative AI API
TIR’s Generative AI (GenAI) API offers a suite of ready-to-use inference endpoints, enabling seamless interaction with advanced models for text-to-text, speech-to-text, embeddings, and text-to-speech tasks. These APIs provide developers with the tools to easily integrate generative AI capabilities into their applications.
Key features:
Cost Effectiveness: You’re only charged for the requests you make. Allowing you to control expenses while scaling according to your needs.
Ready to Use: GenAI APIs are always available and can be accessed anytime, providing instant integration into your applications with no commitments or long-term contracts. Use them as needed without worrying about setup or lock-in periods.
Playground : Test and explore models capabilities directly on TIRs UI in the Playground section after selecting the Model
Note
Billing parameters may vary based on the model you use. For more information on pricing, select the model you are interested in and refer to the usage section.
Quick Start
How to Integrate GenAI API with your application ?
Integration methods vary depending on the model you use. Detailed steps for each model can be found in the Playground or API section.
Here are the available integration options:
Rest API: This method is compatible with ll models. Use the REST API endpoints for straightforward integration.
OpenAI SDK: All LLMs (text generation) models such as Llama and Mistral on TIR GenAI are OpenAI compatible. you can integrate by updating the OPENAI_BASE_URL and OPENAI_API_KEY in your application if it uses openai sdk. Start with sample code provided on TIRs UI.
TIR SDK: It is a dedicated SDK for lauching and manging services on E2E network’s TIR platform
We will go through all the integrations options in this doc. To access the model you need to create Token.
Generating Token To Access GenAI Models
- Navigate to the API Token Section on TIRs UI using the side navbar
Create new Token
- Copy the Auth Token and API Key.
Note
OPENAI_API_KEY for the openai compatible model is the auth token copied in the previous step
Accessing GenAI using Rest API
For this example we will use Mistral 7B Instruct v0.3 Model. Mistral is Text generations Large language model
- Select Mistral 7B Instruct v0.3 card in the GenAI section
- Open the HTTP tab to find the cURL request for the model
Copy the cURL request into any API testing tool. For this tutorial, we’ll use Postman. Before making the request, add the Auth token (generated in the Generating Token to Access GenAI Models section) to the Authorization Header.
Note
For all API requests, the Auth token is of type Bearer.
After adding the token, modify the payload based on your requirement send the request. You can also generate sample code for various languages in Postman’s Code section.
Accessing GenAI using OpenAI SDK
For this example we will use Llama 3.1 8B Instruct Model. Llama is Text generations Large language model. #. Select Llama 3.1 8B Instruct card in the GenAI section
- For this tutorial, we’ll write the script in Python. Open the Python tab and copy the sample Python code
Install OpenAI package using pip
pip install -U openai
Paste the sample code in python file and change value the api_key parameter passed in openai client with the Auth Token generated in the Generating Token to Access GenAI Models section
Run the python script and response will be printed
Accessing GenAI using TIR SDK
For this example we will use Whisper Large V3 Model. Whisper is Speech to text model which can used for tasks like Transcribe, Translate. #. Select Whisper Large V3 card in the GenAI section
- TIR SDK is written in python, so head to API tab can copy sample code. Add path of audio file in the input field of data dict and tweak other parameters
Before running the script export environment in terminal, replace env values for E2E_TIR_ACCESS_TOKEN and E2E_TIR_API_KEY with token generated in in the Generating Token to Access GenAI Models section
- Run the script and the response will be printed
How to Check Usage & Pricing of GenAI API ?
For Example select Vector Embeddings model card in the GenAI section
- Open Usage tab or click on Check Pricing
- Open Usage tab or click on Check Pricing. You can also specify custom interval to check billing between specific dates.
Note
When Multiple Billing parameter are associated with model it will be mentioned in the usage table along with their costing