> For the complete documentation index, see [llms.txt](https://runyourai.gitbook.io/userguide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://runyourai.gitbook.io/userguide/runyour-agent/workspace/api/undefined.md).

# 모델 호출하기 (실제 호출 방법 예제)

발급한 키로 모델을 호출하는 방법을 안내합니다. **기존 OpenAI SDK 코드에서 API 키와 Base URL만 변경**하면 그대로 동작합니다.

#### Base URL과 인증

<table><thead><tr><th width="138.38671875">항목</th><th>값</th></tr></thead><tbody><tr><td>Base URL</td><td><code>https://api.runyour.ai/v1</code></td></tr><tr><td>인증</td><td>요청 헤더에 <code>Authorization: Bearer &#x3C;API_KEY></code></td></tr></tbody></table>

#### 주요 엔드포인트

<table><thead><tr><th width="100.6015625">메서드</th><th>경로</th><th>용도</th></tr></thead><tbody><tr><td>POST</td><td><code>/v1/chat/completions</code></td><td>AI 응답 생성 (주요 엔드포인트)</td></tr><tr><td>POST</td><td><code>/v1/responses</code></td><td>OpenAI Responses API 형식 호출</td></tr><tr><td>GET</td><td><code>/v1/models</code></td><td>사용 가능한 모델 목록 조회</td></tr></tbody></table>

#### 호출 예시

```python
# Python (openai 호환 SDK)
from openai import OpenAI

client = OpenAI(
    api_key="runyour-v1-YOUR_API_KEY",
    base_url="https://api.runyour.ai/v1",
)

completion = client.chat.completions.create(
    model="openai/gpt-5.2",
    messages=[{"role": "user", "content": "안녕하세요!"}],
    temperature=0.7,
    max_tokens=300,
)
print(completion.choices[0].message.content)
```

```bash
# cURL
curl https://api.runyour.ai/v1/chat/completions \
  -H "Authorization: Bearer runyour-v1-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-5.2", "messages": [{"role": "user", "content": "안녕하세요!"}]}'
```

#### 모델 지정 (모델 ID)

모델은 **`provider/model-name`** 형식으로 지정하며, 모델 ID만 바꾸면 다른 모델로 즉시 전환됩니다.

<table><thead><tr><th width="178.56640625">프로바이더</th><th>모델 ID 예시</th></tr></thead><tbody><tr><td>OpenAI</td><td><code>openai/gpt-5.5-pro</code>, <code>openai/gpt-5.4</code>, <code>openai/gpt-4o</code></td></tr><tr><td>Anthropic (Claude)</td><td><code>anthropic/claude-sonnet-4-6</code>, <code>anthropic/claude-opus-4-5</code>, <code>anthropic/claude-haiku-4-5</code></td></tr><tr><td>Google (Gemini)</td><td><code>gemini/gemini-2.5-pro</code>, <code>gemini/gemini-2.5-flash</code></td></tr><tr><td>Upstage</td><td><code>upstage/solar-pro3</code>, <code>upstage/solar-mini</code></td></tr><tr><td>Deepseek</td><td><code>deepseek/deepseek-v4-pro</code>, <code>deepseek/deepseek-chat</code></td></tr></tbody></table>

모델은 계속 업데이트되며, 최신 목록은 `GET https://api.runyour.ai/v1/models`로 직접 조회하거나 화면에서 확인하세요.

#### 스트리밍 응답

스트리밍을 사용하면 응답이 완성될 때까지 기다리지 않고, **생성되는 즉시 글자 단위로** 받아볼 수 있습니다. 요청에 `stream=True`(Python) 또는 `stream: true`(Node.js)를 추가합니다.

```python
stream = client.chat.completions.create(
    model="openai/gpt-5.2",
    messages=[{"role": "user", "content": "Runyour Agent를 소개해줘."}],
    stream=True,
)

for chunk in stream:
    token = chunk.choices[0].delta.content
    if token is not None:
        print(token, end="", flush=True)
```

응답은 Server-Sent Events(SSE) 형식으로 전송되며, 각 청크의 `choices[0].delta.content`에 텍스트가 담깁니다. `finish_reason`이 `stop`이면 완료되고, 마지막에 `[DONE]` 신호가 전송됩니다.

{% hint style="warning" %}
생성된 토큰은 **스트림 중단 여부와 관계없이** 비용이 청구됩니다. 처음에는 비스트리밍으로 테스트한 뒤 전환하는 것을 권장합니다.
{% endhint %}

#### 호출 이력·크레딧 확인

API 호출도 크레딧을 사용하므로 사용량을 주기적으로 확인하는 것이 좋습니다.

* API 라우터 화면에서 **키별 사용 기록(모델·토큰 수·차감 크레딧)**&#xC744; 상세하게 조회할 수 있습니다.
* 호출에 따른 토큰·크레딧 소모는 그룹 상세 > 사용 분석 > **호출 이력**에서도 확인할 수 있습니다. 이때 **작업/API** 토글로 출처를 구분합니다.

<div data-with-frame="true"><figure><img src="/files/r8bgHElbx2sdLe0wd6w2" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://runyourai.gitbook.io/userguide/runyour-agent/workspace/api/undefined.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
