連携サンプル
Ready-to-copy integration examples: curl, the OpenAI SDK, the Anthropic SDK, streaming, and setup for tools such as Cursor and Cline.
The quickest way to test: call the OpenAI-compatible chat completions endpoint directly with curl.
curl https://aaa.ashp.tw/v1/chat/completions \
-H "Authorization: Bearer $AAA_TOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [{"role": "user", "content": "Hello!"}]
}'
With the official OpenAI Python SDK, just change base_url and api_key and your existing code keeps working.
from openai import OpenAI
client = OpenAI(
api_key="$AAA_TOKEN_API_KEY",
base_url="https://aaa.ashp.tw/v1",
)
resp = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
With the official Anthropic SDK, point base_url at the AAA TOKEN Anthropic-compatible endpoint to use the Claude Messages API.
from anthropic import Anthropic
client = Anthropic(
api_key="$AAA_TOKEN_API_KEY",
base_url="https://aaa.ashp.tw/v1/anthropic",
)
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(msg.content[0].text)
Use the official OpenAI SDK in Node.js by setting just the baseURL and your API key.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AAA_TOKEN_API_KEY,
baseURL: "https://aaa.ashp.tw/v1",
});
const resp = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(resp.choices[0].message.content);
Set stream=True to receive output incrementally. The Python example below reuses the client created above.
stream = client.chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
Cursor, Cline and other dev tools
Cursor: in Settings → Models, enter your API key, enable Override OpenAI Base URL and paste the base URL below, then add the model names you want to use.
Cline (VS Code extension): choose OpenAI Compatible as the API provider, then enter the base URL below, your API key and a model name.
https://aaa.ashp.tw/v1
$AAA_TOKEN_API_KEY をご自身の API キー(sk- で始まる)に置き換えてください。Authorization ヘッダーで送信されます。