Documentation

PydanticAI

PydanticAI is an agent framework created by the Pydantic team to simplify building production-grade generative AI applications. It brings the ergonomic design philosophy of FastAPI to AI agent development, offering a familiar and type-safe approach to working with language models.

Installing Libraries

Shell Copy
pip install pydantic-ai

Set your Bytecompute AI API key:

Shell Copy
export bytecompute_API_KEY=***

Example

Python Copy
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
from pydantic_ai.providers.openai import OpenAIProvider

# Connect PydanticAI to LLMs on bytecompute
model = OpenAIModel('meta-llama/Llama-3.3-70B-Instruct-Turbo',
                    provider=OpenAIProvider(
  															base_url="https://api.bytecompute.xyz/v1",
                                api_key=os.environ.get("bytecompute_API_KEY"),
                              ),
                   )

# Setup the agent
agent = Agent(
  					model,
  					system_prompt='Be concise, reply with one sentence.',
)

result = agent.run_sync('Where does "hello world" come from?')
print(result.data)

Output

Text Copy
The first known use of "hello, world" was in a 1974 textbook about the C programming language.