Skip to main content

Overview

Even the best APIs return errors when something needs your attention—like a missing key or a typo in your request. Knowing how to interpret and handle these responses helps you build resilient, user-friendly applications. Why care? Proper error handling means less downtime, better user experience, and easier debugging.
Most errors are easy to fix once you know what they mean. This page shows you how.

Example Error Response

{
  "error": {
    "message": "Invalid or missing API key",
    "type": "error",
    "code": 401,
    "tip": "<tip>",
    "trace_id": "<trace_id>"
  }
}

Quick Start

How to catch and handle errors in your code:
  • Node.js
  • Python
  • cURL
import OpenAI from 'openai'

const openai = new OpenAI({
  apiKey: process.env.Routeway_API_KEY,
  baseURL: 'https://api.routeway.ai/v1',
})

try {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [{ role: 'user', content: 'Hello' }]
  })
  console.log(response)
} catch (error) {
  // Handle API error
  console.error('API Error:', error.response?.data || error.message)
}

Common Pitfalls

Missing API Key

Double-check your Routeway_API_KEY is set and included in every request.

Rate Limits

Too many requests? You may hit a 429 error. Add retry logic and check your usage.

Wrong Endpoint

A 404 error usually means a typo in your URL or using the wrong HTTP method.

Model Support

Some models don’t support function calling. Check model capabilities before using advanced features.

Deep Dive: Error Types & Solutions

How to Read an Error

Every error response includes:
  • message: Human-readable explanation
  • type: Error category
  • code: Numeric or string code

Error Code Reference

  • 401 Unauthorized
  • 403 Forbidden
  • 429 Too Many Requests
  • 400 Bad Request
  • 404 Not Found
  • 500 Internal Server Error
  • 422 Unprocessable Entity
{
  "error": {
    "message": "Invalid or missing API key",
    "type": "error",
    "code": 401
  }
}
What it means: Your API key is missing, invalid, or expired. How to fix:
  • Set the Routeway_API_KEY environment variable.
  • Include it in your request headers.
  • Generate a new key if needed.

Troubleshooting

1

Read the Error Message

The error message usually tells you exactly what’s wrong.
2

Check Your Request

Validate your API key, endpoint, and payload structure.
3

Consult the Reference

Look up the error code above for a solution.
4

Retry or Contact Support

If you’re stuck, contact support with your full request and error details.

Reference: All Error Codes

CodeMeaningTypical Fix
400Bad RequestCheck required fields, payload structure
401UnauthorizedSet or refresh your API key
403ForbiddenSlow down, contact support if blocked
404Not FoundCheck endpoint and resource existence
422Unprocessable EntityLast message must be from user
429Too Many RequestsReduce frequency, upgrade plan
500Internal Server ErrorRetry, contact support
I