feat: Cloudflare AI Gateway 적용

- OpenAI API 호출을 AI Gateway 경유로 변경
- 지역 제한 (403 unsupported_country_region_territory) 해결
- Gateway: telegram-bot (d8e5997eb4040f8b489f09095c0f623c)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-18 11:36:04 +09:00
parent cbadf99944
commit ec0dea0769

View File

@@ -1,6 +1,9 @@
import type { Env } from './types'; import type { Env } from './types';
import { callDepositAgent } from './deposit-agent'; import { callDepositAgent } from './deposit-agent';
// Cloudflare AI Gateway를 통해 OpenAI API 호출 (지역 제한 우회)
const OPENAI_API_URL = 'https://gateway.ai.cloudflare.com/v1/d8e5997eb4040f8b489f09095c0f623c/telegram-bot/openai/chat/completions';
interface OpenAIMessage { interface OpenAIMessage {
role: 'system' | 'user' | 'assistant' | 'tool'; role: 'system' | 'user' | 'assistant' | 'tool';
content: string | null; content: string | null;
@@ -250,7 +253,7 @@ async function suggestDomains(keywords: string, apiKey: string): Promise<string>
const excludeList = [...checkedDomains].slice(-30).join(', '); const excludeList = [...checkedDomains].slice(-30).join(', ');
// Step 1: GPT에게 도메인 아이디어 생성 요청 // Step 1: GPT에게 도메인 아이디어 생성 요청
const ideaResponse = await fetch('https://api.openai.com/v1/chat/completions', { const ideaResponse = await fetch(OPENAI_API_URL, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -836,7 +839,7 @@ async function executeTool(name: string, args: Record<string, string>, env?: Env
if (hasKorean && env?.OPENAI_API_KEY) { if (hasKorean && env?.OPENAI_API_KEY) {
try { try {
const translateRes = await fetch('https://api.openai.com/v1/chat/completions', { const translateRes = await fetch(OPENAI_API_URL, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -1090,7 +1093,7 @@ async function callOpenAI(
messages: OpenAIMessage[], messages: OpenAIMessage[],
selectedTools?: typeof tools // undefined = 도구 없음, 배열 = 해당 도구만 사용 selectedTools?: typeof tools // undefined = 도구 없음, 배열 = 해당 도구만 사용
): Promise<OpenAIResponse> { ): Promise<OpenAIResponse> {
const response = await fetch('https://api.openai.com/v1/chat/completions', { const response = await fetch(OPENAI_API_URL, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',