Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
通过 OpenAI 兼容模型在 Pydantic AI 中使用 TokenLab
OpenAIChatModel
OpenAIProvider(base_url=...)
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
import os from pydantic_ai import Agent from pydantic_ai.models.openai import OpenAIChatModel from pydantic_ai.providers.openai import OpenAIProvider model = OpenAIChatModel( "claude-sonnet-5", provider=OpenAIProvider( base_url="https://api.tokenlab.sh/v1", api_key=os.environ["TOKENLAB_API_KEY"], ), ) agent = Agent(model) result = agent.run_sync("Explain one benefit of OpenAI-compatible gateways.") print(result.output)
from pydantic_ai import Agent, RunContext agent = Agent(model) @agent.tool def lookup_status(ctx: RunContext[None], service: str) -> str: return f"{service} is online" result = agent.run_sync("Check the TokenLab status.") print(result.output)