Skip to main content
Make your first API call to Heroku AI and build a simple web search assistant using Claude models.

Prerequisites

Call the API

1

Set your API key

Get your API key from the Heroku Dashboard after provisioning a model and set it as an environment variable:
export INFERENCE_KEY='your-api-key-here'
2

Make your first API call

Run this command to create a simple web search assistant:
curl https://us.inference.heroku.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $INFERENCE_KEY" \
  -d '{
    "model": "claude-4-5-sonnet",
    "max_tokens": 1000,
    "messages": [
      {
        "role": "user",
        "content": "What should I search for to find the latest developments in renewable energy?"
      }
    ]
  }'
Example output:
{
  "id": "msg_01HCDu5LRGeP2o7s2xGmxyx8",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Here are some effective search strategies to find the latest renewable energy developments:\n\n## Search Terms to Use:\n- \"renewable energy news 2024\"\n- \"clean energy breakthrough\"\n- \"solar/wind/battery technology advances\"\n- \"green energy innovations\"\n- \"climate tech developments\"\n- \"energy storage solutions\"\n\n## Best Sources to Check:\n\n**News & Industry Sites:**\n- Renewable Energy World\n- GreenTech Media (now Wood Mackenzie)\n- Energy Storage News\n- CleanTechnica\n- PV Magazine (for solar)\n- WindPower Engineering & Development..."
    }
  ],
  "model": "claude-4-5-sonnet",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 21,
    "output_tokens": 305
  }
}

Next steps

Now that you have made your first Heroku AI API request, it’s time to explore what else is possible:

Chat Completions

OpenAI-compatible API for all models.

Messages API

Native Anthropic SDK for Claude models.

Choose a Model

Find the right model for your use case and budget.

AI Studio

Test models interactively before integrating.

Provisioning your first model

If you haven’t provisioned a model yet, use the Heroku CLI:
# Login to Heroku
heroku login

# Create a new app (or use an existing one)
heroku create my-ai-app

# Provision a Claude model
heroku ai:models:create claude-4-5-sonnet --app my-ai-app

# Get your API key
heroku config:get INFERENCE_KEY --app my-ai-app
For more details on provisioning and managing models, see the CLI Commands documentation.