Skip to main content

Using models by API

Calling a hosted model by API is the fastest way to start using Ai2’s Olmo models. There's no hardware to manage and you only pay for the tokens you use. Ai2 models are available on OpenRouter, or directly through our inference providers Cirrascale and Parasail.

This Quick Start covers everything you need to make your first API call using Python or TypeScript, including environment setup, authentication, sending a test request, and printing the model’s response.

OpenRouter​

Prerequisites​

Before you start, make sure you have the following:

  • An OpenRouter API key. You can generate a new key from your OpenRouter Keys page.
  • A development environment with either Python or Node.js installed.

1. Set up your project​

First, prepare your development environment by installing the OpenAI client library.

If you want to use Python, install the official openai library using pip.

pip install openai
OpenAI Compatible

OpenRouter provides OpenAI-compatible endpoints, which means you can use OpenAI's official client libraries and API structure to interact with Olmo models.

2. Set your API key​

For security, set your API key as an environment variable in your terminal. Both the Python and TypeScript scripts will read this variable to authenticate your calls.

export OPENROUTER_API_KEY="YOUR_KEY_HERE"

3. Create the test script​

Now, create a script to initialize the client and call the Olmo API via OpenRouter.

Create a file named test_openrouter.py. This script sends a prompt to the allenai/olmo-3-32b-think model:

test_openrouter.py

import os
from openai import OpenAI

# Initialize the client with your key and the OpenRouter base URL
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.environ.get("OPENROUTER_API_KEY"),
)

print("Sending request to Olmo model via OpenRouter...")

# Send a request to the Olmo chat model
response = client.chat.completions.create(
model="allenai/olmo-3-32b-think",
messages=[
{
"role": "user",
"content": "What are 5 things to do in Seattle?",
}
],
)

# Print the model's response
print("\n--- Model Response ---")
print(response.choices[0].message.content)
Finding Available Models

To ensure you are using a valid model name, check the official OpenRouter Models page or use the OpenRouter API to get a list of available models. OpenRouter uses a provider/model-name format (e.g., allenai/olmo-3-32b-think), and this page provides the exact identifiers for all available models.

Explore the OpenRouter Documentation

For more details on features like routing, fallbacks, and usage metrics, please refer to the official OpenRouter Documentation.

4. Execute the test​

Finally, run your script from the terminal to get a response from the model.

Execute the Python script by running:

python test_openrouter.py

You should see a list of five things to do in Seattle printed to your console, as the following example output illustrates:

Sending request to Olmo model via OpenRouter...

--- Model Response ---
1. Visit Pike Place Market: A bustling marketplace with unique shops, fresh produce, and seafood. Don't miss the iconic salmon toss at Pike Place Fish Market.

2. Explore the Seattle Aquarium: Get up close with seals, octopuses, and a mangrove forest exhibit while learning about the diverse marine environments around Seattle.

3. Experience the Space Needle: ascend to the top for stunning 360-degree views of the city and surroundings. Enjoy a rotating restaurant if you wish to have a meal with a view.

4. Wander the Seattle Art Museum (SAM) and Museum of Pop Culture (MoPOP): SAM hosts modern and contemporary art, while MoPOP explores popular culture through music, sci-fi, and fantasy exhibitions.

5. Hike at Discovery Park: Enjoy over 520 acres of natural landscapes and trails, home to magnificent views, historical military sites, and a lighthouse. Great for photography and picnics.

Enjoy exploring Seattle's rich culture, natural beauty, and delicious cuisine!

Cirrascale​

Prerequisites​

Before you start, make sure you have the following:

  • A Cirrascale API key and the endpoint to access the API. You can generate a new key and get the endpoint URL from your Cirrascale account console. Cirrascale API Key
  • A development environment. You need either Python or Node.js with TypeScript installed.

1. Set up your project​

First, prepare your development environment by installing the OpenAI client library.

Install the official openai library using pip.

pip install openai
OpenAI Compatible

Cirrascale provides OpenAI-compatible endpoints, which means you can use OpenAI's official client libraries and API structure to interact with Olmo models.

2. Set your API key​

For security, set your API key as an environment variable in your terminal. Both the Python and TypeScript scripts will read this variable to authenticate your calls to the Cirrascale API.

export CIRRASCALE_API_KEY="YOUR_KEY_HERE"

3. Create the test script​

Now, create a script to initialize the client and call the Olmo API.

Create a file named test_olmo.py. This script sends a prompt to the OLMo-2-0325-32B-Instruct model and prints its response.

test_olmo.py

import os
from openai import OpenAI

# Initialize the client with your key and the Cirrascale base URL
client = OpenAI(
api_key=os.environ.get("CIRRASCALE_API_KEY"),
base_url="https://ai2endpoints.cirrascale.ai/api",
)

print("Sending request to Olmo model...")

# Send a request to the Olmo chat model
resp = client.chat.completions.create(
model="OLMo-2-0325-32B-Instruct",
messages=[{"role": "user", "content": "What are 5 things to do in Seattle?"}]
)

# Print the model's response
print("\n--- Model Response ---")
print(resp.choices[0].message.content)
Finding Available Models

