Quick Start
Using RIFX via API
To start using RIFX through API, you can call our API in the following ways:
import requestsimport json
# Send POST request using requests libraryresponse = requests.post( url="https://api.rifx.online/v1/chat/completions", headers={ "Authorization": f"Bearer {RIFX_API_KEY}" # Authorize using your API key }, data=json.dumps({ "model": "gpt-4o-mini", # Specify the model to use "messages": [ { "role": "user", # Message role "content": "What is the purpose of existence?" # User input content } ] }))
// Send POST request using fetch APIfetch("https://api.rifx.online/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${RIFX_API_KEY}`, // Authorize using your API key "Content-Type": "application/json" // Specify request body content type }, body: JSON.stringify({ "model": "gpt-4o-mini", // Specify the model to use "messages": [ { "role": "user", // Message role "content": "What is the purpose of existence?" // User input content } ] })});
# Send POST request using curl commandcurl https://api.rifx.online/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $RIFX_API_KEY" \ -d '{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "What is the purpose of existence?" } ]}'
Using OpenAI Client API
You can also interact with RIFX API using OpenAI’s client API. Here are examples in Python and TypeScript:
from openai import OpenAIfrom os import getenv
# Get API key from environment variable RIFX_API_KEYclient = OpenAI( base_url="https://api.rifx.online/v1", api_key=getenv("RIFX_API_KEY"),)
# Send request using OpenAI client librarycompletion = client.chat.completions.create( model="gpt-4o-mini", # Specify the model to use messages=[ { "role": "user", # Message role "content": "What is the purpose of existence?" # User input content } ])
# Print responseprint(completion.choices[0].message.content)
import OpenAI from "openai";
// Set up OpenAI API clientconst openai = new OpenAI({ baseURL: "https://api.rifx.online/v1", apiKey: process.env.RIFX_API_KEY});
// Send request using OpenAI client libraryasync function main() { const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", // Specify the model to use messages: [ { role: "user", // Message role content: "What is the purpose of existence?" // User input content } ] });
// Print response console.log(completion.choices[0].message);}
main();
Important Notes
- API Key: Ensure you have obtained a valid RIFX API key and store it securely.
- Error Handling: In production applications, it’s recommended to add error handling logic to properly manage request failures.
- Model Selection: Choose appropriate models based on your needs;
gpt-4o-mini
is an example model.
With these examples, you can quickly integrate RIFX API into your applications. Choose the implementation method that best suits your programming language and requirements.