SDK Integration
Since LW AI API is fully OpenAI-compatible, you can use any OpenAI SDK with a simple base URL change. This guide covers the most popular languages.
Python (OpenAI SDK)
Installation
pip install openaiUsage
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": "user", "content": "Hello, LW AI!"}]
)
print(response.choices[0].message.content)Streaming
stream = client.chat.completions.create(
model="deepseek/deepseek-v4-pro",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Async
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://openapi.linkwo.ai/v1",
api_key="YOUR_API_KEY"
)
async def main():
response = await client.chat.completions.create(
model="deepseek/deepseek-v4-pro",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
asyncio.run(main())Node.js (OpenAI SDK)
Installation
npm install openaiUsage
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://openapi.linkwo.ai/v1',
apiKey: 'YOUR_API_KEY',
});
const response = await client.chat.completions.create({
model: 'deepseek/deepseek-v4-pro',
messages: [{ role: 'user', content: 'Hello, LW AI!' }],
});
console.log(response.choices[0].message.content);Streaming
const stream = await client.chat.completions.create({
model: 'deepseek/deepseek-v4-pro',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}Go
Use the official Go SDK or any OpenAI-compatible Go client:
go get github.com/sashabaranov/go-openaipackage main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://openapi.linkwo.ai/v1"
client := openai.NewClientWithConfig(config)
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: openai.GPT4oMini,
Messages: []openai.ChatCompletionMessage{
{Role: openai.ChatMessageRoleUser, Content: "Hello, LW AI!"},
},
},
)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(resp.Choices[0].Message.Content)
}Note: When using Go SDK, pass the model ID string (e.g.,
"deepseek/deepseek-v4-pro") instead of the SDK's built-in constants.
Java
Use the official OpenAI Java SDK:
<dependency>
<groupId>com.theokanning.openai-gpt3-java</groupId>
<artifactId>service</artifactId>
<version>0.18.2</version>
</dependency>OpenAiService service = new OpenAiService("YOUR_API_KEY");
// Override base URL via reflection or custom OkHttpClientAlternatively, make direct HTTP calls using any HTTP client (OkHttp, HttpClient, etc.) to https://openapi.linkwo.ai/v1/chat/completions.
Rust
cargo add async-openaiuse async_openai::{Client, config::OpenAIConfig};
use async_openai::types::{ChatCompletionRequestMessage, ChatCompletionRequestMessageArgs, CreateChatCompletionRequestArgs};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = OpenAIConfig::new()
.with_api_base("https://openapi.linkwo.ai/v1")
.with_api_key("YOUR_API_KEY");
let client = Client::with_config(config);
let request = CreateChatCompletionRequestArgs::default()
.model("deepseek/deepseek-v4-pro")
.messages(vec![
ChatCompletionRequestMessageArgs::default()
.role(async_openai::types::Role::User)
.content("Hello, LW AI!")
.build()?
])
.build()?;
let response = client.chat().create(request).await?;
println!("{}", response.choices[0].message.content);
Ok(())
}cURL
For quick testing, you can always use cURL directly:
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": "user", "content": "Hello!"}]
}'Quick Reference
| Language | Package | Base URL Config |
|---|---|---|
| Python | openai | base_url="https://openapi.linkwo.ai/v1" |
| Node.js | openai | baseURL: 'https://openapi.linkwo.ai/v1' |
| Go | go-openai | config.BaseURL = "https://openapi.linkwo.ai/v1" |
| Rust | async-openai | with_api_base("https://openapi.linkwo.ai/v1") |
| Java | HTTP client | Manual endpoint: https://openapi.linkwo.ai/v1 |
Next Steps
- Chat Completions — Full API reference
- Function Calling — Add tool capabilities
- Integrations — Tool-specific integration guides