Authentication

Make sure to follow the previous steps described in Authentication to obtain an API key and account ID.

Starter Code

Let’s test your setup with with some simple starter code. Here, we’ll using the Completions API to ask GPT 4 to complete the prompt Hello, what can you do?

Python

import requests
import os

# Replace this with your actual API Key
MY_API_KEY = os.environ.get("MY_API_KEY")

headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "x-api-key": MY_API_KEY,
}
payload = {
    "model": "gpt-4",
    "prompt": "Hello, what can you do?"
}

response = requests.post("https://api.egp.scale.com/egp/v1/completions", json=payload, headers=headers)

print(response.text)

You should see a response like the following:

JSON

{
  "completion":{
    "text":"Hello! I'm an AI developed by OpenAI and I'm capable of performing tasks like answering questions, participating in discussions, learning from text inputs, and much more. I assist with generating human-like text based on the prompts given to me. Note that I don't access personal data unless directly provided in the conversation. I am designed to respect user privacy and confidentiality.",
    "finish_reason":null
  },
  "token_usage":{
    "prompt":14,
    "completion":74,
    "total":88
  }
}