- Get an Access Token: Exchange your Client ID and Client Secret for a temporary bearer token, refreshing it when needed.
- Make an API Call: Use the access token to make an authenticated request to the
/chat/completions
endpoint.
Prerequisites
Before starting, ensure you have:- A Gloo AI Studio account
- Your Client ID and Client Secret from the API Credentials page
- Authentication setup - Complete the Authentication Tutorial first
The Completions API requires Bearer token authentication. If you haven’t set up authentication yet, follow the Authentication Tutorial to learn how to exchange your credentials for access tokens and manage token expiration.
Make a Chat Completion Call
Once you have a valid access token (using the authentication methods from the Authentication Tutorial), you can call the Completions API. The examples below show a basic request.Complete Examples
The following examples combine token retrieval, expiration checking, and the API call into a single, runnable script for each language. You’ll want to first set up your environment variables in either an.env
file:
Next Steps
Now that you understand how to use the Completions API, consider exploring:- Authentication Tutorial - For detailed authentication setup
- Completions API - For additional API information
- Chat Tutorial - For stateful chat interactions
- Tool Use - For enhanced completion capabilities