For backend engineers and systems architects, the command-line utility cURL serves as the gold standard for network diagnostics and protocol verification. Before writing bespoke client wrapper classes, wiring application web frameworks, or orchestrating complex data pipelines, verifying connectivity directly from your terminal proves that routing, cryptographic authentication headers, and JSON serialization schemas function flawlessly.
In this practical, step-by-step tutorial, we will dispatch our inaugural request to Claude Sonnet 5.5—Anthropic's flagship hybrid reasoning system—using the TOP AI unified gateway. We will explore both Anthropic's native messaging format and the universal OpenAI-compatible schema.

Why Terminal Diagnostics Must Precede Application Code
When integrating third-party AI APIs into complex codebases, encountering errors—such as HTTP 401 unauthorized exceptions, malformed JSON errors, or network timeouts—often sparks ambiguous debugging sessions. It can be difficult to tell whether the failure stems from application code, serialization flaws, or upstream gateway instability. Testing with raw cURL isolates application layers and communicates directly with the network interface. If your cURL request returns a valid payload in your shell, your credentials, network ingress, and quota allocation are conclusively healthy.
Furthermore, executing cURL requests with verbose flags (such as -v or -i) exposes low-level transport details, including TLS handshake duration, response headers, and exact byte counts, allowing engineers to benchmark baseline latency before introducing application framework overhead.
Environment Setup Across Platforms
The cURL command utility is supported universally across modern computing operating environments:
- macOS & Linux: Native zsh and bash terminal shells include cURL pre-installed out of the box.
- Windows 10 / 11: Modern PowerShell environments support
curl.exe. Ensure you invokecurl.exerather than PowerShell's legacyInvoke-WebRequestalias to prevent parameter parsing conflicts.
Before executing, verify you have your tp-*** secret token copied from the TOP AI developer dashboard.
Protocol Approach 1: Native Anthropic Messages (/v1/messages)
If you are accustomed to the official Anthropic documentation or are migrating pipelines configured for native Anthropic tooling, TOP AI provides a direct native endpoint:
curl -X POST "https://topai.id/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: tp-live-xxxxxxxxxxxxxxxxxxxxxxxx" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Explain the architectural advantages of microservices in two concise sentences for junior developers."
}
]
}'Key technical parameters in this invocation include:
- Target endpoint:
https://topai.id/v1/messages. - Authentication header:
x-api-keypopulated with your secrettp-***token. - Protocol header:
anthropic-versionpinned to ensure deterministic API behavior. - Output bounds:
max_tokensis explicitly specified as required by the Anthropic engine.
Protocol Approach 2: OpenAI-Compatible Chat Completions (/v1/chat/completions)
One of TOP AI's most valuable architectural features is dynamic schema translation. The gateway natively accepts industry-standard OpenAI payloads and transparently translates them to Claude's upstream interface on the fly:
Live TOP AI API Pricing for Models Mentioned
Frequently Asked Questions
Can this cURL snippet run across Linux, macOS, and Windows PowerShell?+
Yes. Modern operating systems support curl natively in terminal shells. On Windows, ensure you are invoking curl.exe or running inside PowerShell 7+.
Does TOP AI support Anthropic's native /v1/messages API structure?+
Yes. TOP AI maintains full dual-stack compatibility, allowing you to hit either https://topai.id/v1/messages (native Anthropic) or https://topai.id/v1/chat/completions (OpenAI compatible).
What is the difference between x-api-key and Authorization: Bearer headers?+
Both authentication methods are validated by the gateway. If adhering to Anthropic guidelines, supply x-api-key. If using the OpenAI standard, provide Authorization: Bearer.
How can I verify real-time billing deductions from the cURL response?+
Every successful JSON envelope returned by TOP AI includes a dedicated 'topai' telemetry object detailing charged_gp (exact points billed) and balance_after (remaining balance).






