Completions API
POST /v1/completions
Generate text completions using our intelligent routing engine. Automatically selects the best model based on latency, cost, and quality metrics.
Request Headers
| Header | Type | Description |
|---|---|---|
| Authorization | string | Bearer token for API authentication |
| Content-Type | string | application/json |
Request Body
| Parameter | Type | Description |
|---|---|---|
| model | string | Model ID or "auto" for intelligent routing |
| messages | array | Array of message objects with role and content |
| max_tokens | integer | Maximum tokens in response (default: 1000) |
| temperature | number | Sampling temperature 0-2 (default: 0.7) |
| top_p | number | Nucleus sampling parameter (default: 1) |
Example Request
curl -X POST https://api.inferenceiq.com/v1/completions \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"max_tokens": 500,
"temperature": 0.7
}'
Example Response
{
"id": "chatcmpl-7x8k9j",
"object": "text_completion",
"created": 1677649420,
"model": "gpt-4",
"choices": [
{
"text": "I'm doing well, thank you for asking!",
"finish_reason": "stop",
"index": 0
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 12,
"total_tokens": 22
}
}
Error Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid API key |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Server Error - Try again later |