> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alterhq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 開発向けAPIルーター

> SDKとカスタムコードからAlter API Routerを使う

独自アプリでAlterをOpenAI互換バックエンドとして利用します。

## Python（OpenAI SDK）

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://alterhq.com/api/v1"
)

response = client.chat.completions.create(
    model="OpenAI#gpt-5",
    messages=[{"role": "user", "content": "What is machine learning?"}]
)

print(response.choices[0].message.content)
```

## JavaScript（OpenAI SDK）

```javascript theme={null}
import OpenAI from 'openai'

const openai = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://alterhq.com/api/v1',
  dangerouslyAllowBrowser: true
})

const completion = await openai.chat.completions.create({
  model: 'OpenAI#gpt-5',
  messages: [{ role: 'user', content: 'Hello!' }]
})

console.log(completion.choices[0].message.content)
```

## LangChain（Python）

```python theme={null}
from langchain_openai import ChatOpenAI

chat = ChatOpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://alterhq.com/api/v1",
    model="OpenAI#gpt-5"
)

response = chat.invoke("What is AI?")
print(response.content)
```

## 直接カール

```bash theme={null}
curl https://alterhq.com/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "OpenAI#gpt-5",
    "messages": [{"role": "user", "content": "What is machine learning?"}]
  }'
```

## 対応パラメータ

* `model`（必須）
* `messages`（必須）
* `temperature`
* `max_tokens`
* `top_p`
* `frequency_penalty`
* `presence_penalty`

## 関連

* [APIゲートウェイ＆ルーターサービス](/ja/api-router/api-gateway)
* [API Router 運用とトラブルシューティング](/ja/api-router/operations)
* [APIモデル考察](/ja/references/api-model-names)
