Quickstart
Develop Your AI-Powered Intelligent Assistant
The Hispread API provides a simple interface to state-of-the-art AI models for natural language processing, image generation, semantic search, and speech recognition. Follow this guide to learn how to generate human-like responses to natural language prompts for semantic search.
Create and Export an API Key
First, create an API key in the Hispread dashboard. Visit Create an API key in the dashboard to generate your key. Save the key in a safe location (for example, in a .zshrc
file or another secure note).
Once your API key is generated, export it as an environment variable in your terminal.
macOS / Linux
Export an environment variable on macOS or Linux systems:
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://api.myhispreadnlp.com/v1/"
Windows
Export an environment variable in PowerShell:
setx OPENAI_API_KEY "your_api_key_here"
setx OPENAI_BASE_URL "https://api.myhispreadnlp.com/v1/"
Make Your First API Request
With your HISPREAD_API_KEY exported as an environment variable, you're ready to make your first API request. You can either use the REST API directly with the HTTP client of your choice or use one of our official SDKs as shown below.
Using Node.js
To use the Hispread API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official SDK. Install the SDK using npm:
NodeJS: Install the SDK
npm install openai
Although the module name is still "openai", it is configured to interact with the Hispread API.
Create a file called example.mjs
and use one of the following examples:
Create a Human-Like Response to a Prompt
import OpenAI from "openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{
role: "user",
content: "Write a haiku about recursion in programming."
},
],
});
console.log(completion.choices[0].message);
Generate an Image Based on a Textual Prompt
import OpenAI from "openai";
const openai = new OpenAI();
const image = await openai.images.generate({ prompt: "A cute baby sea otter" });
console.log(image.data[0].url);
Create Vector Embeddings for a String of Text
import OpenAI from "openai";
const openai = new OpenAI();
const embedding = await openai.embeddings.create({
model: "text-embedding-3-large",
input: "The quick brown fox jumped over the lazy dog",
});
console.log(embedding);
Execute the code with:
node example.mjs
In a few moments, you should see the output of your API request.
Using Python
To use the Hispread API in Python, install the official SDK with pip:
Install the SDK
pip install openai
Create a file called example.py
and try one of the following examples:
Create a Human-Like Response to a Prompt
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
]
)
print(completion.choices[0].message)
Generate an Image Based on a Textual Prompt
from openai import OpenAI
client = OpenAI()
response = client.images.generate(
prompt="A cute baby sea otter",
n=2,
size="1024x1024"
)
print(response.data[0].url)
Create Vector Embeddings for a String of Text
from openai import OpenAI
client = OpenAI()
response = client.embeddings.create(
model="text-embedding-3-large",
input="The food was delicious and the waiter..."
)
print(response)
Execute your Python script with:
python example.py
You should see the output of your API request in a few moments.
Using curl
On Unix-based systems, you can test the Hispread REST API using curl. The examples below assume that you have exported the HISPREAD_API_KEY environment variable as shown above.
Create a Human-Like Response to a Prompt
curl "https://api.myhispreadnlp.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $HISPREAD_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Write a haiku that explains the concept of recursion."
}
]
}'
Generate an Image Based on a Textual Prompt
curl "https://api.myhispreadnlp.com/v1/images/generations" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $HISPREAD_API_KEY" \
-d '{
"prompt": "A cute baby sea otter",
"n": 2,
"size": "1024x1024"
}'
Create Vector Embeddings for a String of Text
curl "https://api.myhispreadnlp.com/v1/embeddings" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $HISPREAD_API_KEY" \
-d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-3-large"
}'
Run these curl commands in your terminal. In a few moments, you should see the corresponding API response.
Next Steps
Now that you've made your first Hispread API request, you can explore additional resources:
-
Chat Completions
Learn more about generating text responses to natural language prompts. -
Fine-tuning
Fine-tune our models with your own data. -
Batch
Learn about batching requests for asynchronous jobs. -
Full API Reference
View the full REST API reference for more details.
Enjoy building with the Hispread API, and feel free to refer back to this guide whenever you need a refresher!
Updated 3 months ago