dottxt CLI
The fastest way to see structured output using the dottxt CLI:pip install dottxt
export DOTTXT_API_KEY="your-api-key"
cat > contact.schema.json <<'JSON'
{
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "pattern": "^[^@]+@[^@]+$" },
"role": { "type": "string" }
},
"required": ["name", "email"],
"additionalProperties": false
}
JSON
dottxt generate \
--model openai/gpt-oss-20b \
--schema contact.schema.json \
"Extract: John Smith <john@acme.com>, VP Engineering"
export DOTTXT_API_KEY="your-api-key"
curl https://api.dottxt.ai/v1/chat/completions \
-H "Authorization: Bearer $DOTTXT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-oss-20b",
"messages": [{ "role": "user", "content": "Extract: John Smith <john@acme.com>, VP Engineering" }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "contact",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "pattern": "^[^@]+@[^@]+$" },
"role": { "type": "string" }
},
"required": ["name", "email"],
"additionalProperties": false
}
}
}
}'
1. Install
pip install dottxt
pip install openai pydantic
npm install ai @ai-sdk/openai
2. Set your API key
export DOTTXT_API_KEY="your-api-key"
$env:DOTTXT_API_KEY="your-api-key"
3. Run your first extraction
from pydantic import BaseModel, Field
from dottxt import DotTxt
class Contact(BaseModel):
name: str = Field(min_length=1)
email: str = Field(pattern=r"^[^@]+@[^@]+$")
role: str | None = None
client = DotTxt()
result = client.generate(
model="openai/gpt-oss-20b",
input="Extract: John Smith <john@acme.com>, VP Engineering",
response_format=Contact,
)
print(result.model_dump())
import os
from openai import OpenAI
from pydantic import BaseModel, Field
class Contact(BaseModel):
name: str = Field(min_length=1)
email: str = Field(pattern=r"^[^@]+@[^@]+$")
role: str | None = None
client = OpenAI(
base_url="https://api.dottxt.ai/v1",
api_key=os.environ["DOTTXT_API_KEY"],
)
response = client.chat.completions.create(
model="openai/gpt-oss-20b",
messages=[
{"role": "user", "content": "Extract: John Smith <john@acme.com>, VP Engineering"}
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "contact",
"strict": True,
"schema": Contact.model_json_schema(),
},
},
)
result = Contact.model_validate_json(response.choices[0].message.content)
print(result.model_dump())
import { createOpenAI } from "@ai-sdk/openai";
import { generateObject, jsonSchema } from "ai";
const dottxt = createOpenAI({
baseURL: "https://api.dottxt.ai/v1",
apiKey: process.env.DOTTXT_API_KEY!,
});
const { object } = await generateObject({
model: dottxt.chat("openai/gpt-oss-20b"),
schemaName: "contact",
schema: jsonSchema({
type: "object",
properties: {
name: { type: "string", minLength: 1 },
email: { type: "string", pattern: "^[^@]+@[^@]+$" },
role: { type: "string" },
},
required: ["name", "email"],
additionalProperties: false,
}),
prompt: "Extract: John Smith <john@acme.com>, VP Engineering",
});
console.log(object);
{
"name": "John Smith",
"email": "john@acme.com",
"role": "VP Engineering"
}
4. Next steps
- Learn schema patterns: JSON Schema overview
- Keep OpenAI-style code and switch providers: Migrate from other providers
- Browse endpoints and auth: API overview
- Send your schema for feedback before launch: Schema audit