Skip to content

Latest commit

 

History

History
108 lines (80 loc) · 4.19 KB

File metadata and controls

108 lines (80 loc) · 4.19 KB

ChatGPT API Relay Examples

OpenAI-compatible ChatGPT API relay examples for AI ROUTER.

AI ROUTER lets developers call ChatGPT-style models through an OpenAI-compatible endpoint, manage API keys, and check usage, quota, balance, and subscription status from the dashboard.

Website:

API endpoint:

https://api.ai-router.dev/v1

Examples

Runtime File
curl examples/curl/chat-completions.sh
Python examples/python/chat_completion.py
Node.js examples/nodejs/chat_completion.mjs

Quick start

Set your API key and choose a model available to that key:

export AI_ROUTER_API_KEY="replace_with_your_api_key"
export AI_ROUTER_MODEL="model_id_from_your_dashboard_or_models_response"

With an authenticated API key, you can list the model IDs available to it:

curl -sS https://api.ai-router.dev/v1/models \
  -H "Authorization: Bearer $AI_ROUTER_API_KEY"

Copy an id from the response into AI_ROUTER_MODEL. The available catalog can vary by API key, account configuration, and time; the dashboard is an equivalent source of the current model ID.

Call the OpenAI-compatible chat completions endpoint:

curl https://api.ai-router.dev/v1/chat/completions \
  -H "Authorization: Bearer $AI_ROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<JSON
  {
    "model": "$AI_ROUTER_MODEL",
    "messages": [
      { "role": "user", "content": "Write one sentence about OpenAI-compatible APIs." }
    ]
  }
JSON

Use the model name returned by /v1/models or shown in your AI ROUTER dashboard.

Documentation

Use-case pages

Integration pages

What this repository contains

This repository contains public examples and developer documentation only. It does not contain the AI ROUTER backend, routing logic, billing logic, account scheduling, or security implementation.

AI ROUTER is not an official OpenAI service. It provides an independent relay service with OpenAI-compatible request patterns. Availability, model names, plans, and pricing are shown in the product dashboard.

Keywords

ChatGPT API relay, OpenAI-compatible API, AI API relay, LLM API, API key management, usage tracking, daily ChatGPT API plan, weekly ChatGPT API plan, developer AI API.