> For the complete documentation index, see [/llms.txt](/llms.txt).

> Source: /docs/capabilities/generate/chat

# API Quickstart

For `/v1/responses`, see [Using the Responses API](#using-the-responses-api). The other examples on this page use Chat Completions.

Make your first Solar API call, understand the response, and learn how to continue a conversation.

## Before you begin

You need an Upstage account and API key. If you do not have them yet, follow [Getting Started](/docs/getting-started).

## Install an OpenAI SDK

Solar is compatible with the OpenAI API. Before using the Solar API, install the official [OpenAI SDK](https://developers.openai.com/api/docs/libraries) for your language.

### Python

```bash copy
pip install --upgrade openai
```

### JavaScript

```bash copy
npm install openai
```

## Make your first request

Start using the Solar API by sending a simple greeting.

**Request**

_Request/response examples: chat / request / quickstart_

## Understand the response

The generated answer is in `choices[0].message.content`. Solar Pro 4 keeps reasoning off by default; set `reasoning_effort` to also receive the reasoning trace in the response—see [Reasoning](/docs/capabilities/generate/reasoning).

_Example: chat / response-200 / quickstart / default_

| Field                                              | Description                                                           |
| -------------------------------------------------- | --------------------------------------------------------------------- |
| `choices[0].message.content`                       | The generated answer text.                                            |
| `choices[0].message.reasoning`                     | The reasoning trace the model produced before answering.              |
| `choices[0].finish_reason`                         | Why generation stopped. `stop` means the model finished on its own.   |
| `model`                                            | The exact model version that handled the request.                     |
| `usage.prompt_tokens`                              | Number of tokens in the request.                                      |
| `usage.completion_tokens`                          | Number of tokens in the generated answer, including reasoning tokens. |
| `usage.completion_tokens_details.reasoning_tokens` | Number of tokens spent on reasoning.                                  |
| `usage.total_tokens`                               | Sum of prompt and completion tokens.                                  |

For the complete response schema, see the [Chat Completions API reference](/api/chat#response).

## What models does Upstage provide?

The table below describes the models currently available as an API. Upstage provides stable _aliases_ that point to specific model versions. These aliases let you integrate once and automatically benefit from future updates without needing to modify your code whenever a model is improved or replaced.

We recommend using aliases instead of hardcoding specific model names, as models are frequently updated. However, please note that model behavior may change slightly when an alias is updated—for example, in how prompts are handled or how outputs are structured. While we strive to ensure smooth transitions, we recommend validating key prompts and responses when using aliases in production.

<table><thead><tr><th align="left" width="150px">Alias</th><th>Currently points to</th><th>RPM / TPM <a href="/docs/guides/rate-limits#solar-pro4">(Learn more)</a></th></tr></thead><tbody><tr><td>solar-pro4 (Solar Pro 4 - Flagship model specialized for agentic use. Strong at document-based work, coding, and business tasks. Supports 512K context length.)</td><td>[solar-pro4-260806](/docs/models/history#solar-pro4-260806)</td><td>100 / 250,000</td></tr><tr><td>solar-mini4 (Solar Mini 4 - Cost-efficient compact model for agentic use. 35B total parameters with 3B active. Supports 512K context length.)</td><td>[solar-mini4-260922](/docs/models/history#solar-mini4-260922)</td><td>100 / 250,000</td></tr><tr><td>syn-pro</td><td>[syn-pro-251021](/docs/models/history#syn-pro-251021)</td><td>100 / 50,000</td></tr></tbody></table>

## Continue the conversation

Chat Completions is stateless: it does not store your conversation history. Each request is handled on its own, so the model only knows what you send in `messages`.

To keep context across turns, resend the previous user and assistant messages together with the new user message.

Every resent message counts toward your input tokens, so a long conversation costs more with each turn. As the conversation approaches the model's context limit, trim or summarize older turns.

_Request/response examples: chat / request / multi-turn_

## Stream the response

Streaming lets your application display text as it is generated, instead of waiting for the complete response. Each chunk carries a piece of the answer, so the first words appear within a moment.

_Request/response examples: chat / request / streaming_

With the OpenAI SDK, each chunk exposes its text at `choices[0].delta.content`. When reasoning is on via `reasoning_effort`, the reasoning trace streams first in `choices[0].delta.reasoning`, before the answer chunks arrive. LangChain and LlamaIndex use their own chunk interfaces, as shown above. Raw SSE streams, including the cURL example, finish with `data: [DONE]`.

## Using the Responses API

The [Responses API](/api/responses) is available on Solar Pro 4 and Solar Mini 4.

This API stores nothing, so a conversation is continued by sending the whole history. Append the previous response's `output` items to your `input`, then add the new user message. `previous_response_id` and `conversation` are rejected with a `400`.

`reasoning` items may appear in `output`. Sending them back is safe — they are ignored, and reasoning is re-derived on each turn.

### Python

```python
from openai import OpenAI

client = OpenAI(
    api_key="UPSTAGE_API_KEY",
    base_url="https://api.upstage.ai/v1",
)

first = client.responses.create(
    model="solar-pro4",
    input="My name is Alex. Reply with ok.",
)

history = [{"role": "user", "content": "My name is Alex. Reply with ok."}]
history += [item.model_dump(exclude_none=True) for item in first.output]
history.append({"role": "user", "content": "What is my name?"})

second = client.responses.create(model="solar-pro4", input=history)
print(second.output_text)  # Alex
```

### cURL

```bash
curl --location 'https://api.upstage.ai/v1/responses' \
  --header 'Authorization: Bearer UPSTAGE_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "solar-pro4",
    "input": [
      { "role": "user", "content": "My name is Alex. Reply with ok." },
      {
        "type": "message",
        "role": "assistant",
        "content": [{ "type": "output_text", "text": "ok", "annotations": [] }]
      },
      { "role": "user", "content": "What is my name?" }
    ]
  }'
```

## Next steps

Now that your first request works, explore the capabilities you can build on top of it.

[Reasoning](/docs/capabilities/generate/reasoning) — Let the model think through multi-step problems before answering.

[Structured Outputs](/docs/capabilities/generate/structured-outputs) — Constrain responses to a JSON schema your application can parse.

[Tool Calling](/docs/capabilities/generate/tool-calling) — Let the model call your own tools and APIs.