Stripe is a top provider of payment infrastructure and long known for having a fantastic developer...
Story time ... via OpenAI API
OpenAI continues to improve in both it's models and it's applicability to essentially everything we do today. Of course, there are now a number of useful options available but today we're going take a dive into the OpenAI API and see what's possible.
OpenAI offers a variety of APIs that empower developers to integrate advanced AI functionalities into their applications. In this guide, we’ll show you how to use Bruno to explore and test OpenAI’s API capabilities, such as generating text, creating embeddings, and more.
We've created a public repository on GitHub containing OpenAI API collections for Bruno. These collections provide request templates for all API endpoints, have pre-configured bodies, and are set up to inherit authentication after you enter it in the collection settings. Once you have a key, you can start exploring the surface area of the API in 60 seconds or less.
Let’s get started! 🚀
Getting Started with the OpenAI API Collection in Bruno
To begin, you’ll need to download and install Bruno, which is available for Windows, macOS, and Linux.
Once installed, you’ll fetch 🐶 your API collection for OpenAI.
Step 1: Clone the Repo from GitHub into Bruno
-
Clone the public GitHub repository containing OpenAI’s Bruno Collections.
-
Open the collection in Bruno.
If unfamiliar with Git, follow these instructions on cloning a repository.
Step 2: Set Up the Environment
-
Click on Environment Variables and create a new Collection Environment called
OpenAI
. -
Add a variable called
openaikey
and set its value to your OpenAI API key. Mark this as 'secret'.You can obtain your API key by logging into your OpenAI account and navigating to the API Keys section in your OpenAI dashboard.
Step 3: Configure Authentication
-
In your OpenAI API Collection, open Settings.
-
Under Auth, select Bearer Token and set the token value to
.
-
Save the changes. This configuration ensures that all requests in the OpenAI collection use your API credentials for authentication. All requests in this collection use the
Inherit
method of Auth, so it will automatically insert your key when making calls.
Exploring the OpenAI API Using Bruno
The OpenAI API is organized into several endpoints, including completions
, edits
, embeddings
, and more. Each endpoint in the collection includes all possible request methods (e.g., POST) and parameters.
Example: Generating a Text Completion
To generate a text completion, follow these steps:
-
Navigate to the
Chat Completions
folder underAPI Capabilities
. -
Select the
Create Completions
request. -
Click Send.
In this example, we've passed over the request of "Write me a short story about Bruno the dog" in the Content
for "role": "user"
.
If everything is set up correctly, you’ll receive a response from OpenAI with the generated text. Bruno’s response viewer makes it easy to review and understand the data.
A lovely story, if I do say so myself!
This example also has a number of tests written against it that you can view within both the Tests
tab of the request and the response:
These tests could also be automated by using Bruno's CLI in your pipeline.
Example: Creating Embeddings for Text
Embeddings are useful for tasks like similarity search or clustering. Here’s how to generate embeddings:
-
Navigate to the
Embeddings
folder underAPI Capabilities
. -
Select the
Create Embedding
request. -
Click Send.
In this example, we're generating embeddings based on the input of "OpenAI provides advanced AI tools".
You’ll receive a response containing the embeddings, which you can use in your applications.
Why Use OpenAI Embeddings?
- Efficiency: They reduce text to a fixed-size numerical representation that can be processed quickly.
- Versatility: Can be used across various NLP tasks, even without fine-tuning.
- Contextual Understanding: Capture nuances of meaning, enabling tasks like semantic search and retrieval to work effectively.
By leveraging embeddings, you can build systems that understand and process data in a way that aligns closely with human semantic reasoning.
Test Advanced Use Cases
Once you’re familiar with making API requests to OpenAI with Bruno, try combining endpoints to test advanced scenarios. Here are a few ideas:
-
Build a Q&A Bot: Use
completions
to process user questions and generate intelligent responses. -
Create a Search System: Use
embeddings
for similarity searches on a dataset of text documents. -
Experiment with Fine-Tuned Models: Test a fine-tuned model by passing the model ID in your API requests.
Why Use Bruno?
Here are a few reasons why developers are choosing Bruno as their API client:
Feature | Bruno | Others |
---|---|---|
Pricing | Open Source & Affordable Paid Plans | Free & Expensive Paid Plans |
Data Storage | All data stored locally | Requires Cloud Sync |
Collaboration | Local projects, Native Git Sync | Cloud-based Sharing |
UI/UX | Clean, modern interface | Complex, Bloated |
Bruno Advantages
-
Local-First: Bruno saves everything locally, ensuring faster and more secure workflows for those who prefer not to use cloud storage.
-
Native Git: Directly sync, version, store, and collaborate with your team using any Git provider.
-
Open Source: You have full control over the tool and can contribute to its development.
-
Lightweight: Bruno is fast, simple, and focused on API development without unnecessary bloat.
Summary
Using Bruno to test and explore OpenAI’s APIs is simple, powerful, and available through Git. From setting up authentication to building complex API requests, Bruno offers a lightweight, open-source way to manage your API workflows.
With Bruno, you can:
-
Authenticate requests using your OpenAI API key.
-
Explore endpoints like
completions
andembeddings
. -
Create simple or advanced AI-driven workflows.
We look forward to seeing what you build using OpenAI and Bruno. If you’d like OpenAI to maintain their own Bruno collections on GitHub, let them know @OpenAIDevs!