View Categories

Making an API request

The GPTNow API is formatted for compatibility with OpenAI. By altering the configuration, one can utilize the OpenAI SDK or other software that is compatible with the OpenAI API to access the GPTNow API.

Parameter Value
base_url *https://api.gptnow.net
api_keyYour GPTNow API Key
* To be compatible with OpenAI, you can also use https://api.gptnow.net/v1/chat/completions as the base_url.

Invoke The Chat API #

After acquiring an API key, you can utilize the GPTNow API by employing the provided example scripts.

Bash #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
curl https://api.gptnow.net/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $Your GPTNow API Key" \
  -d '{
        "model": "gpt-4o",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Hello!"}
        ],
        "stream": true
      }'

Python 3 #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from openai import OpenAI

client = OpenAI(api_key="Your GPTNow API Key", base_url="https://api.gptnow.net")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"},
    ],
    stream=true
)

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

Node.js #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }],
    model: "gpt-4o",
  });

  console.log(completion.choices[0]);
}

main();