**Introduction**

Welcome to NextAI Documentation 🎉

A step by step easy documentation to get started with Inferencing NextAI’s open source models.

You can also checkout our small 3-5 mins video tutorials to here. 🚀

Getting Started 📑

You can interact with the Next AI’s API through HTTP requests from any language, via our official Python bindings, our official Node.js library

To install the official Python bindings, run the following command

pip install openai

Visit your API Keys page to retrieve the API key or you can even find API Key for the model deployed in model details you'll use API Key in your requests .

All API requests should include your API key in an Authorization HTTP header as follows:

Authorization: Bearer NextAI_API_KEY

NextAI’s APIs are OpenAI API compatible to facilitate the migration from openAI APIs to NextAI APIs with just 2 lines of code changes.

Make sure you set the base url to point to Next API endpoint of deployed model and set the API key provided to you.

Interact with your model

import os
from openai import OpenAI
%env NEXTAI_API_KEY=#add your NextAI api key here

client = OpenAI(
    api_key=os.environ.get("NEXTAI_API_KEY"),
    base_url = "add your end point URL"  #example: <https://zephyr.nextai.co.in/v1>
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Tell me a hello world joke",
        }
    ],
    model="add your model name", #example: zephyr-7b-alpha
)

Interact with your model in Streaming

stream = client.chat.completions.create(
    model="add your model name", #example: zephyr-7b-alpha
    messages=[{"role": "user", "content": "Tell a hello world joke"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

JSON mode:

you can set response_format to { "type": "json_object" } to enable JSON mode.

response = client.chat.completions.create(
  model="zephyr-7b-alpha",
  response_format={ "type": "json_object" },
  messages=[
    {"role": "system", "content": "You are a helpful assistant designed to output JSON."},
    {"role": "user", "content": "Who won the world series in 2023?"}
  ]
)
print(response.choices[0].message.content)