API Documentation
Get started with MuxueAI API in minutes.
Quick Start
To use the MuxueAI API, you need an API key from your dashboard.
curl -X POST https://muxueai.top/v1/chat/completions \\n -H "Authorization: Bearer YOUR_API_KEY" \\n -H "Content-Type: application/json" \\n -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}'Authentication
All API requests require your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYEndpoints
POST /v1/chat/completions
Send a chat completion request. Fully OpenAI-compatible.
{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}], "temperature": 0.7, "max_tokens": 1000}GET /v1/models
List available models.
curl https://muxueai.top/v1/models -H "Authorization: Bearer YOUR_API_KEY"Code Examples
Python
import requests
headers = {"Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}
data = {"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}
resp = requests.post("https://muxueai.top/v1/chat/completions", headers=headers, json=data)
print(resp.json())JavaScript (Node.js)
const resp = await fetch('https://muxueai.top/v1/chat/completions', {
method: 'POST',
headers: {'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'gpt-4', messages: [{role: 'user', content: 'Hello!'}]})
});
const data = await resp.json();
console.log(data);Error Handling
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid API key |
| 402 | Insufficient tokens |
| 429 | Rate limit exceeded |
| 500 | Server error |