# π€ requests-ai-validator
**AI-powered REST API testing framework - drop-in replacement for requests with intelligent validation**
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
## π― What is it?
`requests-ai-validator` is a drop-in replacement for the popular `requests` library that adds **AI-powered validation** capabilities to your REST API tests. It uses Large Language Models (LLMs) to intelligently validate API responses, request-response consistency, and business logic.
## β¨ Key Features
- π **Drop-in replacement** for `requests` - change only the import statement
- π€ **AI-powered validation** - intelligent analysis of API interactions
- π **Multiple AI providers** - OpenAI, Anthropic, Ollama support
- π― **Schema validation** - Pydantic models, JSON Schema, OpenAPI support
- π **English feedback** - clear and professional AI responses
- π **Business rules** - custom validation rules
- π **Allure integration** - detailed reporting
- βοΈ **Environment configuration** - easy setup via .env
## π Quick Start
### Installation
```bash
pip install requests-ai-validator
```
### Basic Usage
```python
# Replace this line:
import requests
# With this line:
import requests_ai_validator as requests
# Use exactly like regular requests + AI validation:
from pydantic import BaseModel
class UserModel(BaseModel):
id: int
name: str
email: str
# Regular request
response = requests.get("https://api.example.com/users/1")
# With AI validation - just add parameters!
response = requests.get(
"https://api.example.com/users/1",
ai_validation=True,
ai_schema=UserModel,
ai_rules=["User must exist and be valid"]
)
# If AI finds issues β test fails with detailed feedback
```
## βοΈ Configuration
### Environment Variables (.env)
```bash
# AI Configuration
AI_TOKEN=your-api-key-here
AI_PROVIDER=openai
AI_MODEL=gpt-3.5-turbo
```
### Supported Providers
| Provider | Models | API Key |
|----------|--------|---------|
| **OpenAI** | gpt-3.5-turbo, gpt-4, gpt-4-turbo, gpt-4o | `AI_TOKEN` |
| **Anthropic** | claude-3-haiku, claude-3-sonnet, claude-3-opus | `AI_TOKEN` |
| **Ollama** | llama2, codellama, mistral | No API key (local) |
### Language
All AI feedback is provided in **English** for universal compatibility and clarity.
## π Usage Examples
### 1. Simple GET Request
```python
import requests_ai_validator as requests
from pydantic import BaseModel
class UserModel(BaseModel):
id: int
name: str
email: str
# AI validation built into the request
response = requests.get(
"https://api.example.com/users/1",
ai_validation=True,
ai_schema=UserModel
)
```
### 2. POST Request with Business Rules
```python
response = requests.post(
"https://api.example.com/users",
json={"name": "John", "email": "john@example.com"},
ai_validation=True,
ai_schema=UserModel,
ai_rules=[
"User should be successfully created",
"ID should be a positive number"
]
)
```
### 3. Session Usage
```python
session = requests.Session(ai_provider="openai")
response = session.get(
url,
ai_validation=True,
ai_schema=Model
)
```
### 4. Manual Configuration
```python
# Override environment settings
requests.configure_global_ai(
ai_provider="anthropic",
api_key="your-claude-key",
model="claude-3-sonnet"
)
```
## π― AI Validation Categories
The AI validates 5 key areas:
| Category | Description | Example |
|----------|-------------|---------|
| **http_compliance** | HTTP protocol validation | "Status code 200 correct for GET request" |
| **request_validation** | Request payload validation | "Request contains valid data: name, email" |
| **response_structure** | Response format validation | "Response has valid JSON structure" |
| **schema_compliance** | Schema adherence | "All required fields present in response" |
| **data_consistency** | Request-response consistency | "Common fields match: name, email" |
## β Error Handling
When AI validation fails, you get detailed feedback:
```python
AssertionError: β AI validation failed: Schema validation issues found.
{'schema_compliance': "Missing required field 'missing_field' in response", 'data_consistency': 'Request field name does not match response'}
```
## π§ Advanced Usage
### Positive vs Negative Tests
```python
# Positive test - expect AI to find no issues
response = requests.get(url, ai_validation=True, expected_result=True)
# Negative test - expect AI to find issues
response = requests.get(url, ai_validation=True, expected_result=False)
```
### Custom AI Instructions
```python
response = requests.post(
url,
json=data,
ai_validation=True,
ai_schema=Model,
ai_rules=["Business rule 1", "Business rule 2"],
ai_instructions=["Focus on data consistency", "Ignore performance"]
)
```
### Manual AI Validation
```python
# Get response first
response = requests.get(url)
# Then validate manually
validation_result = response.validate_with_ai(
schema=Model,
rules=["Custom rules"],
expected_success=True
)
# Print detailed feedback (optional)
response.print_validation_details()
```
## π Integration with Existing Code
### Minimal Changes Required
```python
# Before:
import requests
response = requests.get(url)
assert response.status_code == 200
return Model(**response.json())
# After:
import requests_ai_validator as requests # Only this line changed
response = requests.get(url, ai_validation=True, ai_schema=Model) # Added AI validation
assert response.status_code == 200
return Model(**response.json())
```
### Framework Integration
Works seamlessly with popular testing frameworks:
- β
**pytest** - automatic test failure on AI issues
- β
**Allure** - detailed AI feedback in reports
- β
**unittest** - standard assertions work
- β
**Custom frameworks** - minimal integration effort
## π How It Works
1. **Make request** - uses standard `requests` library
2. **AI analysis** - sends request/response to LLM for validation
3. **Intelligent feedback** - gets structured analysis of API interaction
4. **Test control** - fails test if AI finds issues (configurable)
## π― Benefits
- π§ **Intelligent validation** - catches issues traditional testing misses
- π **Easy adoption** - minimal code changes required
- π **Deep analysis** - validates business logic, not just structure
- π **Rich feedback** - detailed explanations of issues found
- β‘ **Fast integration** - works with existing test suites
- π **Multi-language** - supports different feedback languages
## π Requirements
- Python 3.8+
- `requests` library
- `pydantic` for schema validation
- AI provider API key (OpenAI, Anthropic) or local Ollama
## π Links
- **GitHub**: [Source code](https://github.com/manikosto/requests-ai-validator)
- **PyPI**: [Package](https://pypi.org/project/requests-ai-validator/)
- **Issues**: [Report bugs](https://github.com/manikosto/requests-ai-validator/issues)
- **Examples**: See `project/` directory for integration examples
## π License
MIT License - see [LICENSE](LICENSE) file for details.
## π¨ Created with
This framework was created with **ΠΠ°ΠΉΠ± ΠΊΠΎΠ΄ΠΈΠ½Π³** - AI-powered development approach that combines human creativity with AI assistance to build elegant and powerful solutions.
---
**Transform your API testing with AI intelligence! π**
Raw data
{
"_id": null,
"home_page": "https://github.com/manikosto/requests-ai-validator",
"name": "requests-ai-validator",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "requests, api, testing, validation, ai, http, automation",
"author": "Aleksei Koledachkin",
"author_email": "Aleksei Koledachkin <akoledachkin@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/81/10/42680aaa2c8c2a98ae4dcf81b8f69d87d85ecfe5d5627a3e0f8a9f5ccda8/requests_ai_validator-1.0.4.tar.gz",
"platform": null,
"description": "# \ud83e\udd16 requests-ai-validator\n\n**AI-powered REST API testing framework - drop-in replacement for requests with intelligent validation**\n\n[](https://www.python.org/downloads/)\n[](https://opensource.org/licenses/MIT)\n\n## \ud83c\udfaf What is it?\n\n`requests-ai-validator` is a drop-in replacement for the popular `requests` library that adds **AI-powered validation** capabilities to your REST API tests. It uses Large Language Models (LLMs) to intelligently validate API responses, request-response consistency, and business logic.\n\n## \u2728 Key Features\n\n- \ud83d\udd04 **Drop-in replacement** for `requests` - change only the import statement\n- \ud83e\udd16 **AI-powered validation** - intelligent analysis of API interactions\n- \ud83d\udcca **Multiple AI providers** - OpenAI, Anthropic, Ollama support\n- \ud83c\udfaf **Schema validation** - Pydantic models, JSON Schema, OpenAPI support\n- \ud83c\udf0d **English feedback** - clear and professional AI responses\n- \ud83d\udccb **Business rules** - custom validation rules\n- \ud83d\udcca **Allure integration** - detailed reporting\n- \u2699\ufe0f **Environment configuration** - easy setup via .env\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\npip install requests-ai-validator\n```\n\n### Basic Usage\n\n```python\n# Replace this line:\nimport requests\n\n# With this line:\nimport requests_ai_validator as requests\n\n# Use exactly like regular requests + AI validation:\nfrom pydantic import BaseModel\n\nclass UserModel(BaseModel):\n id: int\n name: str\n email: str\n\n# Regular request\nresponse = requests.get(\"https://api.example.com/users/1\")\n\n# With AI validation - just add parameters!\nresponse = requests.get(\n \"https://api.example.com/users/1\",\n ai_validation=True,\n ai_schema=UserModel,\n ai_rules=[\"User must exist and be valid\"]\n)\n# If AI finds issues \u2192 test fails with detailed feedback\n```\n\n## \u2699\ufe0f Configuration\n\n### Environment Variables (.env)\n\n```bash\n# AI Configuration\nAI_TOKEN=your-api-key-here\nAI_PROVIDER=openai\nAI_MODEL=gpt-3.5-turbo\n```\n\n### Supported Providers\n\n| Provider | Models | API Key |\n|----------|--------|---------|\n| **OpenAI** | gpt-3.5-turbo, gpt-4, gpt-4-turbo, gpt-4o | `AI_TOKEN` |\n| **Anthropic** | claude-3-haiku, claude-3-sonnet, claude-3-opus | `AI_TOKEN` |\n| **Ollama** | llama2, codellama, mistral | No API key (local) |\n\n### Language\n\nAll AI feedback is provided in **English** for universal compatibility and clarity.\n\n## \ud83d\udcd6 Usage Examples\n\n### 1. Simple GET Request\n\n```python\nimport requests_ai_validator as requests\nfrom pydantic import BaseModel\n\nclass UserModel(BaseModel):\n id: int\n name: str\n email: str\n\n# AI validation built into the request\nresponse = requests.get(\n \"https://api.example.com/users/1\",\n ai_validation=True,\n ai_schema=UserModel\n)\n```\n\n### 2. POST Request with Business Rules\n\n```python\nresponse = requests.post(\n \"https://api.example.com/users\",\n json={\"name\": \"John\", \"email\": \"john@example.com\"},\n ai_validation=True,\n ai_schema=UserModel,\n ai_rules=[\n \"User should be successfully created\",\n \"ID should be a positive number\"\n ]\n)\n```\n\n### 3. Session Usage\n\n```python\nsession = requests.Session(ai_provider=\"openai\")\n\nresponse = session.get(\n url,\n ai_validation=True,\n ai_schema=Model\n)\n```\n\n### 4. Manual Configuration\n\n```python\n# Override environment settings\nrequests.configure_global_ai(\n ai_provider=\"anthropic\",\n api_key=\"your-claude-key\",\n model=\"claude-3-sonnet\"\n)\n```\n\n## \ud83c\udfaf AI Validation Categories\n\nThe AI validates 5 key areas:\n\n| Category | Description | Example |\n|----------|-------------|---------|\n| **http_compliance** | HTTP protocol validation | \"Status code 200 correct for GET request\" |\n| **request_validation** | Request payload validation | \"Request contains valid data: name, email\" |\n| **response_structure** | Response format validation | \"Response has valid JSON structure\" |\n| **schema_compliance** | Schema adherence | \"All required fields present in response\" |\n| **data_consistency** | Request-response consistency | \"Common fields match: name, email\" |\n\n## \u274c Error Handling\n\nWhen AI validation fails, you get detailed feedback:\n\n```python\nAssertionError: \u274c AI validation failed: Schema validation issues found.\n{'schema_compliance': \"Missing required field 'missing_field' in response\", 'data_consistency': 'Request field name does not match response'}\n```\n\n## \ud83d\udd27 Advanced Usage\n\n### Positive vs Negative Tests\n\n```python\n# Positive test - expect AI to find no issues\nresponse = requests.get(url, ai_validation=True, expected_result=True)\n\n# Negative test - expect AI to find issues \nresponse = requests.get(url, ai_validation=True, expected_result=False)\n```\n\n### Custom AI Instructions\n\n```python\nresponse = requests.post(\n url,\n json=data,\n ai_validation=True,\n ai_schema=Model,\n ai_rules=[\"Business rule 1\", \"Business rule 2\"],\n ai_instructions=[\"Focus on data consistency\", \"Ignore performance\"]\n)\n```\n\n### Manual AI Validation\n\n```python\n# Get response first\nresponse = requests.get(url)\n\n# Then validate manually\nvalidation_result = response.validate_with_ai(\n schema=Model,\n rules=[\"Custom rules\"],\n expected_success=True\n)\n\n# Print detailed feedback (optional)\nresponse.print_validation_details()\n```\n\n## \ud83d\udcca Integration with Existing Code\n\n### Minimal Changes Required\n\n```python\n# Before:\nimport requests\nresponse = requests.get(url)\nassert response.status_code == 200\nreturn Model(**response.json())\n\n# After:\nimport requests_ai_validator as requests # Only this line changed\nresponse = requests.get(url, ai_validation=True, ai_schema=Model) # Added AI validation\nassert response.status_code == 200\nreturn Model(**response.json())\n```\n\n### Framework Integration\n\nWorks seamlessly with popular testing frameworks:\n\n- \u2705 **pytest** - automatic test failure on AI issues\n- \u2705 **Allure** - detailed AI feedback in reports\n- \u2705 **unittest** - standard assertions work\n- \u2705 **Custom frameworks** - minimal integration effort\n\n## \ud83d\udd0d How It Works\n\n1. **Make request** - uses standard `requests` library\n2. **AI analysis** - sends request/response to LLM for validation\n3. **Intelligent feedback** - gets structured analysis of API interaction\n4. **Test control** - fails test if AI finds issues (configurable)\n\n## \ud83c\udfaf Benefits\n\n- \ud83e\udde0 **Intelligent validation** - catches issues traditional testing misses\n- \ud83d\ude80 **Easy adoption** - minimal code changes required\n- \ud83d\udd0d **Deep analysis** - validates business logic, not just structure\n- \ud83d\udcca **Rich feedback** - detailed explanations of issues found\n- \u26a1 **Fast integration** - works with existing test suites\n- \ud83c\udf0d **Multi-language** - supports different feedback languages\n\n## \ud83d\udccb Requirements\n\n- Python 3.8+\n- `requests` library\n- `pydantic` for schema validation\n- AI provider API key (OpenAI, Anthropic) or local Ollama\n\n## \ud83d\udd17 Links\n\n- **GitHub**: [Source code](https://github.com/manikosto/requests-ai-validator)\n- **PyPI**: [Package](https://pypi.org/project/requests-ai-validator/)\n- **Issues**: [Report bugs](https://github.com/manikosto/requests-ai-validator/issues)\n- **Examples**: See `project/` directory for integration examples\n\n## \ud83d\udcc4 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## \ud83c\udfa8 Created with\n\nThis framework was created with **\u0412\u0430\u0439\u0431 \u043a\u043e\u0434\u0438\u043d\u0433** - AI-powered development approach that combines human creativity with AI assistance to build elegant and powerful solutions.\n\n---\n\n**Transform your API testing with AI intelligence! \ud83d\ude80**\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "AI-powered validation wrapper for Python requests library",
"version": "1.0.4",
"project_urls": {
"Bug Reports": "https://github.com/yourusername/requests-ai-validator/issues",
"Homepage": "https://github.com/yourusername/requests-ai-validator",
"Source": "https://github.com/yourusername/requests-ai-validator"
},
"split_keywords": [
"requests",
" api",
" testing",
" validation",
" ai",
" http",
" automation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f0f7519161f01119597972e9c99766810049760a1d4a51984e8796d12b7d8bba",
"md5": "0530e7dfafc25ff986add4231ba578bd",
"sha256": "420ae233c5f5bad258bdca6e621e32e85e19c0f8449e5db8799f5a9f05adc52e"
},
"downloads": -1,
"filename": "requests_ai_validator-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0530e7dfafc25ff986add4231ba578bd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 37908,
"upload_time": "2025-08-22T13:42:19",
"upload_time_iso_8601": "2025-08-22T13:42:19.811541Z",
"url": "https://files.pythonhosted.org/packages/f0/f7/519161f01119597972e9c99766810049760a1d4a51984e8796d12b7d8bba/requests_ai_validator-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "811042680aaa2c8c2a98ae4dcf81b8f69d87d85ecfe5d5627a3e0f8a9f5ccda8",
"md5": "ca98cac71a530897dee3ba675f5401c7",
"sha256": "300157bbf1c0113fdcca15d7913b9ada96d23b27be3d8c1779059dd15dfc92bf"
},
"downloads": -1,
"filename": "requests_ai_validator-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "ca98cac71a530897dee3ba675f5401c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 33681,
"upload_time": "2025-08-22T13:42:21",
"upload_time_iso_8601": "2025-08-22T13:42:21.039919Z",
"url": "https://files.pythonhosted.org/packages/81/10/42680aaa2c8c2a98ae4dcf81b8f69d87d85ecfe5d5627a3e0f8a9f5ccda8/requests_ai_validator-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-22 13:42:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "manikosto",
"github_project": "requests-ai-validator",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.25.0"
]
]
},
{
"name": "openai",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "anthropic",
"specs": [
[
">=",
"0.25.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"0.19.0"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"7.0.0"
]
]
},
{
"name": "allure-pytest",
"specs": [
[
">=",
"2.12.0"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
">=",
"4.0.0"
]
]
}
],
"lcname": "requests-ai-validator"
}