To ensure you are using a valid model name, you can get a complete list by sending a GET request to https://ai2endpoints.cirrascale.ai/api/models with your API key. The response will show all model IDs available for use.

OpenAI API Reference

Because the Cirrascale API is OpenAI-compatible, the official OpenAI API documentation is an excellent resource for understanding request parameters like temperature, top_p, and streaming options.

4. Execute the test​

Finally, run your script from the terminal to get a response from the model.

Execute the Python script directly.

python test_olmo.py

You should see a list of five things to do in Seattle printed to your console, as the following example output illustrates:

Sending request to Olmo model...

--- Model Response ---
1. Space Needle: For an unmatched panoramic view of Seattle and various attractions, a trip to the Space Needle is a must. Reserved tables at Loupe Bar & Terrace, located at the top, offer an exclusive atmosphere for enjoying drinks with a view.

2. Seattle Art Museum (SAM) and Olympic Sculpture Park: Explore SAM's extensive collection consisting of American, European, and Asian art spanning centuries. Just outside, the Olympic Sculpture Park provides an exciting and serene outdoor experience featuring sculptures from internationally recognized artists.

3. Pike Place Market: The famous market is known for its fresh flowers, seafood, and produce. Be sure to check out the original Starbucks at Pike Place and watch the iconic flying fish at the Pike Place Fish Market, where the staff toss fish for customer orders.

4. Museum of Pop Culture (MoPOP): Explore the museum's exhibits dedicated to popular culture, including music, sci-fi, games, and more. The museum features interactive exhibits that appeal to all ages.

5. Chihuly Garden and Glass: Visit this stunning glass exhibit and enjoy Dale Chihuly's remarkable glass installations both indoors and out. Experience the breathtaking, colorful displays of glass art during sunset for an especially magical experience.

Each of these attractions offers unique experiences that showcase Seattle's unique character and attractions.
Explore the Cirrascale Documentation

For more details on quotas, rate limits, and billing, please refer to the official Cirrascale API Reference.

Parasail​

Prerequisites​

Before you start, make sure you have the following:

  • A Parasail API key. You can generate a new key by creating an account on the Parasail platform and navigating to your Parasail API Keys page.
  • A development environment with either Python or Node.js installed.

1. Set up your project​

First, prepare your development environment by installing the OpenAI client library.

If you want to use Python, install the openai library using pip.

pip install openai
OpenAI Compatible

Parasail provides OpenAI-compatible endpoints, which means you can use OpenAI's official client libraries and API structure to interact with Olmo models.

2. Set your API key​

For security, set your API key as an environment variable in your terminal. Both the Python and TypeScript scripts will read this variable to authenticate your calls.

export PARASAIL_API_KEY="YOUR_KEY_HERE"

3. Create the test script​

Now, create a script to construct the API request and call the Olmo API via Parasail.

Create a file named test_parasail.py. This script sends a prompt to the Olmo-3-32B-Think model.

test_parasail.py

import os
from openai import OpenAI

# The client uses the API key from your environment and the specific Parasail URL.
client = OpenAI(
api_key=os.environ.get("PARASAIL_API_KEY"),
base_url="https://api.parasail.io/v1",
)

print("Sending request to Olmo model...")
# This sends a request to the Olmo chat model.
resp = client.chat.completions.create(
model="Olmo-3-32B-Think",
messages=[{"role":"user","content":"What are 5 things to do in Seattle"}]
)

print("--- Model Response ---")
print(resp.choices[0].message.content)

4. Execute the test​

Finally, run your script from the terminal to get a response from the model.

Execute the Python script by running:

python test_parasail.py

You should see a list of five things to do in Seattle printed to your console, as the following example output illustrates:

Sending request to Olmo model...

--- Model Response ---
1. **Pike Place Market**: Explore one of the oldest farmers' markets in the US. Pike Place Market is a vibrant area with fresh produce, seafood, flowers, and local crafts. Don't miss the fish throwing at the famous Pike Place Fish Market.

2. **Chihuly Garden and Glass**: Visit Dale Chihuly's incredible glass sculptures at the Chihuly Garden and Glass, which showcases stunning, colorful installations.

3. **Space Needle**: For panoramic views of Seattle, head up to the top of the Space Needle – the ultimate Seattle landmark. The observation deck provides views of the Cascade and Olympic Mountains, Elliott Bay, and the city skyline.

4. **Seattle Art Museum (SAM)**: The Seattle Art Museum is a leading museum with a diverse collection of art from various cultures. The SAM is a must-visit for art lovers, with regular exhibitions, educational programs, and captivating galleries.

5. **Woodland Park Zoo**: For a family-friendly outing, visit the Woodland Park Zoo. This award-winning zoo is known for its naturalistic animal exhibits and conservation efforts. Highlights include the Fur Ball Festival and Pumpkin Smash, depending on the season.

Additionally, it's crucial to note seasonal events and festivals, as Seattle hosts many including Bumbershoot, Northwest Folklife Festival, and Cherry Blossom Festival, which would add more to your experience depending on when you visit. Also, exploring the nearby Olympic National Park or venturing to the famous Fremont neighborhood could add more to your visit.
Explore the Parasail Documentation

For more details on batch jobs, classic completions, and other advanced workflows, please refer to the official Parasail Documentation.