[Service Name] API
# Title) in the document, Hugo will automatically use the title from front matter to generate the page title.đ Service Overview
Tip:
- Access URL (web link): Use Markdown link format
[URL](URL), it will automatically display an arrow icon (â) - API Endpoint: If it contains placeholders or requires dynamic replacement, use code format
`https://api.example.com/v1`; if it’s a fixed URL, you can use link format
Service Name: [API Service Name]
Provider: Provider Name
API Endpoint: https://api.example.com/v1 (if has placeholders) or https://api.example.com/v1 (if fixed URL)
Service Type: [Completely Free/Limited Free/Trial Credits]
Registration Requirements: [Whether registration/credit card/identity verification required]
â Service Description
[Service Name] API is [service form description, such as: developer API interface, RESTful API service, etc.] provided by [Provider Name].
Main Features
- [Feature 1]: [Detailed explanation]
- [Feature 2]: [Detailed explanation]
- [Feature 3]: [Detailed explanation]
- [Feature 4]: [Detailed explanation]
đ Available Models
Free/Trial Models List
| Model Name | Context Length | Output Length | Features | Use Cases |
|---|---|---|---|---|
| [model-1] | [Length] | [Length] | [Features] | [Cases] |
| [model-2] | [Length] | [Length] | [Features] | [Cases] |
| [model-3] | [Length] | [Length] | [Features] | [Cases] |
Model Detailed Description
[Model 1]
- Context Window: [Specific value]
- Main Purpose: [Explanation]
- Advantages: [Explanation]
[Model 2]
- Context Window: [Specific value]
- Main Purpose: [Explanation]
- Advantages: [Explanation]
đĸ Quotas and Limitations
Free Tier Limitations
| Limitation | Quota | Notes |
|---|---|---|
| Daily Requests | [Number] requests/day | [Notes] |
| Requests Per Minute | [Number] requests/min | [Notes] |
| Daily Tokens | [Number] tokens/day | [Notes] |
| Tokens Per Minute | [Number] tokens/min | [Notes] |
| Max Context Length | [Number] tokens | [Notes] |
| Max Output Length | [Number] tokens | [Notes] |
| Concurrent Requests | [Number] | [Notes] |
| Trial Credits | [Amount] | [Validity period] |
| Credit Card Required | â /â | [Notes] |
â ī¸ Important Limitations
- [Limitation 1]: [Detailed explanation]
- [Limitation 2]: [Detailed explanation]
- [Limitation 3]: [Detailed explanation]
Quota Reset Time
- Daily Quota: [Reset time, e.g., UTC 0:00]
- Per-minute Quota: [Reset rules]
- Trial Credits: [Validity period and expiration rules]
đ° Pricing Information
Free/Trial
- Free Quota: [Explanation]
- Trial Credits: [Amount and validity period]
- Acquisition Method: [Explanation]
Paid Pricing (if applicable)
| Model | Input Price | Output Price | Notes |
|---|---|---|---|
| [model-1] | $[Price]/M tokens | $[Price]/M tokens | [Notes] |
| [model-2] | $[Price]/M tokens | $[Price]/M tokens | [Notes] |
đ How to Use
Prerequisites
1. Register Account
If registration process is explained in Provider document, link to it:
- Please register an account first
If it’s API-specific registration process, explain in detail.
2. Get API Key
Detailed steps (if same for all users):
Step 1: Login to Developer Platform
- Visit Developer Platform
- Login with your account
Step 2: Create API Key
- [Detailed operation]
- [Detailed operation]
- Important: Copy and securely save your API key
Step 3: [Optional step, like topping up or binding credit card]
- [Detailed operation]
- [Detailed operation]
đģ Code Examples
Python Example
Install Dependencies:
pip install openai # or other SDKBasic Usage:
from openai import OpenAI
# Initialize client (please replace with your API key)
client = OpenAI(
base_url="https://api.example.com/v1",
api_key="YOUR_API_KEY"
)
# Send request
response = client.chat.completions.create(
model="model-name",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, please introduce yourself."}
],
max_tokens=1000,
temperature=0.7
)
# Print response
print(response.choices[0].message.content)
# View Token usage
print(f"\nTokens used: {response.usage.total_tokens}")Streaming Output Example:
# Streaming output (suitable for real-time display)
stream = client.chat.completions.create(
model="model-name",
messages=[
{"role": "user", "content": "Write a poem about AI"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")cURL Example
Basic Request:
curl https://api.example.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "model-name",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
],
"max_tokens": 1000,
"temperature": 0.7
}'Streaming Output:
curl https://api.example.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "model-name",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}'Node.js Example (Optional)
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.example.com/v1',
apiKey: 'YOUR_API_KEY',
});
async function main() {
const completion = await client.chat.completions.create({
model: 'model-name',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello, please introduce yourself.' }
],
max_tokens: 1000,
temperature: 0.7,
});
console.log(completion.choices[0].message.content);
console.log(`\nTokens used: ${completion.usage.total_tokens}`);
}
main();đ Core Advantages
Technical Advantages
-
[Advantage 1]:
- [Detailed explanation]
- [Data support]
-
[Advantage 2]:
- [Detailed explanation]
- [Data support]
-
[Advantage 3]:
- [Detailed explanation]
- [Data support]
Comparison with Other APIs
| Feature | [This Service] | [Competitor 1] | [Competitor 2] |
|---|---|---|---|
| Free Quota | [Data] | [Data] | [Data] |
| Request Speed | [Data] | [Data] | [Data] |
| Number of Models | [Number] | [Number] | [Number] |
| Context Length | [Length] | [Length] | [Length] |
| Price | [Price] | [Price] | [Price] |
| Credit Card Required | â /â | â /â | â /â |
đĄ Practical Suggestions
â Recommended Practices
-
[Suggestion 1]:
- [Detailed explanation]
- [Code example]
-
[Suggestion 2]:
- [Detailed explanation]
- [Code example]
-
[Suggestion 3]:
- [Detailed explanation]
đ¯ Best Practices
Make Full Use of Free Quota:
- [Suggestion 1]
- [Suggestion 2]
- [Suggestion 3]
Optimize Token Usage:
- [Suggestion 1]
- [Suggestion 2]
- [Suggestion 3]
Error Handling:
import time
from openai import OpenAI, RateLimitError, APIError
client = OpenAI(
base_url="https://api.example.com/v1",
api_key="YOUR_API_KEY"
)
def call_api_with_retry(messages, max_retries=3):
"""API call with retry mechanism"""
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="model-name",
messages=messages
)
return response
except RateLimitError:
print(f"Rate limit reached, waiting and retrying... ({attempt + 1}/{max_retries})")
time.sleep(2 ** attempt) # Exponential backoff
except APIError as e:
print(f"API error: {e}")
if attempt == max_retries - 1:
raise
return Noneâ ī¸ Precautions
- [Precaution 1]: [Explanation]
- [Precaution 2]: [Explanation]
- [Precaution 3]: [Explanation]
đ¯ Practical Application Cases
Case 1: [Application Scenario Name]
Scenario Description: [Description]
# Complete code example
def example_case_1():
"""[Function description]"""
client = OpenAI(
base_url="https://api.example.com/v1",
api_key="YOUR_API_KEY"
)
# Implementation code
response = client.chat.completions.create(
model="model-name",
messages=[
{"role": "user", "content": "Example question"}
]
)
return response.choices[0].message.content
# Usage example
result = example_case_1()
print(result)Case 2: [Application Scenario Name]
Scenario Description: [Description]
# Code exampleđ§ Common Questions
Q: [Question 1]
A: [Answer]
Q: [Question 2]
A: [Answer]
Q: [Question 3]
A: [Answer]
Q: [Question 4]
A: [Answer]
Q: [Question 5]
A: [Answer]
đ Related Resources
- API Endpoint:
https://api.example.com/v1 - Developer Platform: https://platform.example.com
- API Documentation: https://docs.example.com
- Provider Homepage: Link to Provider document
- Corresponding Chatbot Service: Link to Chatbot document (if available)
- SDK Repository: [GitHub link]
- Example Code: [GitHub link]
- API Status: [Status page link]
đ Changelog
- [Year-Month]: [API updates, new models, quota changes]
- [Year-Month]: [API updates, new models, quota changes]
- [Year-Month]: [API updates, new models, quota changes]
Service Provider: [Provider Name]