First Request
After setting up authentication, you're ready to make your first API request. This guide walks you through each part of a request and explains the response.
Basic Request
The most common endpoint is Chat Completions, which generates a response based on a list of messages:
curl https://openapi.linkwo.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7
}'Understanding the Response
A successful response returns JSON like this:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1719000000,
"model": "deepseek/deepseek-v4-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 8,
"total_tokens": 32
}
}Key Fields
| Field | Description |
|---|---|
id | Unique identifier for the completion |
choices | Array of completion choices (usually one) |
choices[].message | The assistant's reply |
choices[].finish_reason | Why the model stopped generating (stop, length, content_filter) |
usage | Token counts for billing and monitoring |
Message Roles
Each message has a role that tells the model how to interpret it:
| Role | Description |
|---|---|
system | Sets the assistant's behavior and personality |
user | The end-user's input or instruction |
assistant | The model's previous replies (for multi-turn conversations) |
Multi-Turn Conversation
Include previous messages to maintain context:
from openai import OpenAI
client = OpenAI(
base_url="https://openapi.linkwo.ai/v1",
api_key="YOUR_API_KEY"
)
response = client.chat.completions.create(
model="deepseek/deepseek-v4-pro",
messages=[
{"role": "system", "content": "You are a travel guide."},
{"role": "user", "content": "What's the best time to visit Japan?"},
{"role": "assistant", "content": "The best time to visit Japan is during spring (March-May) for cherry blossoms or autumn (October-November) for fall foliage."},
{"role": "user", "content": "What about budget-friendly options?"}
]
)
print(response.choices[0].message.content)Common Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
temperature | float | 1.0 | Controls randomness (0 = deterministic, 2 = very random) |
max_tokens | int | model max | Maximum tokens to generate in the response |
top_p | float | 1.0 | Nucleus sampling threshold |
stream | bool | false | Stream partial results as they're generated |
Error Handling
If something goes wrong, the API returns an error object:
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"code": "invalid_api_key"
}
}Common HTTP status codes:
| Status | Meaning |
|---|---|
| 400 | Bad request — check your parameters |
| 401 | Unauthorized — invalid or missing API key |
| 429 | Rate limit exceeded — slow down or upgrade |
| 500 | Server error — retry after a brief wait |
See Error Codes for the complete list.
Next Steps
- Streaming Response — Get real-time streaming output
- Chat Completions API — Full API reference
- SDK Integration — Use SDKs in your language