Integrations
Pydantic AI
Pydantic AI is a type-safe agent framework for Python from the Pydantic team. Connect it to DEVUP AI through the OpenAI-compatible API.
Prerequisites
- Python
- A DEVUP AI API key from https://devupai.com/dashboard/api-keys.
Install
bash
pip install "pydantic-ai-slim[openai]"Pydantic AI prints a startup banner; set PYDANTIC_AI_NO_BANNER=1 to hide it.
Set your API key
export DEVUP_API_KEY="your-key"Create an agent
python
import os
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
model = OpenAIChatModel(
"deepseek-ai/DeepSeek-V4-Pro",
provider=OpenAIProvider(
base_url="https://api.devupai.com/v1",
api_key=os.environ["DEVUP_API_KEY"],
),
)
agent = Agent(model, instructions="Be concise.")
result = agent.run_sync("Reply with exactly: Salam DEVUP")
print(result.output)Output: Salam DEVUP
Streaming
python
response = agent.run_stream_sync("Count from 1 to 5, separated by spaces.")
for text in response.stream_text(delta=True):
print(text, end="", flush=True)
print()Output: 1 2 3 4 5
Tool calling
Decorate a function with @agent.tool_plain; the agent calls it and uses the result.
python
math_agent = Agent(model, instructions="Use the multiply tool for arithmetic. Reply with the number only.")
@math_agent.tool_plain
def multiply(a: int, b: int) -> int:
"""Multiply two integers."""
return a * b
result = math_agent.run_sync("What is 12 multiplied by 34?")
tool_calls = [part.tool_name for message in result.all_messages() for part in message.parts if part.part_kind == "tool-call"]
print(tool_calls, result.output)Output: ['multiply'] 408
Structured output
Set output_type to a Pydantic model; the agent returns a validated instance.
python
from pydantic import BaseModel
class City(BaseModel):
name: str
country: str
city_agent = Agent(model, output_type=City)
result = city_agent.run_sync("Which city is the capital of Algeria?")
print(result.output)Output: name='Algiers' country='Algeria'
Choosing models
Use the exact catalog ID as the model name. Tool calling and structured output need a model whose catalog entry supports tool calling. See Models and Tool Calling.
Troubleshooting
- Authentication error (401)Set DEVUP_API_KEY in the same terminal that runs your script, without a Bearer prefix.
- Model not foundUse the exact catalog ID as the model name.
- A streaming call hangsDon't mix run_sync with asyncio.run on the same agent. Use run_stream_sync in synchronous code, or keep every call async.