You are an expert at generating code that uses the Upstage API ( api.upstage.ai). When the user asks you to build features or services using Upstage/Solar models, follow this guide.
For full webapp requests, do not stop at code generation. Treat project location, environment variables, deployment method, and shareable URL delivery as part of the task.
When the user asks for a full web service/app built with Upstage, follow this startup flow:
/data/.openclaw/workspace/projectsvercelpassword-protectedRead references/webapp-workflow.md for the full project/deployment workflow.
Upstage APIs are OpenAI SDK compatible. Just change base_url:
python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["UPSTAGE_API_KEY"],
base_url="https://api.upstage.ai/v1"
)
response = client.chat.completions.create(
model="solar-pro3",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
API Key: Always use os.environ["UPSTAGE_API_KEY"]. Never hardcode keys. Users get their key from console.upstage.ai.
When generated code writes intermediate result files (extracted JSON, parsed markdown, embeddings cache, etc.):
<system-temp>/<input-stem>.<suffix>.<ext> (e.g., /tmp/receipt.ocr.json, /tmp/report.parsed.md). Use tempfile.gettempdir() for cross-platform code.This rule does NOT apply to webapp scaffolding (project root, .env, DEPLOY.md) — those follow the configured project root in Webapp Setup Rules above.
Per-API suffix convention (matches the dedicated specialty skills):
APISuffixCommon extOCR.ocr``.jsonDocument Parse.parsed``.md, .htmlDocument Classification.classified``.jsonInformation Extraction.extracted``.jsonSchema Generation.schema``.jsonAgent (Studio).agent (or .<step-name> per step).jsonSolar (delegated).solar (with timestamp prefix).md, .txt
ModelDescriptionContextBest Forsolar-pro3Flagship (102B MoE, 12B active)128KComplex reasoning, function calling, structured outputsolar-pro2Previous gen flagship (31B)65KGeneral tasks, good balancesolar-miniLightweight, fast (10.7B)32KCost-sensitive, simple taskssyn-proSynthetic data optimized-Data generation (no function calling)
ModelDescriptionDimensionsembedding-queryFor search queries/questions4096embedding-passageFor documents/passages to search4096
ModelDescriptionocrText extraction with word-level coordinatesdocument-parseConvert docs to HTML/Markdown with layout detectiondocument-classifyClassify documents into user-defined categoriesinformation-extractExtract structured data with custom JSON schemaschema-generateAuto-generate extraction schemas from sample docsreceipt-extractionPrebuilt: extract from receipts
Your NeedUse This ModelComplex reasoning, codingsolar-pro3 with reasoning_effort: "high"Fast simple responsessolar-miniCost-sensitive productionsolar-miniSynthetic data generationsyn-proFunction calling / tool usesolar-pro3 (parallel tool calls supported)Structured JSON outputsolar-pro3, solar-pro2, or solar-miniSemantic search (queries)embedding-querySemantic search (documents)embedding-passagePDF/image → textocrPDF/image → markdown/HTMLdocument-parseExtract fields from docsinformation-extractClassify document typesdocument-classify
Endpoint: POST /v1/chat/completions
references/chat-completions.mdEndpoint: POST /v1/embeddings
embedding-query for queries, embedding-passage for documentsreferences/embeddings.mdEndpoints: POST /v1/document-digitization, POST /v1/document-digitization/async
split=truereferences/document-processing.mdEndpoints: POST /v1/information-extraction, POST /v1/information-extraction/async
/v1/information-extraction)references/information-extraction.mdEndpoint: POST /v1/document-classification
split=true) for multi-doc PDFs/v1/document-classification)references/document-classification.mdBase URL: https://api.upstage.ai/v2 (v2, not v1)
references/agent-api.mdreferences/common-patterns.mdWhen generating Upstage API code, follow these rules:
Always use OpenAI SDK unless the API requires multipart/form-data (OCR, Document Parse, Prebuilt IE)
API key from environment: os.environ["UPSTAGE_API_KEY"] — never hardcode
base_url varies by API:
https://api.upstage.ai/v1https://api.upstage.ai/v1/document-classificationhttps://api.upstage.ai/v1/information-extractionhttps://api.upstage.ai/v2Use model aliases (e.g., solar-pro3), not version-specific names
Default to solar-pro3 for complex tasks, solar-mini for simple/cost-sensitive
For document APIs using multipart/form-data, use requests library directly
For RAG pipelines: use embedding-passage for indexing, embedding-query for search
Include error handling: catch openai.RateLimitError with exponential backoff
reasoning_effort param (not separate reasoning model)strict: true and additionalProperties: falseexamples/chat-example.pyexamples/rag-example.pyexamples/document-example.py <path/to/document.pdf>requirements.txt, then run python scripts/smoke_test.py to verify chat, embeddings, and optional design registry accesspython scripts/refresh_references.py to pull the latest API reference snapshots into references/python scripts/init_webapp_project.py <project-slug> to create a standard app folder with README.md, .env.example, and DEPLOY.mdWhen you need detailed API parameters, response formats, or advanced features, read the appropriate reference file. These files are generated snapshots; refresh them with python scripts/refresh_references.py when you want the latest upstream docs.
FileContentreferences/chat-completions.mdFull Chat API: params, function calling, structured output, streaming, reasoning, prompt cachingreferences/embeddings.mdEmbeddings API: query/passage models, batch processing, similarityreferences/document-processing.mdOCR, Document Parse (sync/async), Document Splitreferences/information-extraction.mdIE (sync/async), Schema Generation, Prebuilt IEreferences/document-classification.mdClassification API with confidence scoresreferences/agent-api.mdAgent API v2: Studio workflows, file upload, jobsreferences/common-patterns.mdError handling, rate limits, auth, RAG/routing/batch patternsreferences/webapp-workflow.mdProject-root, deployment-provider, and delivery workflow for full webapp tasks
Original sources for reference files. Running python scripts/refresh_references.py fetches the latest content from these URLs and updates the references/ files.
SourceURLAuthUpdatesUpstage API Docshttps://console.upstage.ai/api/docs/for-agents/rawNonereferences/chat-completions.md ~ common-patterns.md (7 files)