close
close

How to use the OpenAI o1 API

How to use the OpenAI o1 API

OpenAI recently launched the o1 model, the first in a series of “reasoning” models aimed at solving complex problems faster than humans. Along with the smaller o1-mini, this model, often called the “Strawberry” model in AI circles, has received a lot of attention.

The release of o1 marks a milestone in OpenAI’s pursuit of AI models with human-like reasoning capabilities. While o1 excels at handling multistep problems and coding tasks, it comes at a higher cost and slower performance compared to GPT-4o. Despite being labeled as a “preview,” it offers a tantalizing glimpse into the future of AI technology.

💡 Improve your workflow with Apidog!

Looking for an API testing tool that simplifies your workflow? Apidog is an all-in-one solution for sending requests, debugging APIs, and optimizing development processes. Whether you’re processing simple requests or complex cURL commands, Apidog’s intuitive interface makes API testing easy.

Sign up for free

How do you use OpenAI o1?

ChatGPT Plus and Team users will have access to both o1-preview and o1-mini via the plan selector. Initially, usage will be limited to 30 messages per week for o1-preview and 50 for o1-mini, but OpenAI plans to expand these limits soon.

For developers, API access is available to those in usage level 5, with a rate limit of 20 requests per minute. The API currently lacks features such as function calls, streaming, and system messages, though OpenAI is working on adding these capabilities. Full API documentation is available for more information.

What makes OpenAI o1 unique?

o1 is trained using a new optimization algorithm and dataset, applying reinforcement learning instead of the pattern-mimicking methods of previous models. This allows it to solve problems step by step, similar to how humans tackle complex tasks. It produces more accurate answers with fewer hallucinations, although OpenAI acknowledges that hallucinations still occur.

Improved problem solving capabilities

In internal testing, o1 outperformed GPT-4o in tasks like coding and solving mathematical problems, placing in the 89th percentile in Codeforces competitions and scoring 83% on a qualifying exam for the International Mathematical Olympiad, significantly better than GPT-4o’s 13%.

Limitations of OpenAI o1

Although o1 excels at reasoning tasks, it does have limitations. It lacks the extensive factual knowledge of GPT-4o, cannot browse the web, and cannot process files or images. Despite these shortcomings, OpenAI sees o1 as the first of a new class of AI models, representing a shift in both AI naming conventions and technical capabilities.

How do I use the OpenAI o1 API?

If you’d like to use OpenAI’s latest model, o1, for its improved reasoning capabilities, you can follow this quick guide to get started:

1. Get access to the OpenAI o1 API

  • Visit the OpenAI website to sign up or log in for API access.
  • Go to the API Keys section to generate your API key. Please note that o1 is more expensive than previous models such as GPT-4o.

2. Install the OpenAI Python library

Install the OpenAI Python library on your local machine with this command:

pip install openai
Go to full screen mode

Exit full screen

3. Make your first API call

With your API key, you can now make your first API call in Python:

import openai

def get_chat_completion(prompt, model="o1-preview"):
    messages = ({"role": "user", "content": prompt})
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0,
    )
    return response.choices(0).message("content")

response = get_chat_completion("Translate into Spanish: I am learning to use OpenAI API!")
print(response)
Go to full screen mode

Exit full screen

This function sends a prompt to the o1-preview model and returns a response.

4. Integrate the OpenAI o1 API into your project

If you’re working with a web framework like Flask or Django, you can embed OpenAI API calls into your routes or views.

Example with Flask:

from flask import Flask, request, jsonify
import openai

app = Flask(__name__)

openai.api_key = "your-api-key-here"

@app.route('/ask', methods=('POST'))
def ask_openai():
    prompt = request.json('prompt')
    response = openai.Completion.create(
        model="o1-preview",
        prompt=prompt,
        max_tokens=100
    )
    return jsonify(response.choices(0).text)

if __name__ == '__main__':
    app.run(debug=True)
Go to full screen mode

Exit full screen

This code sets up an API route /ask where users can send a prompt and the application will return the response generated by OpenAI.

An easier way to test OpenAI o1 API – using Apidog

Apidog is a powerful API testing tool similar to Postman. You can send cURL requests to OpenAI’s API with Apidog. Here’s how to set up a POST request:

curl https://api.openai.com/v1/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "o1-preview",
    "prompt": "Explain the theory of relativity in simple terms.",
    "max_tokens": 150
  }'
Go to full screen mode

Exit full screen

Copy the above cURL code and paste it into Apidog’s search bar:

Testing API Endpoints with Apidog

Replace $OPENAI_API_KEY with your actual API bearer token. After sending the request, you will receive a detailed response report.

Enter the bearer token into Apidog

Once the API is ready to use, you can generate client code directly in Apidog and use it for direct implementation in a real project.

Learn how to get bearer token with Apidog.

Building the future

Although o1 is still in its early stages, it represents a significant leap in AI, particularly for reasoning and problem-solving tasks. Despite its higher cost and slower speed, it shows the future of AI, where models not only recognize patterns but also reason through them.

As OpenAI continues to refine this series, the introduction of o1 lays the foundation for future developments in AI, bringing us closer to a world where machines can solve increasingly complex problems.