API Reference

AI Gateway supports both OpenAI and Anthropic API formats. Use whichever fits your existing codebase.

OpenAI-Compatible Endpoint

POSThttps://ai.hopeagrico.com/v1/chat/completions

Drop-in replacement for the OpenAI Chat Completions API. Compatible with all OpenAI SDKs and tools including Cursor, ChatBox, and ChatGPT SDK.

Supported Parameters

ParameterTypeRequiredDescription
modelstringRequiredModel ID (e.g., gpt-5.4-mini, auto)
messagesarrayRequiredArray of message objects with role and content
temperaturefloatOptionalSampling temperature (0-2). Default: 1
max_tokensintegerOptionalMaximum tokens to generate
top_pfloatOptionalNucleus sampling parameter. Default: 1
streambooleanOptionalEnable streaming responses. Default: false
stopstring|arrayOptionalStop sequences
frequency_penaltyfloatOptionalPenalty for new tokens (-2 to 2). Default: 0
presence_penaltyfloatOptionalPenalty for presence (-2 to 2). Default: 0
toolsarrayOptionalTool definitions for function calling
tool_choicestring|objectOptionalTool selection strategy

Request Example

curl -X POST https://ai.hopeagrico.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-5.4-mini",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'

Response Example

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "gpt-5.4-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 12,
    "total_tokens": 37
  }
}

Anthropic-Compatible Endpoint

POSThttps://ai.hopeagrico.com/v1/messages

Native Anthropic Messages API format. Used by Claude Code, Cline, and all Anthropic SDK apps. Supports streaming, tool use, vision, and extended thinking.

Supported Parameters

ParameterTypeRequiredDescription
modelstringRequiredModel ID (e.g., claude-sonnet-4.5, auto)
messagesarrayRequiredArray of message objects
max_tokensintegerRequiredMaximum tokens to generate
systemstringOptionalSystem prompt
temperaturefloatOptionalSampling temperature (0-1). Default: 1
top_pfloatOptionalNucleus sampling. Default: 1
streambooleanOptionalEnable streaming. Default: false
stop_sequencesarrayOptionalStop sequences
toolsarrayOptionalTool definitions
thinkingobjectOptionalExtended thinking configuration

Request Example

curl -X POST https://ai.hopeagrico.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4.5",
    "max_tokens": 1024,
    "system": "You are a helpful assistant.",
    "messages": [
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'

Response Example

{
  "id": "msg_abc123",
  "type": "message",
  "model": "claude-sonnet-4.5",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "The capital of France is Paris."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 25,
    "output_tokens": 12
  }
}

Error Codes

CodeDescription
400Bad Request — Invalid parameters or malformed request body
401Unauthorized — Invalid or missing API key
403Forbidden — API key lacks required permissions or model access
429Rate Limited — Too many requests. Retry after the Retry-After header
500Internal Server Error — Unexpected error on our end
502Bad Gateway — Upstream provider returned an error
503Service Unavailable — Temporary overload or maintenance

Rate Limiting

Rate limits are applied per account based on your subscription tier. Limits are measured as requests per hour.

TierRate Limit
Free10 requests/hour
Lite30 requests/hour
Pro60 requests/hour
Enterprise300 requests/hour

When rate limited, the API returns a 429 status code with a Retry-After header indicating when you can retry.