Back to APIs
AI & MLBearer Token
OpenAI
Access state-of-the-art language models, image generation, speech-to-text, and embeddings through a simple REST API.
Base URL
https://api.openai.com/v1GPT-4oembeddingsimagesspeechmoderation
Endpoints
POST
/chat/completionsGenerate a chat completion using GPT-4o or another model.
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
},
body: JSON.stringify({
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
})
});
const data = await response.json();
console.log(data);Response Preview
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "gpt-4o",
"choices": [{
"message": { "role": "assistant", "content": "Hello! How can I help you today?" },
"finish_reason": "stop",
"index": 0
}],
"usage": { "prompt_tokens": 10, "completion_tokens": 9 }
}POST
/embeddingsCreate a vector embedding for a given text input.
const response = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
},
body: JSON.stringify({
"model": "text-embedding-3-small",
"input": "The quick brown fox"
})
});
const data = await response.json();
console.log(data);Response Preview
{
"object": "list",
"data": [{
"object": "embedding",
"embedding": [0.0023, -0.009, "..."],
"index": 0
}],
"model": "text-embedding-3-small",
"usage": { "prompt_tokens": 5, "total_tokens": 5 }
}