The Mainstream AI API Protocols in 2026: Companies, Formats & Working Examples
As AI becomes infrastructure, understanding the protocol differences between major vendors is critical for developers. This guide provides technically accurate, production-ready examples of how each API works — no speculation, just real formats.
Part 1: OpenAI (Chat Completions API)
Official Documentation: https://platform.openai.com/docs/api-reference
OpenAI maintains the most widely adopted API format, which has become a de facto standard emulated by many alternative models.
Core Endpoints
| Capability | Endpoint | Method |
|---|---|---|
| Text Chat | https://api.openai.com/v1/chat/completions |
POST |
| Image Generation | https://api.openai.com/v1/images/generations |
POST |
| Image Understanding (GPT-4o/GPT-4V) | https://api.openai.com/v1/chat/completions |
POST |
| Audio Transcription (Whisper) | https://api.openai.com/v1/audio/transcriptions |
POST |
| Text-to-Speech | https://api.openai.com/v1/audio/speech |
POST |
| Video Generation (Sora, if available) | Check current docs | — |
1. Text Chat Completions (Standard)
Request Example:
POST https://api.openai.com/v1/chat/completions
Authorization: Bearer sk-...your-key...
Content-Type: application/json
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Explain recursion in one sentence."
}
],
"temperature": 0.7,
"max_tokens": 500,
"stream": false
}
Response Example:
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1719310000,
"model": "gpt-4o-...",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Recursion is a programming technique where a function calls itself with a modified input until it reaches a base case that stops the recursion."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 32,
"completion_tokens": 45,
"total_tokens": 77
},
"system_fingerprint": "fp_..."
}
2. Multimodal (Image Input)
Request Example:
POST https://api.openai.com/v1/chat/completions
Authorization: Bearer sk-...your-key...
Content-Type: application/json
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What's in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg",
"detail": "high"
}
}
]
}
],
"max_tokens": 300
}
Or base64 inline:
POST https://api.openai.com/v1/chat/completions
Authorization: Bearer sk-...your-key...
Content-Type: application/json
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image."
},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
}
}
]
}
]
}
Response Structure: Same as text chat (see above).
3. Audio Transcription (Whisper)
Request Example (multipart/form-data):
POST https://api.openai.com/v1/audio/transcriptions
Authorization: Bearer sk-...your-key...
Content-Type: multipart/form-data; boundary=----boundary
------boundary
Content-Disposition: form-data; name="file"; filename="audio.mp3"
Content-Type: audio/mpeg
[...binary audio data...]
------boundary
Content-Disposition: form-data; name="model"
whisper-1
------boundary
Content-Disposition: form-data; name="response_format"
json
------boundary--
Response Example:
{
"text": "The quick brown fox jumps over the lazy dog."
}
Or verbose JSON:
{
"task": "transcribe",
"language": "english",
"duration": 2.5,
"text": "The quick brown fox jumps over the lazy dog.",
"segments": [
{
"id": 0,
"seek": 0,
"start": 0.0,
"end": 2.5,
"text": "The quick brown fox jumps over the lazy dog."
}
]
}
4. Text-to-Speech
Request Example:
POST https://api.openai.com/v1/audio/speech
Authorization: Bearer sk-...your-key...
Content-Type: application/json
{
"model": "tts-1",
"input": "The quick brown fox jumps over the lazy dog.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}
Response: Binary audio stream (MP3).
5. Image Generation (DALL-E)
Request Example:
POST https://api.openai.com/v1/images/generations
Authorization: Bearer sk-...your-key...
Content-Type: application/json
{
"model": "dall-e-3",
"prompt": "A cute robot cat sitting on a windowsill, sunset in background, cyberpunk style.",
"n": 1,
"size": "1024x1024",
"quality": "standard",
"response_format": "url"
}
Response Example:
{
"created": 1719310000,
"data": [
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/...",
"revised_prompt": "A cute robotic cat with metallic fur sitting elegantly on a windowsill..."
}
]
}
Part 2: Anthropic (Claude Messages API)
Official Documentation: https://docs.anthropic.com/claude/reference/messages_post
Anthropic uses a clean, thoughtfully designed API format focused on safety and long context.
Core Endpoints
| Capability | Endpoint | Method |
|---|---|---|
| Text & Multimodal Chat | https://api.anthropic.com/v1/messages |
POST |
1. Text Messages (Standard)
Request Example:
POST https://api.anthropic.com/v1/messages
x-api-key: sk-ant-...your-key...
anthropic-version: 2023-06-01
Content-Type: application/json
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Explain recursion in one sentence."
}
],
"system": "You are a helpful, precise assistant.",
"temperature": 0.7
}
Response Example:
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-3-5-sonnet-20241022",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself with progressively simpler inputs until it reaches a base case that can be solved directly."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 25,
"output_tokens": 48
}
}
2. Multimodal (Images)
Request Example:
POST https://api.anthropic.com/v1/messages
x-api-key: sk-ant-...your-key...
anthropic-version: 2023-06-01
Content-Type: application/json
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "/9j/4AAQSkZJRg..."
}
},
{
"type": "text",
"text": "What's in this image?"
}
]
}
]
}
Response Structure: Same as text messages (see above).
3. Multi-Turn Conversation
Request Example:
POST https://api.anthropic.com/v1/messages
x-api-key: sk-ant-...your-key...
anthropic-version: 2023-06-01
Content-Type: application/json
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
},
{
"role": "assistant",
"content": "The capital of France is Paris."
},
{
"role": "user",
"content": "And how far is it from London?"
}
]
}
Response Example:
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-3-5-sonnet-20241022",
"content": [
{
"type": "text",
"text": "Paris is approximately 344 kilometers (214 miles) from London by direct air travel."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 68,
"output_tokens": 32
}
}
Part 3: Google (Gemini API)
Official Documentation: https://ai.google.dev/api
Google's Gemini API supports unified multimodal interactions across text, image, audio, and video.
Core Endpoints
| Capability | Endpoint | Method |
|---|---|---|
| Text & Multimodal (Generate Content) | https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent |
POST |
| Streamed Generation | https://generativelanguage.googleapis.com/v1beta/models/{model}:streamGenerateContent |
POST |
Note: Replace {model} with gemini-2.0-flash-exp, gemini-1.5-pro, etc.
1. Text Only (Generate Content)
Request Example:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=YOUR_API_KEY
Content-Type: application/json
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Explain recursion in one sentence."
}
]
}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 500
}
}
Response Example:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "Recursion is a programming technique where a function calls itself with a modified, smaller problem until it reaches a base case that can be solved directly, unwinding the call stack to produce the final result."
}
],
"role": "model"
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 52,
"totalTokenCount": 64
}
}
2. Multimodal (Text + Image)
Request Example:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=YOUR_API_KEY
Content-Type: application/json
{
"contents": [
{
"role": "user",
"parts": [
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "/9j/4AAQSkZJRg..."
}
},
{
"text": "What's in this image?"
}
]
}
]
}
Response Structure: Same as text generation (see above).
3. Multimodal (Text + Audio)
Request Example:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=YOUR_API_KEY
Content-Type: application/json
{
"contents": [
{
"role": "user",
"parts": [
{
"inline_data": {
"mime_type": "audio/mp3",
"data": "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU2..."
}
},
{
"text": "Transcribe this audio."
}
]
}
]
}
Response Example:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "The quick brown fox jumps over the lazy dog."
}
],
"role": "model"
}
}
],
"usageMetadata": {
"promptTokenCount": 842,
"candidatesTokenCount": 18,
"totalTokenCount": 860
}
}
4. Multimodal (Text + Video)
Request Example:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=YOUR_API_KEY
Content-Type: application/json
{
"contents": [
{
"role": "user",
"parts": [
{
"inline_data": {
"mime_type": "video/mp4",
"data": "AAAAIGZ0eXBtcDQyAAAAAG1wNDJpc29tAAACAG1wNDJpc3..."
}
},
{
"text": "Summarize what happens in this video."
}
]
}
]
}
Response Example:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "The video shows a cat sitting on a windowsill, watching birds outside. After about 10 seconds, the cat stands up and moves away from the window."
}
],
"role": "model"
}
}
],
"usageMetadata": {
"promptTokenCount": 2846,
"candidatesTokenCount": 48,
"totalTokenCount": 2894
}
}
Part 4: Quick Comparison Cheat Sheet
| Aspect | OpenAI | Anthropic | Google Gemini |
|---|---|---|---|
| Authentication | Authorization: Bearer sk-... |
x-api-key: sk-ant-... + anthropic-version |
URL query ?key=... |
| Text Message Key | messages[].content |
messages[].content |
contents[].parts[].text |
| System Prompt | { role: "system", ... } |
Top-level "system" field |
systemInstruction field |
| Image Input | { type: "image_url", ... } |
{ type: "image", source: {...} } |
{ inline_data: { mime_type, data } } |
| Streaming Flag | stream: true |
(check docs) | Use :streamGenerateContent |
| Usage Field | usage: { prompt_tokens, completion_tokens } |
usage: { input_tokens, output_tokens } |
usageMetadata: { promptTokenCount, ... } |
Part 5: cURL Quick Reference (Production-Ready)
OpenAI (cURL)
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Anthropic (cURL)
curl https://api.anthropic.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'
Google Gemini (cURL)
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Hello!"}]}]
}'
Important Notes
This guide reflects current stable API patterns as of mid-2026. Always refer to the official documentation before deploying to production, as APIs evolve.
For checking how AI-visible your own site is, use our AI Visibility Checker tool.