Skip to main content
Gloo AI is designed to be drop-in compatible with the OpenAI API format. This means you can use the official, community-maintained OpenAI SDKs for Python and Node.js to build values-aligned applications without learning a new syntax.
Compatibility Mode You do not need to install a specific “Gloo” library. You simply configure the standard OpenAI client to point to Gloo AI’s infrastructure.

Prerequisites: Authentication

Before using the SDK, you need to obtain an access token using your Client ID and Client Secret. Gloo AI uses OAuth2 client credentials flow—there are no long-lived API keys.
1

Get your credentials

Obtain your Client ID and Client Secret from the API Credentials page in Gloo AI Studio.
2

Exchange for access token

Use your credentials to get a temporary bearer token (expires in 1 hour).
3

Use token in SDK

Pass the access token as the api_key parameter in the OpenAI client.
Access tokens expire after 1 hour. Your application must handle token refresh. See the Authentication Tutorial for complete token management patterns.

Python

The Python library is the standard for AI engineering and data science.
1

Install the libraries

Use pip to install the OpenAI package and requests for token exchange.
pip install openai requests python-dotenv
2

Set up environment variables

Create a .env file with your credentials:
GLOO_CLIENT_ID=your_client_id_here
GLOO_CLIENT_SECRET=your_client_secret_here
3

Get access token and configure the client

Exchange your credentials for an access token, then initialize the OpenAI client.
import os
import requests
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()

# Step 1: Exchange credentials for access token
def get_access_token():
    response = requests.post(
        "https://platform.ai.gloo.com/oauth2/token",
        headers={"Content-Type": "application/x-www-form-urlencoded"},
        data={"grant_type": "client_credentials", "scope": "api/access"},
        auth=(os.getenv("GLOO_CLIENT_ID"), os.getenv("GLOO_CLIENT_SECRET"))
    )
    response.raise_for_status()
    return response.json()["access_token"]

# Step 2: Initialize OpenAI client with Gloo AI
client = OpenAI(
    api_key=get_access_token(),  # Use access token as api_key
    base_url="https://platform.ai.gloo.com/ai/v1"
)

# Step 3: Make a request
completion = client.chat.completions.create(
    model="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello world!"}
    ]
)

print(completion.choices[0].message.content)
For production applications, implement token caching and automatic refresh. See the Authentication Tutorial for a complete TokenManager class.

Node.js / TypeScript

Perfect for full-stack developers and web applications.
1

Install the libraries

npm install openai axios dotenv
2

Set up environment variables

Create a .env file with your credentials:
GLOO_CLIENT_ID=your_client_id_here
GLOO_CLIENT_SECRET=your_client_secret_here
3

Get access token and configure the client

Exchange your credentials for an access token, then initialize the OpenAI client.
import OpenAI from "openai";
import axios from "axios";
import * as dotenv from "dotenv";

dotenv.config();

// Step 1: Exchange credentials for access token
async function getAccessToken(): Promise<string> {
  const response = await axios.post(
    "https://platform.ai.gloo.com/oauth2/token",
    "grant_type=client_credentials&scope=api/access",
    {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      auth: {
        username: process.env.GLOO_CLIENT_ID!,
        password: process.env.GLOO_CLIENT_SECRET!,
      },
    }
  );
  return response.data.access_token;
}

async function main() {
  // Step 2: Initialize OpenAI client with Gloo AI
  const client = new OpenAI({
    apiKey: await getAccessToken(), // Use access token as apiKey
    baseURL: "https://platform.ai.gloo.com/ai/v1",
  });

  // Step 3: Make a request
  const completion = await client.chat.completions.create({
    model: "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    messages: [{ role: "user", content: "Say this is a test" }],
  });

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

main();
For production applications, implement token caching and automatic refresh. See the Authentication Tutorial for complete token management patterns.

Vibe Coding & Editor Setup

Because Gloo AI adheres to open standards, you can use it directly inside AI-native code editors (like Cursor, Windsurf, or VS Code) to “vibe code” with values-aligned models.

Cursor / VS Code

  1. Go to Settings > Models
  2. Add a Custom Provider
  3. Set URL: https://platform.ai.gloo.com/ai/v1
  4. Generate an access token and paste it as the API key

Agent Frameworks

Compatible with LangChain, CrewAI, and AutoGen by setting the openai_api_base parameter and providing an access token.
Access tokens expire after 1 hour. For editor integrations, you’ll need to generate a new token periodically via the API Credentials page or programmatically using the OAuth2 flow.

Supported Models

When using the SDK, you must use the exact Model IDs supported by Gloo AI. Here are some commonly used models:
ProviderModel ID
Anthropicus.anthropic.claude-3-5-sonnet-20241022-v2:0
Anthropicus.anthropic.claude-3-opus-20240229-v1:0
Metameta.llama3-70b-instruct-v1:0
Mistralmistral.mistral-large-2402-v1:0
See the Supported Models page for the full list of available Model IDs and their capabilities.