Metadata-Version: 2.4
Name: llm-api-adapter-qwen
Version: 0.1.0
Summary: Qwen Model Studio package for llm-api-adapter
Author: Sergey Inozemtsev
License: MIT License
        
        Copyright (c) 2025 Sergey Inozemtsev
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/Inozem/llm_api_adapter/
Keywords: llm,qwen,model-studio,adapter,api
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: llm-api-adapter<1.0.0,>=0.9.3
Provides-Extra: async
Requires-Dist: llm-api-adapter[async]<1.0.0,>=0.9.3; extra == "async"
Provides-Extra: httpx
Requires-Dist: llm-api-adapter[httpx]<1.0.0,>=0.9.3; extra == "httpx"
Dynamic: license-file

# llm-api-adapter-qwen

Official Model Studio Frankfurt/Global support for Qwen in
[llm-api-adapter](https://github.com/Inozem/llm_api_adapter/). The package uses
the Anthropic-compatible Messages API directly.

## Installation

Install through the Core package extra:

```bash
pip install "llm-api-adapter[qwen]"
```

Direct installation is also supported when Core is managed separately:

```bash
pip install llm-api-adapter-qwen
```

Async requests need HTTPX:

```bash
pip install "llm-api-adapter[qwen,async]"
```

Synchronous requests use `requests` by default. To opt into HTTPX for sync
`chat()` and `stream_chat()`, install `"llm-api-adapter[qwen,httpx]"` and pass
`transport="httpx"`.

## Quick start

```python
import os

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter

adapter = UniversalLLMAPIAdapter(
    organization="qwen",
    model="qwen3.8-max",
    api_key=os.environ["QWEN_API_KEY"],
)

response = adapter.chat(
    messages=[UserMessage("Explain retrieval-augmented generation.")],
    max_tokens=128,
    workspace_id=os.environ["QWEN_WORKSPACE_ID"],
)
print(response.content)
```

Qwen 0.1.0 supports only Model Studio's Frankfurt Global deployment. Pass the
required `workspace_id` explicitly to every `chat`, `stream_chat`, `achat`,
and `astream_chat` call; it is never read from an environment variable. The
package uses:

```text
https://{workspace_id}.eu-central-1.maas.aliyuncs.com/apps/anthropic/v1/messages
```

## Supported models and capabilities

The package deliberately exposes fixed model IDs, not moving aliases:
`qwen3.8-max`, `qwen3.8-flash`, `qwen3.7-plus`, and `qwen3.7-flash`.

| Capability | Supported models |
| --- | --- |
| Text chat, sync/async streaming, application function tools, JSON Schema/Pydantic output, and image URLs or bytes | All four models |
| `reasoning_level` | Qwen 3.8: categorical effort; Qwen 3.7: numeric thinking budget |

All four models default to hybrid thinking. Set `reasoning_level="none"` to
disable thinking, or `capture_reasoning=True` to receive provider-emitted
reasoning separately from visible text. `max_tokens` must be a positive integer
and limits generated output; it is separate from Qwen 3.7's thinking budget.
With thinking enabled, Model Studio's reported `usage.output_tokens` can also
include thinking tokens, so it can exceed `max_tokens` even when the visible
answer respects that output limit.

Cost fields use Frankfurt Global standard USD text rates. They exclude cached,
batch, promotional, and negotiated pricing.

Qwen permits `tool_choice="auto"` and `"none"` in thinking mode, but not a
forced `"any"` or named tool. For a forced tool call, the adapter automatically
disables thinking and issues a `UserWarning`; pass `reasoning_level="none"` to
make that choice explicit without a warning.

## PDF input

Qwen 0.1.0 supports images, but not PDFs. `DocumentPart` URLs and bytes are
rejected before any HTTP request:

```text
Qwen does not support DocumentPart; PDF and OCR are unavailable in Qwen 0.1.0.
```

The package does not make a partial PDF/OCR request or upload document bytes.

See the main [llm-api-adapter README](https://github.com/Inozem/llm_api_adapter/#readme)
for the shared API contract and examples.
