mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-31 12:30:30 +08:00
Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d26214581 | ||
|
|
d66795f1d4 | ||
|
|
ed17d25183 | ||
|
|
f7f8677367 | ||
|
|
041d7f8bef | ||
|
|
208909274f | ||
|
|
43720ce166 | ||
|
|
7a11b80884 | ||
|
|
03054b21e4 | ||
|
|
da48e8c4ea | ||
|
|
0fc7236673 | ||
|
|
6a00ea71df | ||
|
|
3f23f3c38a | ||
|
|
2da946464f | ||
|
|
d06237bfde | ||
|
|
ab530a160e |
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(python3:*)",
|
||||
"Bash(git push:*)",
|
||||
"Bash(gh pr create:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
<div align="center">
|
||||
<a href="https://codespaces.new/OpenRouterTeam/python-sdk.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
|
||||
<a href="https://codespaces.new/speakeasy-sdks/openrouter-python-sdk.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pylintrc
|
||||
docs/docs.json
|
||||
docs/overview.mdx
|
||||
@@ -1,225 +0,0 @@
|
||||
name: Auto-merge Speakeasy PR
|
||||
|
||||
# Called as a follow-up job after Speakeasy Generate (mode: pr). Merges the
|
||||
# regen PR opened/updated in the same workflow run so sdk_publish.yaml can run.
|
||||
# Prefer branch_name from Generate logs; fall back to run_started_at heuristics.
|
||||
# Uses GH_DOCS_SYNC GitHub App token (not a PAT) so merges trigger downstream push.
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
run_started_at:
|
||||
description: ISO timestamp when the parent Generate workflow run started
|
||||
required: true
|
||||
type: string
|
||||
branch_name:
|
||||
description: Speakeasy regen branch from the parent Generate run (optional)
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
secrets:
|
||||
GH_DOCS_SYNC_APP_ID:
|
||||
required: true
|
||||
GH_DOCS_SYNC_APP_PRIVATE_KEY:
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
concurrency:
|
||||
group: auto-merge-speakeasy
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
auto-merge:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Generate GitHub App token
|
||||
id: app-token
|
||||
# actions/create-github-app-token@v3.2.0 (immutable SHA)
|
||||
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1
|
||||
with:
|
||||
app-id: ${{ secrets.GH_DOCS_SYNC_APP_ID }}
|
||||
private-key: ${{ secrets.GH_DOCS_SYNC_APP_PRIVATE_KEY }}
|
||||
|
||||
- name: Resolve Speakeasy regen PR
|
||||
id: pr
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_STARTED="${{ inputs.run_started_at }}"
|
||||
BRANCH="${{ inputs.branch_name }}"
|
||||
|
||||
PR_JSON=$(gh pr list \
|
||||
--repo "$REPO" \
|
||||
--state open \
|
||||
--search "head:speakeasy-sdk-regen-" \
|
||||
--limit 500 \
|
||||
--json number,updatedAt,title,labels,author,headRefName)
|
||||
|
||||
PR_NUM=""
|
||||
if [ -n "$BRANCH" ]; then
|
||||
CANDIDATE=$(echo "$PR_JSON" | jq -r --arg branch "$BRANCH" \
|
||||
'[.[] | select(.headRefName == $branch)] | .[0] // empty')
|
||||
if [ -n "$CANDIDATE" ] && echo "$CANDIDATE" | jq -e '
|
||||
(.headRefName | startswith("speakeasy-sdk-regen-"))
|
||||
and (.title | contains("🐝 Update SDK"))
|
||||
and ([.labels[].name] | any(. == "patch" or . == "minor" or . == "major"))
|
||||
and (.author.is_bot == true)
|
||||
' > /dev/null; then
|
||||
PR_NUM=$(echo "$CANDIDATE" | jq -r '.number')
|
||||
echo "Resolved Speakeasy regen PR #$PR_NUM from branch $BRANCH"
|
||||
else
|
||||
echo "::warning::branch_name=$BRANCH did not match a valid open regen PR — falling back to run_started_at"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$PR_NUM" ]; then
|
||||
PR_NUM=$(echo "$PR_JSON" | jq -r --arg started "$RUN_STARTED" '
|
||||
[.[]
|
||||
| select(.headRefName | startswith("speakeasy-sdk-regen-"))
|
||||
| select(.title | contains("🐝 Update SDK"))
|
||||
| select([.labels[].name] | any(. == "patch" or . == "minor" or . == "major"))
|
||||
| select(.author.is_bot == true)
|
||||
| select(.updatedAt >= $started)
|
||||
] | sort_by(.updatedAt) | last | .number // empty')
|
||||
fi
|
||||
|
||||
if [ -z "$PR_NUM" ]; then
|
||||
echo "No Speakeasy regen PR for this Generate run — skipping auto-merge"
|
||||
echo "::notice title=auto-merge-skipped::No qualifying Speakeasy regen PR to merge"
|
||||
{
|
||||
echo "## Auto-merge skipped"
|
||||
echo "No qualifying \`speakeasy-sdk-regen-*\` PR was found."
|
||||
echo "- branch_name input: \`${BRANCH:-<empty>}\`"
|
||||
echo "- run_started_at: \`$RUN_STARTED\`"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "pr_num=" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "pr_num=$PR_NUM" >> "$GITHUB_OUTPUT"
|
||||
echo "$PR_JSON" > /tmp/speakeasy_pr_json.json
|
||||
|
||||
- name: Close superseded Speakeasy PRs
|
||||
if: steps.pr.outputs.pr_num != ''
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
CURRENT_PR="${{ steps.pr.outputs.pr_num }}"
|
||||
PR_JSON=$(cat /tmp/speakeasy_pr_json.json)
|
||||
|
||||
PRIOR_JSON=$(echo "$PR_JSON" | jq -r --arg current_pr "$CURRENT_PR" \
|
||||
'[.[].number | select(tostring != $current_pr)] | .[]')
|
||||
|
||||
if [ -z "$PRIOR_JSON" ]; then
|
||||
echo "No superseded Speakeasy PRs to close"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mapfile -t PRIOR <<< "$PRIOR_JSON"
|
||||
|
||||
echo "Closing ${#PRIOR[@]} superseded Speakeasy PR(s)"
|
||||
for N in "${PRIOR[@]}"; do
|
||||
gh pr close "$N" --repo "${{ github.repository }}" --delete-branch \
|
||||
--comment "Superseded by newer Speakeasy SDK generation PR #${CURRENT_PR}" \
|
||||
|| echo "::warning::Failed to close PR #$N (continuing)"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
- name: Auto-merge Speakeasy PR
|
||||
if: steps.pr.outputs.pr_num != ''
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
PR_NUM="${{ steps.pr.outputs.pr_num }}"
|
||||
REPO="${{ github.repository }}"
|
||||
|
||||
wait_for_checks() {
|
||||
local pr=$1
|
||||
local timeout=600
|
||||
local interval=15
|
||||
local elapsed=0
|
||||
|
||||
echo "Waiting for PR #$pr checks (timeout ${timeout}s)..."
|
||||
while [ "$elapsed" -lt "$timeout" ]; do
|
||||
TOTAL=$(gh pr view "$pr" --repo "$REPO" --json statusCheckRollup --jq \
|
||||
'.statusCheckRollup | length')
|
||||
PENDING=$(gh pr view "$pr" --repo "$REPO" --json statusCheckRollup --jq \
|
||||
'[.statusCheckRollup[]? | select(.status != "COMPLETED")] | length')
|
||||
FAILED=$(gh pr view "$pr" --repo "$REPO" --json statusCheckRollup --jq \
|
||||
'[.statusCheckRollup[]? | select(.status == "COMPLETED") | select(.conclusion != "SUCCESS" and .conclusion != "SKIPPED" and .conclusion != "NEUTRAL")] | length')
|
||||
|
||||
if [ "$TOTAL" -eq 0 ]; then
|
||||
# GITHUB_TOKEN-authored regen PRs get no pull_request checks at all,
|
||||
# so TOTAL stays 0 forever. Wait a short grace window in case checks
|
||||
# are merely slow to register, then proceed rather than time out.
|
||||
if [ "$elapsed" -ge 60 ]; then
|
||||
echo "No checks registered after ${elapsed}s — proceeding (checkless PR)"
|
||||
return 0
|
||||
fi
|
||||
echo "Checks not yet registered — waiting ${interval}s..."
|
||||
sleep "$interval"
|
||||
elapsed=$((elapsed + interval))
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$PENDING" -eq 0 ]; then
|
||||
if [ "$FAILED" -gt 0 ]; then
|
||||
echo "::error::PR #$pr has failing checks — refusing direct merge"
|
||||
gh pr checks "$pr" --repo "$REPO" || true
|
||||
exit 1
|
||||
fi
|
||||
echo "All checks completed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Checks pending ($PENDING) — waiting ${interval}s..."
|
||||
sleep "$interval"
|
||||
elapsed=$((elapsed + interval))
|
||||
done
|
||||
|
||||
echo "::error::Timed out waiting for PR #$pr checks"
|
||||
exit 1
|
||||
}
|
||||
|
||||
STATE=$(gh pr view "$PR_NUM" --repo "$REPO" --json state --jq .state)
|
||||
if [ "$STATE" != "OPEN" ]; then
|
||||
echo "PR #$PR_NUM is $STATE — skipping merge"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
MERGE_METHOD=""
|
||||
# Prefer GitHub auto-merge when required checks exist; otherwise
|
||||
# squash-merge directly after checks pass (sdk-release-prs.yaml pattern).
|
||||
AUTO_MERGE_NOOP_PATTERN='is in clean status|protected branch rules|Branch does not have required protected branch rules'
|
||||
if gh pr merge "$PR_NUM" --repo "$REPO" --squash --auto --delete-branch 2> /tmp/gh-merge.err; then
|
||||
MERGE_METHOD="auto-merge queued"
|
||||
echo "Auto-merge enabled for Speakeasy PR #$PR_NUM"
|
||||
elif grep -qiE "$AUTO_MERGE_NOOP_PATTERN" /tmp/gh-merge.err; then
|
||||
echo "Auto-merge not applicable — waiting for checks, then merging PR #$PR_NUM directly"
|
||||
cat /tmp/gh-merge.err >&2
|
||||
wait_for_checks "$PR_NUM"
|
||||
gh pr merge "$PR_NUM" --repo "$REPO" --squash --delete-branch
|
||||
MERGE_METHOD="direct squash (checks passed)"
|
||||
else
|
||||
echo "::error::Failed to enable auto-merge on Speakeasy PR #$PR_NUM"
|
||||
cat /tmp/gh-merge.err >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "::notice title=auto-merge-pr::Merged Speakeasy PR #$PR_NUM ($MERGE_METHOD)"
|
||||
{
|
||||
echo "## Auto-merge complete"
|
||||
echo "- PR: #$PR_NUM"
|
||||
echo "- Method: $MERGE_METHOD"
|
||||
echo "- Token: GH_DOCS_SYNC GitHub App"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
@@ -1,32 +0,0 @@
|
||||
name: Docs navigation
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
paths:
|
||||
- "docs/sdks/**"
|
||||
- "scripts/gen-docs-nav.sh"
|
||||
- ".github/workflows/docs-nav.yaml"
|
||||
|
||||
jobs:
|
||||
gen-docs-nav:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# jq is preinstalled on GitHub-hosted ubuntu runners.
|
||||
- name: Regenerate docs navigation
|
||||
run: scripts/gen-docs-nav.sh
|
||||
|
||||
- name: Auto-commit docs.json navigation
|
||||
uses: int128/update-generated-files-action@v2
|
||||
with:
|
||||
commit-message: "Chore: regenerate docs navigation"
|
||||
@@ -1,46 +0,0 @@
|
||||
name: Notify Monorepo of Changes
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
notify-monorepo:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Send repository dispatch to monorepo
|
||||
run: |
|
||||
# Determine which event type to send based on repository name
|
||||
REPO_NAME="${GITHUB_REPOSITORY#*/}" # Gets 'python-sdk' from 'OpenRouterTeam/python-sdk'
|
||||
|
||||
case "$REPO_NAME" in
|
||||
"typescript-sdk")
|
||||
EVENT_TYPE="sync-typescript-sdk"
|
||||
;;
|
||||
"python-sdk")
|
||||
EVENT_TYPE="sync-python-sdk"
|
||||
;;
|
||||
"ai-sdk-provider")
|
||||
EVENT_TYPE="sync-ai-sdk-provider"
|
||||
;;
|
||||
"cli")
|
||||
EVENT_TYPE="sync-cli"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown repository: $REPO_NAME"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Sending repository_dispatch event: $EVENT_TYPE"
|
||||
|
||||
curl -L \
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer ${{ secrets.MONOREPO_SYNC_TOKEN }}" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
https://api.github.com/repos/OpenRouterTeam/openrouter-web/dispatches \
|
||||
-d "{\"event_type\":\"$EVENT_TYPE\",\"client_payload\":{\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"sha\":\"$GITHUB_SHA\"}}"
|
||||
|
||||
echo "✅ Notification sent to monorepo"
|
||||
@@ -1,37 +0,0 @@
|
||||
name: PR Validation
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- .speakeasy/in.openapi.yaml
|
||||
|
||||
concurrency:
|
||||
group: pr-validation-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
|
||||
- name: Build SDK
|
||||
run: uv build
|
||||
|
||||
- name: Type check (mypy)
|
||||
run: uv run --group dev mypy src
|
||||
|
||||
- name: Type check (pyright)
|
||||
run: uv run --group dev pyright src
|
||||
|
||||
- name: Lint (pylint)
|
||||
run: uv run --group dev pylint src --rcfile pylintrc
|
||||
@@ -21,11 +21,6 @@ permissions:
|
||||
types:
|
||||
- labeled
|
||||
- unlabeled
|
||||
|
||||
concurrency:
|
||||
group: speakeasy-generate
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15
|
||||
@@ -35,69 +30,4 @@ jobs:
|
||||
set_version: ${{ github.event.inputs.set_version }}
|
||||
secrets:
|
||||
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
pypi_token: ${{ secrets.PYPI_TOKEN }}
|
||||
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
||||
|
||||
resolve-branch:
|
||||
needs: generate
|
||||
if: ${{ !cancelled() && needs.generate.result == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
branch_name: ${{ steps.branch.outputs.branch_name }}
|
||||
run_started_at: ${{ steps.branch.outputs.run_started_at }}
|
||||
steps:
|
||||
- name: Extract branch from Generate logs
|
||||
id: branch
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_ID="${{ github.run_id }}"
|
||||
|
||||
RUN_STARTED="${{ github.run_started_at }}"
|
||||
if [ -z "$RUN_STARTED" ]; then
|
||||
RUN_STARTED=$(gh run view "$RUN_ID" --repo "$REPO" --json startedAt --jq '.startedAt')
|
||||
echo "Resolved run_started_at from API: $RUN_STARTED"
|
||||
fi
|
||||
echo "run_started_at=$RUN_STARTED" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Full-run logs are unavailable while the workflow is in progress;
|
||||
# fetch logs from the completed generate job instead.
|
||||
JOB_ID=$(gh run view "$RUN_ID" --repo "$REPO" --json jobs --jq \
|
||||
'[.jobs[] | select(.name == "generate / Generate Target")] | .[0].databaseId // empty')
|
||||
|
||||
BRANCH=""
|
||||
if [ -z "$JOB_ID" ]; then
|
||||
echo "::warning::Could not find generate job id — auto-merge will use run_started_at fallback"
|
||||
else
|
||||
MAX_ATTEMPTS=12
|
||||
INTERVAL=10
|
||||
for attempt in $(seq 1 "$MAX_ATTEMPTS"); do
|
||||
BRANCH=$(gh run view "$RUN_ID" --repo "$REPO" --job "$JOB_ID" --log 2>/dev/null \
|
||||
| grep -oE 'branch_name=speakeasy-sdk-regen-[0-9]+' | tail -1 | cut -d= -f2 || true)
|
||||
if [ -n "$BRANCH" ]; then
|
||||
echo "Extracted branch_name=$BRANCH (attempt $attempt)"
|
||||
break
|
||||
fi
|
||||
if [ "$attempt" -lt "$MAX_ATTEMPTS" ]; then
|
||||
echo "Job logs not ready — waiting ${INTERVAL}s (attempt $attempt/$MAX_ATTEMPTS)..."
|
||||
sleep "$INTERVAL"
|
||||
fi
|
||||
done
|
||||
if [ -z "$BRANCH" ]; then
|
||||
echo "::warning::Could not extract branch_name from Generate logs after ${MAX_ATTEMPTS} attempts — auto-merge will use run_started_at fallback"
|
||||
fi
|
||||
fi
|
||||
echo "branch_name=$BRANCH" >> "$GITHUB_OUTPUT"
|
||||
|
||||
auto-merge:
|
||||
needs: [generate, resolve-branch]
|
||||
if: ${{ !cancelled() && needs.generate.result == 'success' }}
|
||||
uses: ./.github/workflows/auto-merge-speakeasy-pr.yaml
|
||||
with:
|
||||
run_started_at: ${{ needs.resolve-branch.outputs.run_started_at }}
|
||||
branch_name: ${{ needs.resolve-branch.outputs.branch_name }}
|
||||
secrets:
|
||||
GH_DOCS_SYNC_APP_ID: ${{ secrets.GH_DOCS_SYNC_APP_ID }}
|
||||
GH_DOCS_SYNC_APP_PRIVATE_KEY: ${{ secrets.GH_DOCS_SYNC_APP_PRIVATE_KEY }}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
name: Generate (spec change merged)
|
||||
permissions:
|
||||
checks: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
statuses: write
|
||||
id-token: write
|
||||
"on":
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
force:
|
||||
description: Force generation of SDKs
|
||||
type: boolean
|
||||
default: false
|
||||
set_version:
|
||||
description: optionally set a specific SDK version
|
||||
type: string
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- .speakeasy/in.openapi.yaml
|
||||
|
||||
concurrency:
|
||||
group: speakeasy-generate-spec-change
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
|
||||
uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15
|
||||
with:
|
||||
force: ${{ github.event.inputs.force }}
|
||||
mode: pr
|
||||
set_version: ${{ github.event.inputs.set_version }}
|
||||
secrets:
|
||||
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
pypi_token: ${{ secrets.PYPI_TOKEN }}
|
||||
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
||||
|
||||
resolve-branch:
|
||||
needs: generate
|
||||
if: ${{ !cancelled() && needs.generate.result == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
branch_name: ${{ steps.branch.outputs.branch_name }}
|
||||
run_started_at: ${{ steps.branch.outputs.run_started_at }}
|
||||
steps:
|
||||
- name: Extract branch from Generate logs
|
||||
id: branch
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_ID="${{ github.run_id }}"
|
||||
|
||||
RUN_STARTED="${{ github.run_started_at }}"
|
||||
if [ -z "$RUN_STARTED" ]; then
|
||||
RUN_STARTED=$(gh run view "$RUN_ID" --repo "$REPO" --json startedAt --jq '.startedAt')
|
||||
echo "Resolved run_started_at from API: $RUN_STARTED"
|
||||
fi
|
||||
echo "run_started_at=$RUN_STARTED" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Full-run logs are unavailable while the workflow is in progress;
|
||||
# fetch logs from the completed generate job instead.
|
||||
JOB_ID=$(gh run view "$RUN_ID" --repo "$REPO" --json jobs --jq \
|
||||
'[.jobs[] | select(.name == "generate / Generate Target")] | .[0].databaseId // empty')
|
||||
|
||||
BRANCH=""
|
||||
if [ -z "$JOB_ID" ]; then
|
||||
echo "::warning::Could not find generate job id — auto-merge will use run_started_at fallback"
|
||||
else
|
||||
MAX_ATTEMPTS=12
|
||||
INTERVAL=10
|
||||
for attempt in $(seq 1 "$MAX_ATTEMPTS"); do
|
||||
BRANCH=$(gh run view "$RUN_ID" --repo "$REPO" --job "$JOB_ID" --log 2>/dev/null \
|
||||
| grep -oE 'branch_name=speakeasy-sdk-regen-[0-9]+' | tail -1 | cut -d= -f2 || true)
|
||||
if [ -n "$BRANCH" ]; then
|
||||
echo "Extracted branch_name=$BRANCH (attempt $attempt)"
|
||||
break
|
||||
fi
|
||||
if [ "$attempt" -lt "$MAX_ATTEMPTS" ]; then
|
||||
echo "Job logs not ready — waiting ${INTERVAL}s (attempt $attempt/$MAX_ATTEMPTS)..."
|
||||
sleep "$INTERVAL"
|
||||
fi
|
||||
done
|
||||
if [ -z "$BRANCH" ]; then
|
||||
echo "::warning::Could not extract branch_name from Generate logs after ${MAX_ATTEMPTS} attempts — auto-merge will use run_started_at fallback"
|
||||
fi
|
||||
fi
|
||||
echo "branch_name=$BRANCH" >> "$GITHUB_OUTPUT"
|
||||
|
||||
auto-merge:
|
||||
needs: [generate, resolve-branch]
|
||||
if: ${{ !cancelled() && needs.generate.result == 'success' }}
|
||||
uses: ./.github/workflows/auto-merge-speakeasy-pr.yaml
|
||||
with:
|
||||
run_started_at: ${{ needs.resolve-branch.outputs.run_started_at }}
|
||||
branch_name: ${{ needs.resolve-branch.outputs.branch_name }}
|
||||
secrets:
|
||||
GH_DOCS_SYNC_APP_ID: ${{ secrets.GH_DOCS_SYNC_APP_ID }}
|
||||
GH_DOCS_SYNC_APP_PRIVATE_KEY: ${{ secrets.GH_DOCS_SYNC_APP_PRIVATE_KEY }}
|
||||
@@ -1,23 +1,19 @@
|
||||
name: Publish
|
||||
name: Speakeasy Tagging
|
||||
permissions:
|
||||
checks: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
statuses: write
|
||||
id-token: write
|
||||
"on":
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- .speakeasy/gen.lock
|
||||
workflow_dispatch: {}
|
||||
jobs:
|
||||
publish:
|
||||
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
|
||||
tag:
|
||||
uses: speakeasy-api/sdk-generation-action/.github/workflows/tag.yaml@v15
|
||||
with:
|
||||
target: open-router
|
||||
registry_tags: main
|
||||
secrets:
|
||||
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
pypi_token: ${{ secrets.PYPI_TOKEN }}
|
||||
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
||||
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
||||
+2
-14
@@ -1,24 +1,12 @@
|
||||
.venv/
|
||||
venv/
|
||||
src/*.egg-info/
|
||||
**/__pycache__/
|
||||
.pytest_cache/
|
||||
.python-version
|
||||
.DS_Store
|
||||
pyrightconfig.json
|
||||
**/.speakeasy/temp/
|
||||
**/.speakeasy/logs/
|
||||
.speakeasy/reports
|
||||
# Build artifacts
|
||||
/dist
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
*.egg
|
||||
# Speakeasy generation artifacts (generated in OSS repo, not here)
|
||||
.speakeasy/*.lock
|
||||
.speakeasy/*.openapi.yaml
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
.DS_Store
|
||||
.venv/
|
||||
|
||||
+302
-11130
File diff suppressed because it is too large
Load Diff
+9
-48
@@ -6,7 +6,7 @@ generation:
|
||||
sdkClassName: OpenRouter
|
||||
maintainOpenAPIOrder: true
|
||||
usageSnippets:
|
||||
optionalPropertyRendering: never
|
||||
optionalPropertyRendering: withExample
|
||||
sdkInitStyle: constructor
|
||||
useClassNamesForArrayFields: true
|
||||
fixes:
|
||||
@@ -16,91 +16,52 @@ generation:
|
||||
requestResponseComponentNamesFeb2024: true
|
||||
securityFeb2025: true
|
||||
sharedErrorComponentsApr2025: true
|
||||
sharedNestedComponentsJan2026: false
|
||||
nameOverrideFeb2026: false
|
||||
auth:
|
||||
oAuth2ClientCredentialsEnabled: true
|
||||
oAuth2PasswordEnabled: true
|
||||
hoistGlobalSecurity: true
|
||||
inferSSEOverload: true
|
||||
sdkHooksConfigAccess: true
|
||||
schemas:
|
||||
allOfMergeStrategy: shallowMerge
|
||||
requestBodyFieldName: ""
|
||||
versioningStrategy: automatic
|
||||
persistentEdits: {}
|
||||
tests:
|
||||
generateTests: false
|
||||
generateNewTests: true
|
||||
skipResponseBodyAssertions: false
|
||||
documentation: mintlify
|
||||
preApplyUnionDiscriminators: true
|
||||
python:
|
||||
version: 0.11.33
|
||||
version: 0.5.2
|
||||
additionalDependencies:
|
||||
dev: {}
|
||||
main: {}
|
||||
allowedRedefinedBuiltins:
|
||||
- id
|
||||
- object
|
||||
- input
|
||||
- models
|
||||
- hash
|
||||
asyncMode: both
|
||||
authors:
|
||||
- OpenRouter
|
||||
- Speakeasy
|
||||
baseErrorName: OpenRouterError
|
||||
bodyVariantOverloads: false
|
||||
clientServerStatusCodesAsErrors: true
|
||||
constFieldCasing: upper
|
||||
defaultErrorName: OpenRouterDefaultError
|
||||
description: Official Python Client SDK for OpenRouter.
|
||||
enableCustomCodeRegions: false
|
||||
description: Python Client SDK Generated by Speakeasy.
|
||||
enableCustomCodeRegions: true
|
||||
enumFormat: union
|
||||
envVarPrefix: OPENROUTER
|
||||
errorSchemaValidation: true
|
||||
eventStreamClassNames:
|
||||
async: EventStreamAsync
|
||||
sync: EventStream
|
||||
fixFlags:
|
||||
asyncPaginationSep2025: true
|
||||
conflictResistantModelImportsFeb2026: false
|
||||
responseRequiredSep2024: true
|
||||
flattenGlobalSecurity: true
|
||||
flattenRequests: true
|
||||
flatteningOrder: parameters-first
|
||||
forwardCompatibleEnumsByDefault: false
|
||||
forwardCompatibleUnionsByDefault: tagged-only
|
||||
imports:
|
||||
option: openapi
|
||||
paths:
|
||||
callbacks: callbacks
|
||||
callbacks: ""
|
||||
errors: errors
|
||||
operations: operations
|
||||
shared: components
|
||||
webhooks: webhooks
|
||||
inferSSEOverload: true
|
||||
inferUnionDiscriminators: true
|
||||
operations: ""
|
||||
shared: ""
|
||||
webhooks: ""
|
||||
inputModelSuffix: input
|
||||
inputTypedDictSuffix: TypedDict
|
||||
legacyPyright: false
|
||||
license: Apache-2.0
|
||||
maxMethodParams: 999
|
||||
methodArguments: infer-optional-args
|
||||
methodTimeoutArgument: timeout-ms
|
||||
methodTimeoutUnits: milliseconds
|
||||
moduleName: ""
|
||||
multipartArrayFormat: legacy
|
||||
optionalDependencies: {}
|
||||
outputModelSuffix: output
|
||||
packageManager: uv
|
||||
packageName: openrouter
|
||||
preApplyUnionDiscriminators: false
|
||||
pytestFilterWarnings: []
|
||||
pytestTimeout: 0
|
||||
rawResponseHelpers: false
|
||||
responseFormat: flat
|
||||
responseSchemaValidation: true
|
||||
sseFlatResponse: true
|
||||
templateVersion: v2
|
||||
useAsyncHooks: false
|
||||
|
||||
+1389
-35653
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
lintVersion: 1.0.0
|
||||
defaultRuleset: openrouter
|
||||
rulesets:
|
||||
openrouter:
|
||||
rulesets:
|
||||
- speakeasy-recommended
|
||||
- speakeasy-generation
|
||||
rules:
|
||||
oas3-missing-example:
|
||||
severity: "off"
|
||||
File diff suppressed because it is too large
Load Diff
+1394
-35532
File diff suppressed because it is too large
Load Diff
@@ -1,52 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Add HTTP-Referer and X-OpenRouter-Title as global parameters
|
||||
version: 0.0.0
|
||||
actions:
|
||||
# Add global parameters for app identification
|
||||
- target: $
|
||||
description: Add x-speakeasy-globals for HTTP-Referer, X-OpenRouter-Title, and X-OpenRouter-Categories headers
|
||||
update:
|
||||
x-speakeasy-globals:
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/AppIdentifier"
|
||||
- $ref: "#/components/parameters/AppDisplayName"
|
||||
- $ref: "#/components/parameters/AppCategories"
|
||||
|
||||
# Add component parameters
|
||||
- target: $.components
|
||||
description: Add parameters for app identification headers
|
||||
update:
|
||||
parameters:
|
||||
AppIdentifier:
|
||||
name: HTTP-Referer
|
||||
in: header
|
||||
schema:
|
||||
type: string
|
||||
description: |
|
||||
The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
||||
This is used to track API usage per application.
|
||||
AppDisplayName:
|
||||
name: X-OpenRouter-Title
|
||||
in: header
|
||||
schema:
|
||||
type: string
|
||||
description: |
|
||||
The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
||||
AppCategories:
|
||||
name: X-OpenRouter-Categories
|
||||
in: header
|
||||
schema:
|
||||
type: string
|
||||
description: |
|
||||
Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
|
||||
|
||||
# Add header parameters to all paths so Speakeasy matches them with globals
|
||||
- target: $.paths[*]
|
||||
description: Reference app identification headers on all paths so Speakeasy injects them via globals
|
||||
update:
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/AppIdentifier"
|
||||
- $ref: "#/components/parameters/AppDisplayName"
|
||||
- $ref: "#/components/parameters/AppCategories"
|
||||
@@ -1,11 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Simplify redundant allOf inline schemas
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: "$..allOf[?@.enum && !@['$ref']]"
|
||||
description: >
|
||||
Remove inline enum definitions that duplicate a $ref enum in the same
|
||||
allOf. These are artifacts from zod-openapi .extend() serialization.
|
||||
remove: true
|
||||
@@ -1,10 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Convert boolean query params from string to boolean
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: $..parameters[?@.schema["x-openrouter-type"] == "boolean"].schema
|
||||
description: Convert x-openrouter-type boolean params from string to boolean
|
||||
update:
|
||||
type: boolean
|
||||
@@ -1,10 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Fix nullable pagination params
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: $..parameters[?@.name == "offset" && @.in == "query"].schema
|
||||
description: Remove nullable from offset query params to fix mypy errors in pagination helpers
|
||||
update:
|
||||
nullable: false
|
||||
@@ -1,10 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Add open enums
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: $..[?length(@.enum) > 1]
|
||||
description: Automatically open all enums that have length > 1
|
||||
update:
|
||||
x-speakeasy-unknown-values: allow
|
||||
@@ -1,15 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Remove RSS+XML response schemas and related parameters
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: $..responses.*.content["application/rss+xml"]
|
||||
description: Remove application/rss+xml response schemas
|
||||
remove: true
|
||||
- target: $..parameters[?@.name == "use_rss"]
|
||||
description: Remove use_rss parameter
|
||||
remove: true
|
||||
- target: $..parameters[?@.name == "use_rss_chat_links"]
|
||||
description: Remove use_rss_chat_links parameter
|
||||
remove: true
|
||||
@@ -1,11 +0,0 @@
|
||||
overlay: 1.0.0
|
||||
x-speakeasy-jsonpath: rfc9535
|
||||
info:
|
||||
title: Retry request-timeout and rate-limit responses
|
||||
version: 0.0.0
|
||||
actions:
|
||||
- target: $["x-speakeasy-retries"].statusCodes
|
||||
description: Also retry 408 (request timeout) and 429 (rate limit), not just 5XX
|
||||
update:
|
||||
- "408"
|
||||
- "429"
|
||||
+13
-24
@@ -1,47 +1,36 @@
|
||||
speakeasyVersion: 1.787.0
|
||||
speakeasyVersion: 1.611.1
|
||||
sources:
|
||||
OpenRouter API:
|
||||
OpenRouter Chat Completions API:
|
||||
sourceNamespace: open-router-chat-completions-api
|
||||
sourceRevisionDigest: sha256:1b18bfafe3a31635470908ce53c1bb12af21a82d371f6f979bb5e8463f52afb3
|
||||
sourceBlobDigest: sha256:506597a9fce25fe757037a95da952e36f33dd702afa16c13d43c2df2d5da1ece
|
||||
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
|
||||
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
|
||||
tags:
|
||||
- latest
|
||||
- speakeasy-sdk-regen-1755878373
|
||||
- 1.0.0
|
||||
targets:
|
||||
open-router:
|
||||
source: OpenRouter API
|
||||
source: OpenRouter Chat Completions API
|
||||
sourceNamespace: open-router-chat-completions-api
|
||||
sourceRevisionDigest: sha256:1b18bfafe3a31635470908ce53c1bb12af21a82d371f6f979bb5e8463f52afb3
|
||||
sourceBlobDigest: sha256:506597a9fce25fe757037a95da952e36f33dd702afa16c13d43c2df2d5da1ece
|
||||
codeSamplesNamespace: open-router-python-code-samples
|
||||
codeSamplesRevisionDigest: sha256:7ae639df01271894474a52b709810943afd11f8d9acde069336e9a1f8588ec56
|
||||
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
|
||||
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
|
||||
workflow:
|
||||
workflowVersion: 1.0.0
|
||||
speakeasyVersion: 1.787.0
|
||||
speakeasyVersion: latest
|
||||
sources:
|
||||
OpenRouter API:
|
||||
OpenRouter Chat Completions API:
|
||||
inputs:
|
||||
- location: .speakeasy/in.openapi.yaml
|
||||
overlays:
|
||||
- location: .speakeasy/overlays/open-enums.overlay.yaml
|
||||
- location: .speakeasy/overlays/remove-rss-responses.overlay.yaml
|
||||
- location: .speakeasy/overlays/add-headers.overlay.yaml
|
||||
- location: .speakeasy/overlays/allof-simplify.overlay.yaml
|
||||
- location: .speakeasy/overlays/boolean-query-params.overlay.yaml
|
||||
- location: .speakeasy/overlays/fix-nullable-pagination.overlay.yaml
|
||||
output: .speakeasy/out.openapi.yaml
|
||||
registry:
|
||||
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api
|
||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
||||
targets:
|
||||
open-router:
|
||||
target: python
|
||||
source: OpenRouter API
|
||||
publish:
|
||||
pypi:
|
||||
token: $pypi_token
|
||||
source: OpenRouter Chat Completions API
|
||||
codeSamples:
|
||||
registry:
|
||||
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-python-code-samples
|
||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
|
||||
labelOverride:
|
||||
fixedValue: Python (SDK)
|
||||
blocking: false
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
workflowVersion: 1.0.0
|
||||
speakeasyVersion: 1.787.0
|
||||
speakeasyVersion: latest
|
||||
sources:
|
||||
OpenRouter API:
|
||||
OpenRouter Chat Completions API:
|
||||
inputs:
|
||||
- location: .speakeasy/in.openapi.yaml
|
||||
overlays:
|
||||
- location: .speakeasy/overlays/open-enums.overlay.yaml
|
||||
- location: .speakeasy/overlays/remove-rss-responses.overlay.yaml
|
||||
- location: .speakeasy/overlays/add-headers.overlay.yaml
|
||||
- location: .speakeasy/overlays/allof-simplify.overlay.yaml
|
||||
- location: .speakeasy/overlays/boolean-query-params.overlay.yaml
|
||||
- location: .speakeasy/overlays/fix-nullable-pagination.overlay.yaml
|
||||
- location: .speakeasy/overlays/retry-transient-status-codes.overlay.yaml
|
||||
output: .speakeasy/out.openapi.yaml
|
||||
registry:
|
||||
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api
|
||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
||||
targets:
|
||||
open-router:
|
||||
target: python
|
||||
source: OpenRouter API
|
||||
publish:
|
||||
pypi:
|
||||
token: $pypi_token
|
||||
source: OpenRouter Chat Completions API
|
||||
codeSamples:
|
||||
registry:
|
||||
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-python-code-samples
|
||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
|
||||
labelOverride:
|
||||
fixedValue: Python (SDK)
|
||||
blocking: false
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
# OpenRouter Python SDK
|
||||
|
||||
The OpenRouter Python SDK is a type-safe toolkit for building AI applications with access to 400+ language models through a unified API.
|
||||
|
||||
## Why use the OpenRouter SDK?
|
||||
|
||||
Integrating AI models into applications involves handling different provider APIs, managing model-specific requirements, and avoiding common implementation mistakes. The OpenRouter SDK standardizes these integrations and protects you from footguns.
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY")
|
||||
) as client:
|
||||
response = client.chat.send(
|
||||
model="minimax/minimax-m2",
|
||||
messages=[
|
||||
{"role": "user", "content": "Explain quantum computing"}
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
The SDK provides three core benefits:
|
||||
|
||||
### Auto-generated from API specifications
|
||||
|
||||
The SDK is automatically generated from OpenRouter's OpenAPI specs and updated with every API change. New models, parameters, and features appear in your IDE autocomplete immediately. No manual updates. No version drift.
|
||||
|
||||
```python
|
||||
# When new models launch, they're available instantly
|
||||
response = client.chat.send(
|
||||
model="minimax/minimax-m2"
|
||||
)
|
||||
```
|
||||
|
||||
### Type-safe by default
|
||||
|
||||
Every parameter, response field, and configuration option is fully typed with Python type hints and validated with Pydantic. Invalid configurations are caught at runtime with clear error messages.
|
||||
|
||||
```python
|
||||
response = client.chat.send(
|
||||
model="minimax/minimax-m2",
|
||||
messages=[
|
||||
{"role": "user", "content": "Hello"}
|
||||
# ← Pydantic validates message structure
|
||||
],
|
||||
temperature=0.7, # ← Type-checked and validated
|
||||
stream=True # ← Response type changes based on this
|
||||
)
|
||||
```
|
||||
|
||||
**Actionable error messages:**
|
||||
|
||||
```python
|
||||
# Instead of generic errors, get specific guidance:
|
||||
# "Model 'openai/o1-preview' requires at least 2 messages.
|
||||
# You provided 1 message. Add a system or user message."
|
||||
```
|
||||
|
||||
**Type-safe streaming:**
|
||||
|
||||
```python
|
||||
stream = client.chat.send(
|
||||
model="minimax/minimax-m2",
|
||||
messages=[{"role": "user", "content": "Write a story"}],
|
||||
stream=True
|
||||
)
|
||||
|
||||
for event in stream:
|
||||
# Full type information for streaming responses
|
||||
content = event.choices[0].delta.content if event.choices else None
|
||||
```
|
||||
|
||||
**Async support:**
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
async with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY")
|
||||
) as client:
|
||||
response = await client.chat.send_async(
|
||||
model="minimax/minimax-m2",
|
||||
messages=[{"role": "user", "content": "Hello"}]
|
||||
)
|
||||
print(response.choices[0].message.content)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Using uv (recommended)
|
||||
uv add openrouter
|
||||
|
||||
# Using pip
|
||||
pip install openrouter
|
||||
|
||||
# Using poetry
|
||||
poetry add openrouter
|
||||
```
|
||||
|
||||
**Requirements:** Python 3.9 or higher
|
||||
|
||||
Get your API key from [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys).
|
||||
|
||||
## Quick start
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY")
|
||||
) as client:
|
||||
response = client.chat.send(
|
||||
model="minimax/minimax-m2",
|
||||
messages=[
|
||||
{"role": "user", "content": "Hello!"}
|
||||
]
|
||||
)
|
||||
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
+419
-139
@@ -1,16 +1,50 @@
|
||||
# OpenRouter SDK
|
||||
|
||||
The [OpenRouter SDK](https://openrouter.ai/docs/sdks/python) is a Python toolkit designed to help you build AI-powered features and solutions. Giving you easy access to 400+ models across providers in an easy and type-safe way.
|
||||
|
||||
To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/python/reference) and [Documentation](https://openrouter.ai/docs/sdks/python).
|
||||
|
||||
<!-- No Summary [summary] -->
|
||||
<div align="center">
|
||||
<img width="500" height="300" alt="image" src="https://github.com/user-attachments/assets/19d8ad52-cb56-4f87-8bce-9a9c2233ac16" />
|
||||
<h1>OpenRouter Python SDK</h1>
|
||||
<p>Developer-friendly Python SDK specifically catered to leverage the <strong>OpenRouter</strong> API.</p>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge" /></a>
|
||||
</div>
|
||||
|
||||
<!-- No Table of Contents [toc] -->
|
||||
|
||||
<!-- Start Summary [summary] -->
|
||||
## Summary
|
||||
|
||||
OpenRouter Chat Completions API: OpenAI-compatible Chat Completions API with additional OpenRouter features
|
||||
|
||||
For more information about the API: [OpenRouter Documentation](https://openrouter.ai/docs)
|
||||
<!-- End Summary [summary] -->
|
||||
|
||||
<!-- Start Table of Contents [toc] -->
|
||||
## Table of Contents
|
||||
<!-- $toc-max-depth=2 -->
|
||||
* [SDK Installation](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#sdk-installation)
|
||||
* [IDE Support](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#ide-support)
|
||||
* [SDK Example Usage](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#sdk-example-usage)
|
||||
* [Authentication](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#authentication)
|
||||
* [Available Resources and Operations](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#available-resources-and-operations)
|
||||
* [Server-sent event streaming](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#server-sent-event-streaming)
|
||||
* [Retries](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#retries)
|
||||
* [Error Handling](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#error-handling)
|
||||
* [Server Selection](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#server-selection)
|
||||
* [Custom HTTP Client](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#custom-http-client)
|
||||
* [Resource Management](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#resource-management)
|
||||
* [Debugging](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#debugging)
|
||||
* [Development](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#development)
|
||||
* [Maturity](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#maturity)
|
||||
* [Contributions](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#contributions)
|
||||
|
||||
<!-- End Table of Contents [toc] -->
|
||||
|
||||
<!-- Start SDK Installation [installation] -->
|
||||
## SDK Installation
|
||||
|
||||
> [!TIP]
|
||||
> To finish publishing your SDK to PyPI you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> **Python version upgrade policy**
|
||||
>
|
||||
@@ -23,7 +57,7 @@ The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
|
||||
*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
|
||||
|
||||
```bash
|
||||
uv add openrouter
|
||||
uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### PIP
|
||||
@@ -31,7 +65,7 @@ uv add openrouter
|
||||
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
|
||||
|
||||
```bash
|
||||
pip install openrouter
|
||||
pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### Poetry
|
||||
@@ -39,7 +73,7 @@ pip install openrouter
|
||||
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
|
||||
|
||||
```bash
|
||||
poetry add openrouter
|
||||
poetry add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### Shell and script usage with `uv`
|
||||
@@ -55,7 +89,7 @@ It's also possible to write a standalone Python script without needing to set up
|
||||
```python
|
||||
#!/usr/bin/env -S uv run --script
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# requires-python = ">=3.9"
|
||||
# dependencies = [
|
||||
# "openrouter",
|
||||
# ]
|
||||
@@ -74,12 +108,6 @@ Once that is saved to a file, you can run it with `uv run script.py` where
|
||||
`script.py` can be replaced with the actual file name.
|
||||
<!-- End SDK Installation [installation] -->
|
||||
|
||||
<!-- Start Requirements [requirements] -->
|
||||
## Requirements
|
||||
|
||||
This SDK requires Python 3.9 or higher. For Python version support policy, see the SDK Installation section above.
|
||||
<!-- End Requirements [requirements] -->
|
||||
|
||||
<!-- Start IDE Support [idesupport] -->
|
||||
## IDE Support
|
||||
|
||||
@@ -90,8 +118,10 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
|
||||
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
|
||||
<!-- End IDE Support [idesupport] -->
|
||||
|
||||
<!-- No SDK Example Usage [usage] -->
|
||||
## SDK Usage
|
||||
<!-- Start SDK Example Usage [usage] -->
|
||||
## SDK Example Usage
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
# Synchronous Example
|
||||
@@ -103,25 +133,20 @@ with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.send(messages=[
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], model="anthropic/claude-4.5-sonnet", provider={
|
||||
"zdr": True,
|
||||
"sort": "price",
|
||||
}, stream=True)
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
# Handle response
|
||||
print(res)
|
||||
```
|
||||
|
||||
</br>
|
||||
|
||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
||||
|
||||
```python
|
||||
# Asynchronous Example
|
||||
import asyncio
|
||||
@@ -134,103 +159,375 @@ async def main():
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = await open_router.chat.send_async(messages=[
|
||||
res = await open_router.chat.complete_async(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
<!-- End SDK Example Usage [usage] -->
|
||||
|
||||
<!-- Start Authentication [security] -->
|
||||
## Authentication
|
||||
|
||||
### Per-Client Security Schemes
|
||||
|
||||
This SDK supports the following security scheme globally:
|
||||
|
||||
| Name | Type | Scheme | Environment Variable |
|
||||
| --------- | ---- | ----------- | -------------------- |
|
||||
| `api_key` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
|
||||
|
||||
To authenticate with the API the `api_key` parameter must be set when initializing the SDK client instance. For example:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], model="anthropic/claude-4.5-sonnet", provider={
|
||||
"zdr": True,
|
||||
"sort": "price",
|
||||
}, stream=True)
|
||||
|
||||
async for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
<!-- No Authentication [security] -->
|
||||
|
||||
<!-- No Available Resources and Operations [operations] -->
|
||||
|
||||
<!-- No Standalone functions [standalone-funcs] -->
|
||||
|
||||
<!-- No React hooks with TanStack Query [react-query] -->
|
||||
|
||||
<!-- No Server-sent event streaming [eventstream] -->
|
||||
|
||||
<!-- No Retries [retries] -->
|
||||
|
||||
<!-- No Error Handling [errors] -->
|
||||
|
||||
<!-- No Server Selection [server] -->
|
||||
|
||||
<!-- No Custom HTTP Client [http-client] -->
|
||||
|
||||
<!-- Start Pagination [pagination] -->
|
||||
## Pagination
|
||||
|
||||
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
|
||||
returned response object will have a `Next` method that can be called to pull down the next group of results. If the
|
||||
return value of `Next` is `None`, then there are no more pages to be fetched.
|
||||
|
||||
Here's an example of one such pagination call:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.byok.list(offset=0, limit=50)
|
||||
|
||||
while res is not None:
|
||||
# Handle items
|
||||
|
||||
res = res.next()
|
||||
|
||||
```
|
||||
<!-- End Pagination [pagination] -->
|
||||
|
||||
<!-- Start File uploads [file-upload] -->
|
||||
## File uploads
|
||||
|
||||
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
|
||||
>
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.stt.create_transcription_multipart(file={
|
||||
"file_name": "example.file",
|
||||
"content": open("example.file", "rb"),
|
||||
}, model="openai/whisper-large-v3", language="en")
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End File uploads [file-upload] -->
|
||||
<!-- End Authentication [security] -->
|
||||
|
||||
<!-- Start Available Resources and Operations [operations] -->
|
||||
## Available Resources and Operations
|
||||
|
||||
<details open>
|
||||
<summary>Available methods</summary>
|
||||
|
||||
### [chat](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md)
|
||||
|
||||
* [complete](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md#complete) - Create a chat completion
|
||||
* [complete_stream](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md#complete_stream) - Create a chat completion
|
||||
|
||||
|
||||
</details>
|
||||
<!-- End Available Resources and Operations [operations] -->
|
||||
|
||||
<!-- Start Server-sent event streaming [eventstream] -->
|
||||
## Server-sent event streaming
|
||||
|
||||
[Server-sent events][mdn-sse] are used to stream content from certain
|
||||
operations. These operations will expose the stream as [Generator][generator] that
|
||||
can be consumed using a simple `for` loop. The loop will
|
||||
terminate when the server no longer has any events to send and closes the
|
||||
underlying connection.
|
||||
|
||||
The stream is also a [Context Manager][context-manager] and can be used with the `with` statement and will close the
|
||||
underlying connection when the context is exited.
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete_stream(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=True, temperature=1, top_p=1)
|
||||
|
||||
with res as event_stream:
|
||||
for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
|
||||
```
|
||||
|
||||
[mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
|
||||
[generator]: https://book.pythontips.com/en/latest/generators.html
|
||||
[context-manager]: https://book.pythontips.com/en/latest/context_managers.html
|
||||
<!-- End Server-sent event streaming [eventstream] -->
|
||||
|
||||
<!-- Start Retries [retries] -->
|
||||
## Retries
|
||||
|
||||
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
|
||||
|
||||
To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.utils import BackoffStrategy, RetryConfig
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1,
|
||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
|
||||
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.utils import BackoffStrategy, RetryConfig
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End Retries [retries] -->
|
||||
|
||||
<!-- Start Error Handling [errors] -->
|
||||
## Error Handling
|
||||
|
||||
[`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py) is the base class for all HTTP error responses. It has the following properties:
|
||||
|
||||
| Property | Type | Description |
|
||||
| ------------------ | ---------------- | --------------------------------------------------------------------------------------- |
|
||||
| `err.message` | `str` | Error message |
|
||||
| `err.status_code` | `int` | HTTP response status code eg `404` |
|
||||
| `err.headers` | `httpx.Headers` | HTTP response headers |
|
||||
| `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
|
||||
| `err.raw_response` | `httpx.Response` | Raw HTTP response |
|
||||
| `err.data` | | Optional. Some errors may contain structured data. [See Error Classes](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#error-classes). |
|
||||
|
||||
### Example
|
||||
```python
|
||||
from openrouter import OpenRouter, errors
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
res = None
|
||||
try:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
|
||||
except errors.OpenRouterError as e:
|
||||
# The base class for HTTP error responses
|
||||
print(e.message)
|
||||
print(e.status_code)
|
||||
print(e.body)
|
||||
print(e.headers)
|
||||
print(e.raw_response)
|
||||
|
||||
# Depending on the method different errors may be thrown
|
||||
if isinstance(e, errors.ChatCompletionError):
|
||||
print(e.data.error) # models.Error
|
||||
```
|
||||
|
||||
### Error Classes
|
||||
**Primary errors:**
|
||||
* [`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py): The base class for HTTP error responses.
|
||||
* [`ChatCompletionError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/chatcompletionerror.py): Chat completion error response.
|
||||
|
||||
<details><summary>Less common errors (5)</summary>
|
||||
|
||||
<br />
|
||||
|
||||
**Network errors:**
|
||||
* [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
|
||||
* [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
|
||||
* [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.
|
||||
|
||||
|
||||
**Inherit from [`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py)**:
|
||||
* [`ResponseValidationError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
|
||||
|
||||
</details>
|
||||
<!-- End Error Handling [errors] -->
|
||||
|
||||
<!-- Start Server Selection [server] -->
|
||||
## Server Selection
|
||||
|
||||
### Server Variables
|
||||
|
||||
The default server `https://{provider_url}/api/v1` contains variables and is set to `https://openrouter.ai/api/v1` by default. To override default values, the following parameters are available when initializing the SDK client instance:
|
||||
|
||||
| Variable | Parameter | Default | Description |
|
||||
| -------------- | ------------------- | ----------------- | ----------- |
|
||||
| `provider_url` | `provider_url: str` | `"openrouter.ai"` | |
|
||||
|
||||
#### Example
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
provider_url="https://ruddy-guacamole.info/"
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
|
||||
### Override Server URL Per-Client
|
||||
|
||||
The default server can be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
server_url="https://openrouter.ai/api/v1",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End Server Selection [server] -->
|
||||
|
||||
<!-- Start Custom HTTP Client [http-client] -->
|
||||
## Custom HTTP Client
|
||||
|
||||
The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
|
||||
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
|
||||
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
|
||||
|
||||
For example, you could specify a header for every request that this sdk makes as follows:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import httpx
|
||||
|
||||
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
|
||||
s = OpenRouter(client=http_client)
|
||||
```
|
||||
|
||||
or you could wrap the client with your own custom logic:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.httpclient import AsyncHttpClient
|
||||
import httpx
|
||||
|
||||
class CustomClient(AsyncHttpClient):
|
||||
client: AsyncHttpClient
|
||||
|
||||
def __init__(self, client: AsyncHttpClient):
|
||||
self.client = client
|
||||
|
||||
async def send(
|
||||
self,
|
||||
request: httpx.Request,
|
||||
*,
|
||||
stream: bool = False,
|
||||
auth: Union[
|
||||
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
follow_redirects: Union[
|
||||
bool, httpx._client.UseClientDefault
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
) -> httpx.Response:
|
||||
request.headers["Client-Level-Header"] = "added by client"
|
||||
|
||||
return await self.client.send(
|
||||
request, stream=stream, auth=auth, follow_redirects=follow_redirects
|
||||
)
|
||||
|
||||
def build_request(
|
||||
self,
|
||||
method: str,
|
||||
url: httpx._types.URLTypes,
|
||||
*,
|
||||
content: Optional[httpx._types.RequestContent] = None,
|
||||
data: Optional[httpx._types.RequestData] = None,
|
||||
files: Optional[httpx._types.RequestFiles] = None,
|
||||
json: Optional[Any] = None,
|
||||
params: Optional[httpx._types.QueryParamTypes] = None,
|
||||
headers: Optional[httpx._types.HeaderTypes] = None,
|
||||
cookies: Optional[httpx._types.CookieTypes] = None,
|
||||
timeout: Union[
|
||||
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
extensions: Optional[httpx._types.RequestExtensions] = None,
|
||||
) -> httpx.Request:
|
||||
return self.client.build_request(
|
||||
method,
|
||||
url,
|
||||
content=content,
|
||||
data=data,
|
||||
files=files,
|
||||
json=json,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
timeout=timeout,
|
||||
extensions=extensions,
|
||||
)
|
||||
|
||||
s = OpenRouter(async_client=CustomClient(httpx.AsyncClient()))
|
||||
```
|
||||
<!-- End Custom HTTP Client [http-client] -->
|
||||
|
||||
<!-- Start Resource Management [resource-management] -->
|
||||
## Resource Management
|
||||
@@ -245,9 +542,6 @@ import os
|
||||
def main():
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
# Rest of application here...
|
||||
@@ -257,9 +551,6 @@ def main():
|
||||
async def amain():
|
||||
|
||||
async with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
# Rest of application here...
|
||||
@@ -287,26 +578,15 @@ You can also enable a default debug logger by setting an environment variable `O
|
||||
|
||||
# Development
|
||||
|
||||
## Running Tests
|
||||
## Maturity
|
||||
|
||||
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
|
||||
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
|
||||
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
|
||||
looking for the latest version.
|
||||
|
||||
### Local Development
|
||||
## Contributions
|
||||
|
||||
1. Copy the example environment file:
|
||||
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
|
||||
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
2. Edit `.env` and add your OpenRouter API key:
|
||||
|
||||
```bash
|
||||
OPENROUTER_API_KEY=your_api_key_here
|
||||
```
|
||||
|
||||
3. Run the tests:
|
||||
|
||||
```bash
|
||||
pytest
|
||||
```
|
||||
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=open-router&utm_campaign=python)
|
||||
|
||||
@@ -1,16 +1,50 @@
|
||||
# OpenRouter SDK
|
||||
|
||||
The [OpenRouter SDK](https://openrouter.ai/docs/sdks/python) is a Python toolkit designed to help you build AI-powered features and solutions. Giving you easy access to 400+ models across providers in an easy and type-safe way.
|
||||
|
||||
To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/python/reference) and [Documentation](https://openrouter.ai/docs/sdks/python).
|
||||
|
||||
<!-- No Summary [summary] -->
|
||||
<div align="center">
|
||||
<img width="500" height="300" alt="image" src="https://github.com/user-attachments/assets/19d8ad52-cb56-4f87-8bce-9a9c2233ac16" />
|
||||
<h1>OpenRouter Python SDK</h1>
|
||||
<p>Developer-friendly Python SDK specifically catered to leverage the <strong>OpenRouter</strong> API.</p>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge" /></a>
|
||||
</div>
|
||||
|
||||
<!-- No Table of Contents [toc] -->
|
||||
|
||||
<!-- Start Summary [summary] -->
|
||||
## Summary
|
||||
|
||||
OpenRouter Chat Completions API: OpenAI-compatible Chat Completions API with additional OpenRouter features
|
||||
|
||||
For more information about the API: [OpenRouter Documentation](https://openrouter.ai/docs)
|
||||
<!-- End Summary [summary] -->
|
||||
|
||||
<!-- Start Table of Contents [toc] -->
|
||||
## Table of Contents
|
||||
<!-- $toc-max-depth=2 -->
|
||||
* [SDK Installation](#sdk-installation)
|
||||
* [IDE Support](#ide-support)
|
||||
* [SDK Example Usage](#sdk-example-usage)
|
||||
* [Authentication](#authentication)
|
||||
* [Available Resources and Operations](#available-resources-and-operations)
|
||||
* [Server-sent event streaming](#server-sent-event-streaming)
|
||||
* [Retries](#retries)
|
||||
* [Error Handling](#error-handling)
|
||||
* [Server Selection](#server-selection)
|
||||
* [Custom HTTP Client](#custom-http-client)
|
||||
* [Resource Management](#resource-management)
|
||||
* [Debugging](#debugging)
|
||||
* [Development](#development)
|
||||
* [Maturity](#maturity)
|
||||
* [Contributions](#contributions)
|
||||
|
||||
<!-- End Table of Contents [toc] -->
|
||||
|
||||
<!-- Start SDK Installation [installation] -->
|
||||
## SDK Installation
|
||||
|
||||
> [!TIP]
|
||||
> To finish publishing your SDK to PyPI you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> **Python version upgrade policy**
|
||||
>
|
||||
@@ -23,7 +57,7 @@ The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
|
||||
*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
|
||||
|
||||
```bash
|
||||
uv add openrouter
|
||||
uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### PIP
|
||||
@@ -31,7 +65,7 @@ uv add openrouter
|
||||
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
|
||||
|
||||
```bash
|
||||
pip install openrouter
|
||||
pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### Poetry
|
||||
@@ -39,7 +73,7 @@ pip install openrouter
|
||||
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
|
||||
|
||||
```bash
|
||||
poetry add openrouter
|
||||
poetry add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||
```
|
||||
|
||||
### Shell and script usage with `uv`
|
||||
@@ -55,7 +89,7 @@ It's also possible to write a standalone Python script without needing to set up
|
||||
```python
|
||||
#!/usr/bin/env -S uv run --script
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# requires-python = ">=3.9"
|
||||
# dependencies = [
|
||||
# "openrouter",
|
||||
# ]
|
||||
@@ -74,12 +108,6 @@ Once that is saved to a file, you can run it with `uv run script.py` where
|
||||
`script.py` can be replaced with the actual file name.
|
||||
<!-- End SDK Installation [installation] -->
|
||||
|
||||
<!-- Start Requirements [requirements] -->
|
||||
## Requirements
|
||||
|
||||
This SDK requires Python 3.9 or higher. For Python version support policy, see the SDK Installation section above.
|
||||
<!-- End Requirements [requirements] -->
|
||||
|
||||
<!-- Start IDE Support [idesupport] -->
|
||||
## IDE Support
|
||||
|
||||
@@ -90,8 +118,10 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
|
||||
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
|
||||
<!-- End IDE Support [idesupport] -->
|
||||
|
||||
<!-- No SDK Example Usage [usage] -->
|
||||
## SDK Usage
|
||||
<!-- Start SDK Example Usage [usage] -->
|
||||
## SDK Example Usage
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
# Synchronous Example
|
||||
@@ -103,25 +133,20 @@ with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.send(messages=[
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], model="anthropic/claude-4.5-sonnet", provider={
|
||||
"zdr": True,
|
||||
"sort": "price",
|
||||
}, stream=True)
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
# Handle response
|
||||
print(res)
|
||||
```
|
||||
|
||||
</br>
|
||||
|
||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
||||
|
||||
```python
|
||||
# Asynchronous Example
|
||||
import asyncio
|
||||
@@ -134,103 +159,375 @@ async def main():
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = await open_router.chat.send_async(messages=[
|
||||
res = await open_router.chat.complete_async(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
<!-- End SDK Example Usage [usage] -->
|
||||
|
||||
<!-- Start Authentication [security] -->
|
||||
## Authentication
|
||||
|
||||
### Per-Client Security Schemes
|
||||
|
||||
This SDK supports the following security scheme globally:
|
||||
|
||||
| Name | Type | Scheme | Environment Variable |
|
||||
| --------- | ---- | ----------- | -------------------- |
|
||||
| `api_key` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
|
||||
|
||||
To authenticate with the API the `api_key` parameter must be set when initializing the SDK client instance. For example:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], model="anthropic/claude-4.5-sonnet", provider={
|
||||
"zdr": True,
|
||||
"sort": "price",
|
||||
}, stream=True)
|
||||
|
||||
async for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
<!-- No Authentication [security] -->
|
||||
|
||||
<!-- No Available Resources and Operations [operations] -->
|
||||
|
||||
<!-- No Standalone functions [standalone-funcs] -->
|
||||
|
||||
<!-- No React hooks with TanStack Query [react-query] -->
|
||||
|
||||
<!-- No Server-sent event streaming [eventstream] -->
|
||||
|
||||
<!-- No Retries [retries] -->
|
||||
|
||||
<!-- No Error Handling [errors] -->
|
||||
|
||||
<!-- No Server Selection [server] -->
|
||||
|
||||
<!-- No Custom HTTP Client [http-client] -->
|
||||
|
||||
<!-- Start Pagination [pagination] -->
|
||||
## Pagination
|
||||
|
||||
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
|
||||
returned response object will have a `Next` method that can be called to pull down the next group of results. If the
|
||||
return value of `Next` is `None`, then there are no more pages to be fetched.
|
||||
|
||||
Here's an example of one such pagination call:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.byok.list(offset=0, limit=50)
|
||||
|
||||
while res is not None:
|
||||
# Handle items
|
||||
|
||||
res = res.next()
|
||||
|
||||
```
|
||||
<!-- End Pagination [pagination] -->
|
||||
|
||||
<!-- Start File uploads [file-upload] -->
|
||||
## File uploads
|
||||
|
||||
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
|
||||
>
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.stt.create_transcription_multipart(file={
|
||||
"file_name": "example.file",
|
||||
"content": open("example.file", "rb"),
|
||||
}, model="openai/whisper-large-v3", language="en")
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End File uploads [file-upload] -->
|
||||
<!-- End Authentication [security] -->
|
||||
|
||||
<!-- Start Available Resources and Operations [operations] -->
|
||||
## Available Resources and Operations
|
||||
|
||||
<details open>
|
||||
<summary>Available methods</summary>
|
||||
|
||||
### [chat](docs/sdks/chat/README.md)
|
||||
|
||||
* [complete](docs/sdks/chat/README.md#complete) - Create a chat completion
|
||||
* [complete_stream](docs/sdks/chat/README.md#complete_stream) - Create a chat completion
|
||||
|
||||
|
||||
</details>
|
||||
<!-- End Available Resources and Operations [operations] -->
|
||||
|
||||
<!-- Start Server-sent event streaming [eventstream] -->
|
||||
## Server-sent event streaming
|
||||
|
||||
[Server-sent events][mdn-sse] are used to stream content from certain
|
||||
operations. These operations will expose the stream as [Generator][generator] that
|
||||
can be consumed using a simple `for` loop. The loop will
|
||||
terminate when the server no longer has any events to send and closes the
|
||||
underlying connection.
|
||||
|
||||
The stream is also a [Context Manager][context-manager] and can be used with the `with` statement and will close the
|
||||
underlying connection when the context is exited.
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete_stream(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=True, temperature=1, top_p=1)
|
||||
|
||||
with res as event_stream:
|
||||
for event in event_stream:
|
||||
# handle event
|
||||
print(event, flush=True)
|
||||
|
||||
```
|
||||
|
||||
[mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
|
||||
[generator]: https://book.pythontips.com/en/latest/generators.html
|
||||
[context-manager]: https://book.pythontips.com/en/latest/context_managers.html
|
||||
<!-- End Server-sent event streaming [eventstream] -->
|
||||
|
||||
<!-- Start Retries [retries] -->
|
||||
## Retries
|
||||
|
||||
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
|
||||
|
||||
To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.utils import BackoffStrategy, RetryConfig
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1,
|
||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
|
||||
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.utils import BackoffStrategy, RetryConfig
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End Retries [retries] -->
|
||||
|
||||
<!-- Start Error Handling [errors] -->
|
||||
## Error Handling
|
||||
|
||||
[`OpenRouterError`](./src/openrouter/errors/openroutererror.py) is the base class for all HTTP error responses. It has the following properties:
|
||||
|
||||
| Property | Type | Description |
|
||||
| ------------------ | ---------------- | --------------------------------------------------------------------------------------- |
|
||||
| `err.message` | `str` | Error message |
|
||||
| `err.status_code` | `int` | HTTP response status code eg `404` |
|
||||
| `err.headers` | `httpx.Headers` | HTTP response headers |
|
||||
| `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
|
||||
| `err.raw_response` | `httpx.Response` | Raw HTTP response |
|
||||
| `err.data` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
|
||||
|
||||
### Example
|
||||
```python
|
||||
from openrouter import OpenRouter, errors
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
res = None
|
||||
try:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
|
||||
except errors.OpenRouterError as e:
|
||||
# The base class for HTTP error responses
|
||||
print(e.message)
|
||||
print(e.status_code)
|
||||
print(e.body)
|
||||
print(e.headers)
|
||||
print(e.raw_response)
|
||||
|
||||
# Depending on the method different errors may be thrown
|
||||
if isinstance(e, errors.ChatCompletionError):
|
||||
print(e.data.error) # models.Error
|
||||
```
|
||||
|
||||
### Error Classes
|
||||
**Primary errors:**
|
||||
* [`OpenRouterError`](./src/openrouter/errors/openroutererror.py): The base class for HTTP error responses.
|
||||
* [`ChatCompletionError`](./src/openrouter/errors/chatcompletionerror.py): Chat completion error response.
|
||||
|
||||
<details><summary>Less common errors (5)</summary>
|
||||
|
||||
<br />
|
||||
|
||||
**Network errors:**
|
||||
* [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
|
||||
* [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
|
||||
* [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.
|
||||
|
||||
|
||||
**Inherit from [`OpenRouterError`](./src/openrouter/errors/openroutererror.py)**:
|
||||
* [`ResponseValidationError`](./src/openrouter/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
|
||||
|
||||
</details>
|
||||
<!-- End Error Handling [errors] -->
|
||||
|
||||
<!-- Start Server Selection [server] -->
|
||||
## Server Selection
|
||||
|
||||
### Server Variables
|
||||
|
||||
The default server `https://{provider_url}/api/v1` contains variables and is set to `https://openrouter.ai/api/v1` by default. To override default values, the following parameters are available when initializing the SDK client instance:
|
||||
|
||||
| Variable | Parameter | Default | Description |
|
||||
| -------------- | ------------------- | ----------------- | ----------- |
|
||||
| `provider_url` | `provider_url: str` | `"openrouter.ai"` | |
|
||||
|
||||
#### Example
|
||||
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
provider_url="https://ruddy-guacamole.info/"
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
|
||||
### Override Server URL Per-Client
|
||||
|
||||
The default server can be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
server_url="https://openrouter.ai/api/v1",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
```
|
||||
<!-- End Server Selection [server] -->
|
||||
|
||||
<!-- Start Custom HTTP Client [http-client] -->
|
||||
## Custom HTTP Client
|
||||
|
||||
The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
|
||||
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
|
||||
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
|
||||
|
||||
For example, you could specify a header for every request that this sdk makes as follows:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
import httpx
|
||||
|
||||
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
|
||||
s = OpenRouter(client=http_client)
|
||||
```
|
||||
|
||||
or you could wrap the client with your own custom logic:
|
||||
```python
|
||||
from openrouter import OpenRouter
|
||||
from openrouter.httpclient import AsyncHttpClient
|
||||
import httpx
|
||||
|
||||
class CustomClient(AsyncHttpClient):
|
||||
client: AsyncHttpClient
|
||||
|
||||
def __init__(self, client: AsyncHttpClient):
|
||||
self.client = client
|
||||
|
||||
async def send(
|
||||
self,
|
||||
request: httpx.Request,
|
||||
*,
|
||||
stream: bool = False,
|
||||
auth: Union[
|
||||
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
follow_redirects: Union[
|
||||
bool, httpx._client.UseClientDefault
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
) -> httpx.Response:
|
||||
request.headers["Client-Level-Header"] = "added by client"
|
||||
|
||||
return await self.client.send(
|
||||
request, stream=stream, auth=auth, follow_redirects=follow_redirects
|
||||
)
|
||||
|
||||
def build_request(
|
||||
self,
|
||||
method: str,
|
||||
url: httpx._types.URLTypes,
|
||||
*,
|
||||
content: Optional[httpx._types.RequestContent] = None,
|
||||
data: Optional[httpx._types.RequestData] = None,
|
||||
files: Optional[httpx._types.RequestFiles] = None,
|
||||
json: Optional[Any] = None,
|
||||
params: Optional[httpx._types.QueryParamTypes] = None,
|
||||
headers: Optional[httpx._types.HeaderTypes] = None,
|
||||
cookies: Optional[httpx._types.CookieTypes] = None,
|
||||
timeout: Union[
|
||||
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
|
||||
] = httpx.USE_CLIENT_DEFAULT,
|
||||
extensions: Optional[httpx._types.RequestExtensions] = None,
|
||||
) -> httpx.Request:
|
||||
return self.client.build_request(
|
||||
method,
|
||||
url,
|
||||
content=content,
|
||||
data=data,
|
||||
files=files,
|
||||
json=json,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
timeout=timeout,
|
||||
extensions=extensions,
|
||||
)
|
||||
|
||||
s = OpenRouter(async_client=CustomClient(httpx.AsyncClient()))
|
||||
```
|
||||
<!-- End Custom HTTP Client [http-client] -->
|
||||
|
||||
<!-- Start Resource Management [resource-management] -->
|
||||
## Resource Management
|
||||
@@ -245,9 +542,6 @@ import os
|
||||
def main():
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
# Rest of application here...
|
||||
@@ -257,9 +551,6 @@ def main():
|
||||
async def amain():
|
||||
|
||||
async with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
# Rest of application here...
|
||||
@@ -287,26 +578,15 @@ You can also enable a default debug logger by setting an environment variable `O
|
||||
|
||||
# Development
|
||||
|
||||
## Running Tests
|
||||
## Maturity
|
||||
|
||||
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
|
||||
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
|
||||
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
|
||||
looking for the latest version.
|
||||
|
||||
### Local Development
|
||||
## Contributions
|
||||
|
||||
1. Copy the example environment file:
|
||||
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
|
||||
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
2. Edit `.env` and add your OpenRouter API key:
|
||||
|
||||
```bash
|
||||
OPENROUTER_API_KEY=your_api_key_here
|
||||
```
|
||||
|
||||
3. Run the tests:
|
||||
|
||||
```bash
|
||||
pytest
|
||||
```
|
||||
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=open-router&utm_campaign=python)
|
||||
|
||||
+3
-435
@@ -1,441 +1,9 @@
|
||||
|
||||
|
||||
## 2025-11-15 18:16:18
|
||||
## 2025-08-22 15:59:18
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.658.1 (2.755.6) https://github.com/speakeasy-api/speakeasy
|
||||
- Speakeasy CLI 1.606.2 (2.687.1) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.0.16] .
|
||||
### Releases
|
||||
- [PyPI v0.0.16] https://pypi.org/project/openrouter/0.0.16 - .
|
||||
|
||||
## 2026-06-11 00:55:55
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.9.2] .
|
||||
### Releases
|
||||
- [PyPI v0.9.2] https://pypi.org/project/openrouter/0.9.2 - .
|
||||
|
||||
## 2026-06-17 00:59:07
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.0] .
|
||||
### Releases
|
||||
- [PyPI v0.10.0] https://pypi.org/project/openrouter/0.10.0 - .
|
||||
|
||||
## 2026-06-25 21:56:51
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.1] .
|
||||
### Releases
|
||||
- [PyPI v0.10.1] https://pypi.org/project/openrouter/0.10.1 - .
|
||||
|
||||
## 2026-06-25 22:28:38
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.2] .
|
||||
### Releases
|
||||
- [PyPI v0.10.2] https://pypi.org/project/openrouter/0.10.2 - .
|
||||
|
||||
## 2026-06-26 00:15:50
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.3] .
|
||||
### Releases
|
||||
- [PyPI v0.10.3] https://pypi.org/project/openrouter/0.10.3 - .
|
||||
|
||||
## 2026-06-26 12:06:01
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.4] .
|
||||
### Releases
|
||||
- [PyPI v0.10.4] https://pypi.org/project/openrouter/0.10.4 - .
|
||||
|
||||
## 2026-06-26 14:36:56
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.5] .
|
||||
### Releases
|
||||
- [PyPI v0.10.5] https://pypi.org/project/openrouter/0.10.5 - .
|
||||
|
||||
## 2026-06-26 18:19:11
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.6] .
|
||||
### Releases
|
||||
- [PyPI v0.10.6] https://pypi.org/project/openrouter/0.10.6 - .
|
||||
|
||||
## 2026-06-26 23:43:40
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.7] .
|
||||
### Releases
|
||||
- [PyPI v0.10.7] https://pypi.org/project/openrouter/0.10.7 - .
|
||||
|
||||
## 2026-06-28 15:27:21
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.680.0 (2.788.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.10.8] .
|
||||
### Releases
|
||||
- [PyPI v0.10.8] https://pypi.org/project/openrouter/0.10.8 - .
|
||||
|
||||
## 2026-07-01 16:13:11
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.1] .
|
||||
### Releases
|
||||
- [PyPI v0.11.1] https://pypi.org/project/openrouter/0.11.1 - .
|
||||
|
||||
## 2026-07-03 15:05:16
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.2] .
|
||||
### Releases
|
||||
- [PyPI v0.11.2] https://pypi.org/project/openrouter/0.11.2 - .
|
||||
|
||||
## 2026-07-03 19:54:08
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.3] .
|
||||
### Releases
|
||||
- [PyPI v0.11.3] https://pypi.org/project/openrouter/0.11.3 - .
|
||||
|
||||
## 2026-07-07 14:30:37
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.4] .
|
||||
### Releases
|
||||
- [PyPI v0.11.4] https://pypi.org/project/openrouter/0.11.4 - .
|
||||
|
||||
## 2026-07-07 17:24:44
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.5] .
|
||||
### Releases
|
||||
- [PyPI v0.11.5] https://pypi.org/project/openrouter/0.11.5 - .
|
||||
|
||||
## 2026-07-07 19:09:09
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.6] .
|
||||
### Releases
|
||||
- [PyPI v0.11.6] https://pypi.org/project/openrouter/0.11.6 - .
|
||||
|
||||
## 2026-07-07 21:46:35
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.7] .
|
||||
### Releases
|
||||
- [PyPI v0.11.7] https://pypi.org/project/openrouter/0.11.7 - .
|
||||
|
||||
## 2026-07-08 03:29:04
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.8] .
|
||||
### Releases
|
||||
- [PyPI v0.11.8] https://pypi.org/project/openrouter/0.11.8 - .
|
||||
|
||||
## 2026-07-08 07:00:39
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.9] .
|
||||
### Releases
|
||||
- [PyPI v0.11.9] https://pypi.org/project/openrouter/0.11.9 - .
|
||||
|
||||
## 2026-07-08 09:31:18
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.10] .
|
||||
### Releases
|
||||
- [PyPI v0.11.10] https://pypi.org/project/openrouter/0.11.10 - .
|
||||
|
||||
## 2026-07-08 19:07:22
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.11] .
|
||||
### Releases
|
||||
- [PyPI v0.11.11] https://pypi.org/project/openrouter/0.11.11 - .
|
||||
|
||||
## 2026-07-09 10:13:53
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.12] .
|
||||
### Releases
|
||||
- [PyPI v0.11.12] https://pypi.org/project/openrouter/0.11.12 - .
|
||||
|
||||
## 2026-07-09 17:12:18
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.13] .
|
||||
### Releases
|
||||
- [PyPI v0.11.13] https://pypi.org/project/openrouter/0.11.13 - .
|
||||
|
||||
## 2026-07-09 17:28:34
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.14] .
|
||||
### Releases
|
||||
- [PyPI v0.11.14] https://pypi.org/project/openrouter/0.11.14 - .
|
||||
|
||||
## 2026-07-09 18:16:05
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.15] .
|
||||
### Releases
|
||||
- [PyPI v0.11.15] https://pypi.org/project/openrouter/0.11.15 - .
|
||||
|
||||
## 2026-07-09 19:48:43
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.16] .
|
||||
### Releases
|
||||
- [PyPI v0.11.16] https://pypi.org/project/openrouter/0.11.16 - .
|
||||
|
||||
## 2026-07-09 21:34:56
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.17] .
|
||||
### Releases
|
||||
- [PyPI v0.11.17] https://pypi.org/project/openrouter/0.11.17 - .
|
||||
|
||||
## 2026-07-10 01:18:52
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.18] .
|
||||
### Releases
|
||||
- [PyPI v0.11.18] https://pypi.org/project/openrouter/0.11.18 - .
|
||||
|
||||
## 2026-07-10 15:41:48
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.19] .
|
||||
### Releases
|
||||
- [PyPI v0.11.19] https://pypi.org/project/openrouter/0.11.19 - .
|
||||
|
||||
## 2026-07-10 20:14:59
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.20] .
|
||||
### Releases
|
||||
- [PyPI v0.11.20] https://pypi.org/project/openrouter/0.11.20 - .
|
||||
|
||||
## 2026-07-10 23:01:43
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.21] .
|
||||
### Releases
|
||||
- [PyPI v0.11.21] https://pypi.org/project/openrouter/0.11.21 - .
|
||||
|
||||
## 2026-07-11 03:19:26
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.22] .
|
||||
### Releases
|
||||
- [PyPI v0.11.22] https://pypi.org/project/openrouter/0.11.22 - .
|
||||
|
||||
## 2026-07-12 16:36:57
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.23] .
|
||||
### Releases
|
||||
- [PyPI v0.11.23] https://pypi.org/project/openrouter/0.11.23 - .
|
||||
|
||||
## 2026-07-13 17:54:57
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.24] .
|
||||
### Releases
|
||||
- [PyPI v0.11.24] https://pypi.org/project/openrouter/0.11.24 - .
|
||||
|
||||
## 2026-07-13 19:18:28
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.25] .
|
||||
### Releases
|
||||
- [PyPI v0.11.25] https://pypi.org/project/openrouter/0.11.25 - .
|
||||
|
||||
## 2026-07-13 19:27:34
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.26] .
|
||||
### Releases
|
||||
- [PyPI v0.11.26] https://pypi.org/project/openrouter/0.11.26 - .
|
||||
|
||||
## 2026-07-13 20:42:45
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.27] .
|
||||
### Releases
|
||||
- [PyPI v0.11.27] https://pypi.org/project/openrouter/0.11.27 - .
|
||||
|
||||
## 2026-07-14 05:35:17
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.28] .
|
||||
### Releases
|
||||
- [PyPI v0.11.28] https://pypi.org/project/openrouter/0.11.28 - .
|
||||
|
||||
## 2026-07-14 14:49:30
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.29] .
|
||||
### Releases
|
||||
- [PyPI v0.11.29] https://pypi.org/project/openrouter/0.11.29 - .
|
||||
|
||||
## 2026-07-14 17:49:24
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.30] .
|
||||
### Releases
|
||||
- [PyPI v0.11.30] https://pypi.org/project/openrouter/0.11.30 - .
|
||||
|
||||
## 2026-07-14 21:03:59
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.31] .
|
||||
### Releases
|
||||
- [PyPI v0.11.31] https://pypi.org/project/openrouter/0.11.31 - .
|
||||
|
||||
## 2026-07-14 21:26:36
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.32] .
|
||||
### Releases
|
||||
- [PyPI v0.11.32] https://pypi.org/project/openrouter/0.11.32 - .
|
||||
|
||||
## 2026-07-14 22:07:41
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc
|
||||
- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.11.33] .
|
||||
### Releases
|
||||
- [PyPI v0.11.33] https://pypi.org/project/openrouter/0.11.33 - .
|
||||
- [python v0.1.3] .
|
||||
@@ -6,13 +6,15 @@ import os
|
||||
|
||||
|
||||
with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = open_router.analytics.get_user_activity()
|
||||
res = open_router.chat.complete(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
@@ -21,7 +23,6 @@ with OpenRouter(
|
||||
</br>
|
||||
|
||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
||||
|
||||
```python
|
||||
# Asynchronous Example
|
||||
import asyncio
|
||||
@@ -31,13 +32,15 @@ import os
|
||||
async def main():
|
||||
|
||||
async with OpenRouter(
|
||||
http_referer="<value>",
|
||||
x_open_router_title="<value>",
|
||||
x_open_router_categories="<value>",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||
) as open_router:
|
||||
|
||||
res = await open_router.analytics.get_user_activity_async()
|
||||
res = await open_router.chat.complete_async(messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
},
|
||||
], stream=False, temperature=1, top_p=1)
|
||||
|
||||
# Handle response
|
||||
print(res)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
@@ -1,10 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="400" viewBox="0 0 1200 400">
|
||||
<title>OpenRouter</title>
|
||||
<path fill="currentColor" d="M431.4 196.2c0 11.2-2.1 20.8-6.2 28.8a45 45 0 0 1-41 25 44.8 44.8 0 0 1-41-25c-4.2-8-6.2-17.7-6.2-28.8 0-11.2 2-20.8 6.1-28.8a44.9 44.9 0 0 1 41.1-25 45 45 0 0 1 41 25c4.1 8 6.2 17.6 6.2 28.8m-15.7 0c0-8.5-1.4-15.7-4.1-21.6a30.6 30.6 0 0 0-11.3-13.3c-4.7-3-10.1-4.5-16.1-4.5a30 30 0 0 0-16.2 4.5c-4.7 3-8.4 7.5-11.2 13.3-2.7 5.9-4.1 13-4.1 21.6 0 8.5 1.4 15.7 4.1 21.5A30.7 30.7 0 0 0 368 231c4.8 3 10.2 4.6 16.2 4.6s11.4-1.5 16.1-4.6c4.8-3 8.5-7.4 11.3-13.3 2.7-5.8 4.1-13 4.1-21.5Zm34 81.8V170h15v12.7h1.3c.9-1.6 2.1-3.5 3.8-5.6a22 22 0 0 1 18.7-8.1 30.6 30.6 0 0 1 28.7 18.6c2.9 6 4.3 13.3 4.3 21.8s-1.4 15.8-4.2 21.8a33 33 0 0 1-11.7 14 30 30 0 0 1-17 4.9c-4.7 0-8.6-.8-11.6-2.4a22 22 0 0 1-7.1-5.6c-1.7-2.2-3-4.1-4-5.8h-.8V278h-15.3m15-68.7c0 5.5.7 10.3 2.3 14.5 1.6 4.2 4 7.4 7 9.7 3 2.4 6.7 3.5 11.1 3.5 4.6 0 8.4-1.2 11.5-3.6 3-2.5 5.4-5.8 7-10 1.6-4.2 2.4-8.9 2.4-14.1 0-5.2-.8-9.9-2.4-14a21.7 21.7 0 0 0-7-9.7 18 18 0 0 0-11.5-3.6c-4.4 0-8.1 1.1-11.2 3.4-3 2.3-5.3 5.5-7 9.6a40 40 0 0 0-2.3 14.3ZM572.4 250c-7.8 0-14.4-1.6-20-5-5.6-3.3-9.9-8-12.9-14s-4.5-13.2-4.5-21.3c0-8 1.5-15.1 4.5-21.3a35 35 0 0 1 12.7-14.4 38.5 38.5 0 0 1 32-3 31.3 31.3 0 0 1 19 19.2c2 5 2.9 11 2.9 18.2v5.4h-62.5v-11.5h47.5c0-4-.8-7.6-2.5-10.7a18.6 18.6 0 0 0-17.2-10c-4.3 0-8 1-11.2 3a22.3 22.3 0 0 0-10 19.2v9c0 5.2 1 9.6 2.8 13.3 1.9 3.7 4.5 6.5 7.8 8.4a23 23 0 0 0 11.7 2.9c3 0 5.6-.4 8-1.3a16.4 16.4 0 0 0 10.2-10l14.4 2.7c-1.1 4.3-3.2 8-6.2 11.2-3 3.2-6.7 5.6-11.2 7.4a41.7 41.7 0 0 1-15.3 2.6Zm66-48.2v46.7h-15.3V170H638v12.8h1c1.8-4.2 4.6-7.5 8.5-10 3.8-2.6 8.7-3.8 14.6-3.8 5.4 0 10 1.1 14 3.3 4.1 2.3 7.2 5.6 9.4 10a36 36 0 0 1 3.4 16.3v50h-15.3v-48.2a19 19 0 0 0-4.5-13.3c-3-3.3-7-4.9-12.2-4.9a19 19 0 0 0-9.4 2.3 16.4 16.4 0 0 0-6.5 6.8 21.8 21.8 0 0 0-2.4 10.6Zm72 46.7V143.8h37.3c8 0 14.8 1.4 20.2 4.2 5.4 2.8 9.4 6.7 12 11.6a35 35 0 0 1 4 17c0 6.5-1.3 12.1-4 17a27.3 27.3 0 0 1-12 11.3c-5.4 2.7-12.2 4-20.3 4h-28.2v-13.6h26.8c5.1 0 9.3-.7 12.5-2.2 3.2-1.4 5.6-3.6 7-6.4a21 21 0 0 0 2.3-10c0-4-.7-7.4-2.2-10.3a15.2 15.2 0 0 0-7.1-6.7 29.3 29.3 0 0 0-12.7-2.3h-19.9v91.2h-15.7m51.7-47.3 25.8 47.3h-18l-25.3-47.3h17.5Zm73 48.8a34.1 34.1 0 0 1-32-19.2 47 47 0 0 1-4.6-21.3c0-8.1 1.5-15.2 4.5-21.3a34.1 34.1 0 0 1 32-19.3 34.1 34.1 0 0 1 32 19.3 45 45 0 0 1 4.7 21.3 47 47 0 0 1-4.6 21.3 34.1 34.1 0 0 1-32 19.2m0-12.8c4.8 0 8.8-1.3 11.9-3.8 3.1-2.5 5.4-5.9 7-10a42 42 0 0 0 2.2-14c0-5-.7-9.5-2.2-13.8a22.8 22.8 0 0 0-7-10.1 18.2 18.2 0 0 0-11.9-3.8c-4.8 0-8.8 1.2-12 3.8-3 2.6-5.4 6-7 10.2a40.5 40.5 0 0 0-2.2 13.8c0 5 .8 9.6 2.3 13.8 1.5 4.2 3.8 7.6 7 10.1 3.1 2.5 7.1 3.8 12 3.8ZM938.6 216v-46h15.3v78.6h-15v-13.7h-.8a24.4 24.4 0 0 1-23.5 14.7 26 26 0 0 1-13.4-3.4 23 23 0 0 1-9-10 36.3 36.3 0 0 1-3.4-16.2v-50h15.3v48.1a18 18 0 0 0 4.4 12.8c3 3.2 6.9 4.8 11.6 4.8a19 19 0 0 0 15.7-8.7c1.9-2.9 2.8-6.6 2.8-11Zm72.5-46v12.3h-43V170h43m-31.4-18.8H995v74.3c0 3 .4 5.2 1.3 6.7.9 1.4 2 2.5 3.5 3 1.4.5 3 .8 4.6.8a176.6 176.6 0 0 0 5.4-.7l2.7 12.6a27.2 27.2 0 0 1-10 1.7c-4 0-7.7-.7-11.2-2.2a19.3 19.3 0 0 1-8.4-7c-2.1-3-3.2-7-3.2-11.7v-77.5Zm82.1 99c-7.7 0-14.4-1.7-20-5-5.5-3.4-9.8-8-12.8-14.1-3-6-4.6-13.2-4.6-21.3a47 47 0 0 1 4.6-21.3c3-6.1 7.2-11 12.6-14.4a38.5 38.5 0 0 1 32-3 31.3 31.3 0 0 1 19 19.2c2 5 3 11 3 18.2v5.4H1033v-11.5h47.4c0-4-.8-7.6-2.4-10.7a18.7 18.7 0 0 0-17.3-10c-4.3 0-8 1-11.2 3a22.9 22.9 0 0 0-9.9 19.2v9c0 5.2.9 9.6 2.8 13.3 1.8 3.7 4.4 6.5 7.8 8.4a23 23 0 0 0 11.7 2.9 24 24 0 0 0 7.9-1.3 16.7 16.7 0 0 0 10.2-9.9l14.4 2.6a26 26 0 0 1-6.2 11.2 30 30 0 0 1-11.2 7.4 41.6 41.6 0 0 1-15.3 2.6Zm50.7-1.6V170h14.8v12.5h.8c1.5-4.2 4-7.6 7.6-10 3.7-2.5 7.8-3.7 12.4-3.7a68 68 0 0 1 6.5.4v14.6a31.9 31.9 0 0 0-8-1 20 20 0 0 0-9.6 2.4 17.2 17.2 0 0 0-9.2 15.4v48h-15.3Z"/>
|
||||
<g fill="currentColor" stroke="currentColor">
|
||||
<path stroke-width="35.3" d="M46.2 200.5c5.9 0 28.6-5.1 40.3-11.8 11.8-6.6 11.8-6.6 36.1-23.9 30.8-21.8 52.5-14.5 88.2-14.5"/>
|
||||
<path stroke-width=".4" d="M245.3 150.5 185 185.3v-69.6l60.3 34.8Z"/>
|
||||
<path stroke-width="35.3" d="M45 200.5c5.9 0 28.6 5 40.4 11.7 11.7 6.7 11.7 6.7 36 24 30.8 21.8 52.5 14.5 88.2 14.5"/>
|
||||
<path stroke-width=".4" d="m244.1 250.4-60.3-34.7v69.5l60.3-34.8Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.2 KiB |
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AABenchmarkEntry"
|
||||
---
|
||||
|
||||
Artificial Analysis benchmark index scores.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- |
|
||||
| `agentic_index` | *Nullable[float]* | :heavy_check_mark: | Artificial Analysis Agentic Index score | 55.8 |
|
||||
| `coding_index` | *Nullable[float]* | :heavy_check_mark: | Artificial Analysis Coding Index score | 63.2 |
|
||||
| `intelligence_index` | *Nullable[float]* | :heavy_check_mark: | Artificial Analysis Intelligence Index score | 71.4 |
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
title: "Action"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.OutputWebSearchCallItemActionSearch`
|
||||
|
||||
```python
|
||||
value: components.OutputWebSearchCallItemActionSearch = /* values here */
|
||||
```
|
||||
|
||||
### `components.ActionOpenPage`
|
||||
|
||||
```python
|
||||
value: components.ActionOpenPage = /* values here */
|
||||
```
|
||||
|
||||
### `components.ActionFindInPage`
|
||||
|
||||
```python
|
||||
value: components.ActionFindInPage = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
title: "ActionEnum"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import ActionEnum
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: ActionEnum = "read"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"read"`
|
||||
- `"write"`
|
||||
- `"delete"`
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
title: "ActionFindInPage"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| `pattern` | *str* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.TypeFindInPage](../components/typefindinpage.mdx) | :heavy_check_mark: | N/A |
|
||||
| `url` | *str* | :heavy_check_mark: | N/A |
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "ActionOpenPage"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
|
||||
| `type` | [components.TypeOpenPage](../components/typeopenpage.mdx) | :heavy_check_mark: | N/A |
|
||||
| `url` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "ActionTypeSearch"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import ActionTypeSearch
|
||||
value: ActionTypeSearch = "search"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"search"`
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
title: "ActivityItem"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- |
|
||||
| `byok_usage_inference` | *float* | :heavy_check_mark: | BYOK inference cost in USD (external credits spent) | 0.012 |
|
||||
| `completion_tokens` | *int* | :heavy_check_mark: | Total completion tokens generated | 125 |
|
||||
| `date_` | *str* | :heavy_check_mark: | Date of the activity (YYYY-MM-DD format) | 2025-08-24 |
|
||||
| `endpoint_id` | *str* | :heavy_check_mark: | Unique identifier for the endpoint | 550e8400-e29b-41d4-a716-446655440000 |
|
||||
| `model` | *str* | :heavy_check_mark: | Model slug (e.g., "openai/gpt-4.1") | openai/gpt-4.1 |
|
||||
| `model_permaslug` | *str* | :heavy_check_mark: | Model permaslug (e.g., "openai/gpt-4.1-2025-04-14") | openai/gpt-4.1-2025-04-14 |
|
||||
| `prompt_tokens` | *int* | :heavy_check_mark: | Total prompt tokens used | 50 |
|
||||
| `provider_name` | *str* | :heavy_check_mark: | Name of the provider serving this endpoint | OpenAI |
|
||||
| `reasoning_tokens` | *int* | :heavy_check_mark: | Total reasoning tokens used | 25 |
|
||||
| `requests` | *int* | :heavy_check_mark: | Number of requests made | 5 |
|
||||
| `usage` | *float* | :heavy_check_mark: | Total cost in USD (OpenRouter credits spent) | 0.015 |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AdditionalToolsItem"
|
||||
---
|
||||
|
||||
Additional tools made available to the model at this point in the input
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| `id` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||
| `role` | [components.AdditionalToolsItemRole](../components/additionaltoolsitemrole.mdx) | :heavy_check_mark: | N/A |
|
||||
| `tools` | List[[components.AdditionalToolsItemToolUnion](../components/additionaltoolsitemtoolunion.mdx)] | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.TypeAdditionalTools](../components/typeadditionaltools.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
title: "AdditionalToolsItemRole"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AdditionalToolsItemRole
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AdditionalToolsItemRole = "unknown"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"unknown"`
|
||||
- `"user"`
|
||||
- `"assistant"`
|
||||
- `"system"`
|
||||
- `"critic"`
|
||||
- `"discriminator"`
|
||||
- `"developer"`
|
||||
- `"tool"`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "AdditionalToolsItemTool"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
|
||||
| `type` | *str* | :heavy_check_mark: | N/A |
|
||||
| `__pydantic_extra__` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
|
||||
@@ -1,168 +0,0 @@
|
||||
---
|
||||
title: "AdditionalToolsItemToolUnion"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.AdditionalToolsItemToolFunction`
|
||||
|
||||
```python
|
||||
value: components.AdditionalToolsItemToolFunction = /* values here */
|
||||
```
|
||||
|
||||
### `components.PreviewWebSearchServerTool`
|
||||
|
||||
```python
|
||||
value: components.PreviewWebSearchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.Preview20250311WebSearchServerTool`
|
||||
|
||||
```python
|
||||
value: components.Preview20250311WebSearchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.LegacyWebSearchServerTool`
|
||||
|
||||
```python
|
||||
value: components.LegacyWebSearchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.WebSearchServerTool`
|
||||
|
||||
```python
|
||||
value: components.WebSearchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.FileSearchServerTool`
|
||||
|
||||
```python
|
||||
value: components.FileSearchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.ComputerUseServerTool`
|
||||
|
||||
```python
|
||||
value: components.ComputerUseServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.CodeInterpreterServerTool`
|
||||
|
||||
```python
|
||||
value: components.CodeInterpreterServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.McpServerTool`
|
||||
|
||||
```python
|
||||
value: components.McpServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.ImageGenerationServerTool`
|
||||
|
||||
```python
|
||||
value: components.ImageGenerationServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.CodexLocalShellTool`
|
||||
|
||||
```python
|
||||
value: components.CodexLocalShellTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.ShellServerTool`
|
||||
|
||||
```python
|
||||
value: components.ShellServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.ApplyPatchServerTool`
|
||||
|
||||
```python
|
||||
value: components.ApplyPatchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.CustomTool`
|
||||
|
||||
```python
|
||||
value: components.CustomTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.AdvisorServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.AdvisorServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.SubagentServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.SubagentServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.DatetimeServerTool`
|
||||
|
||||
```python
|
||||
value: components.DatetimeServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.FilesServerTool`
|
||||
|
||||
```python
|
||||
value: components.FilesServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.FusionServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.FusionServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.ImageGenerationServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.ImageGenerationServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.SearchModelsServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.SearchModelsServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.WebFetchServerTool`
|
||||
|
||||
```python
|
||||
value: components.WebFetchServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.WebSearchServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.WebSearchServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.ApplyPatchServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.ApplyPatchServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.BashServerTool`
|
||||
|
||||
```python
|
||||
value: components.BashServerTool = /* values here */
|
||||
```
|
||||
|
||||
### `components.ShellServerToolOpenRouter`
|
||||
|
||||
```python
|
||||
value: components.ShellServerToolOpenRouter = /* values here */
|
||||
```
|
||||
|
||||
### `components.AdditionalToolsItemTool`
|
||||
|
||||
```python
|
||||
value: components.AdditionalToolsItemTool = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AdditionalToolsItemTypeFunction"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AdditionalToolsItemTypeFunction
|
||||
value: AdditionalToolsItemTypeFunction = "function"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"function"`
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AdvisorNestedTool"
|
||||
---
|
||||
|
||||
A tool made available to the advisor sub-agent. Only OpenRouter server tools (e.g. openrouter:web_search) are supported; function tools are rejected because the advisor has no way to execute them. The advisor tool may not list itself.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- |
|
||||
| `parameters` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A | |
|
||||
| `type` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `__pydantic_extra__` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A | \{<br/>"type": "openrouter:web_search"<br/>} |
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
title: "AdvisorReasoning"
|
||||
---
|
||||
|
||||
Reasoning configuration forwarded to the advisor call. Use this to control reasoning effort and token budget for models that support extended thinking.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||
| `effort` | [Optional[components.AdvisorReasoningEffort]](../components/advisorreasoningeffort.mdx) | :heavy_minus_sign: | Reasoning effort level for the advisor call. |
|
||||
| `max_tokens` | *Optional[int]* | :heavy_minus_sign: | Maximum number of reasoning tokens the advisor may use. |
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
title: "AdvisorReasoningEffort"
|
||||
---
|
||||
|
||||
Reasoning effort level for the advisor call.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AdvisorReasoningEffort
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AdvisorReasoningEffort = "max"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"max"`
|
||||
- `"xhigh"`
|
||||
- `"high"`
|
||||
- `"medium"`
|
||||
- `"low"`
|
||||
- `"minimal"`
|
||||
- `"none"`
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
title: "AdvisorServerToolConfig"
|
||||
---
|
||||
|
||||
Configuration for one openrouter:advisor server tool entry.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `forward_transcript` | *Optional[bool]* | :heavy_minus_sign: | When true, the full parent conversation is forwarded to the advisor so it sees the same context the executor does (and the tool-call `prompt`, if given, is appended as a final user turn). When false or omitted, the advisor receives only the `prompt` the executor passes in the tool call. | false |
|
||||
| `instructions` | *Optional[str]* | :heavy_minus_sign: | System instructions for the advisor sub-agent. When omitted, the advisor responds with no system prompt of its own. | You are a senior staff engineer. Give a focused, decisive plan. |
|
||||
| `max_completion_tokens` | *Optional[int]* | :heavy_minus_sign: | Maximum number of output tokens (including reasoning) the advisor may produce. When omitted, the provider's default applies. | 2048 |
|
||||
| `max_tool_calls` | *Optional[int]* | :heavy_minus_sign: | Maximum number of tool-calling steps the advisor sub-agent may take during its agentic loop. Capped at 25. Only relevant when the advisor is given tools. | 5 |
|
||||
| `model` | *Optional[str]* | :heavy_minus_sign: | Slug of the advisor model to consult (any OpenRouter model). When omitted, the executor can choose it via the tool call's `model` argument; if neither is set, the model from the outer API request is used. The advisor tool itself cannot be the advisor model. | ~anthropic/claude-opus-latest |
|
||||
| `name` | *Optional[str]* | :heavy_minus_sign: | Optional name for this advisor. The model sees one tool per named advisor (and one default for an unnamed entry). Names must be unique across advisor entries. Letters, digits, spaces, underscores, and dashes; trimmed; 1–64 chars. | reviewer |
|
||||
| `reasoning` | [Optional[components.AdvisorReasoning]](../components/advisorreasoning.mdx) | :heavy_minus_sign: | Reasoning configuration forwarded to the advisor call. Use this to control reasoning effort and token budget for models that support extended thinking. | \{<br/>"effort": "high"<br/>} |
|
||||
| `stream` | *Optional[bool]* | :heavy_minus_sign: | When true, the advisor's advice streams incrementally as it is produced. In the Responses API this emits `response.output_text.delta` events targeting the advisor output item; the final `advice` field is still set on the completed item. Has no effect on the Chat Completions API (where the advice arrives only as the final tool result). When false or omitted, the advice arrives only as the final result. | false |
|
||||
| `temperature` | *Optional[float]* | :heavy_minus_sign: | Sampling temperature forwarded to the advisor call. When omitted, the provider's default applies. | 0.7 |
|
||||
| `tools` | List[[components.AdvisorNestedTool](../components/advisornestedtool.mdx)] | :heavy_minus_sign: | Tools the advisor sub-agent may use while forming its advice. The advisor runs as an agentic sub-agent over these tools, then returns its text. Only OpenRouter server tools are supported — function tools are rejected — and the list must not include the advisor tool itself. | |
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
title: "AdvisorServerToolOpenRouter"
|
||||
---
|
||||
|
||||
OpenRouter built-in server tool: consults a higher-intelligence advisor model (any OpenRouter model) for guidance mid-generation and returns its response. The advisor may run as a sub-agent with its own tools. Include multiple entries to offer several named advisors; at most one entry may omit `name` to act as the default advisor.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| `parameters` | [Optional[components.AdvisorServerToolConfig]](../components/advisorservertoolconfig.mdx) | :heavy_minus_sign: | Configuration for one openrouter:advisor server tool entry. | \{<br/>"model": "~anthropic/claude-opus-latest",<br/>"name": "reviewer"<br/>} |
|
||||
| `type` | [components.AdvisorServerToolOpenRouterType](../components/advisorservertoolopenroutertype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AdvisorServerToolOpenRouterType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AdvisorServerToolOpenRouterType
|
||||
value: AdvisorServerToolOpenRouterType = "openrouter:advisor"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"openrouter:advisor"`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "Agent"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
|
||||
| `agent_name` | *str* | :heavy_check_mark: | N/A |
|
||||
| `__pydantic_extra__` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: "AgentMessageItem"
|
||||
---
|
||||
|
||||
A message routed between agents in a multi-agent session
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `agent` | [OptionalNullable[components.Agent]](../components/agent.mdx) | :heavy_minus_sign: | N/A | |
|
||||
| `author` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `content` | List[[components.AgentMessageItemContentUnion](../components/agentmessageitemcontentunion.mdx)] | :heavy_check_mark: | N/A | |
|
||||
| `id` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | |
|
||||
| `recipient` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `type` | [components.TypeAgentMessage](../components/typeagentmessage.mdx) | :heavy_check_mark: | N/A | |
|
||||
| `__pydantic_extra__` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A | \{<br/>"author": "/root/worker",<br/>"content": [<br/>\{<br/>"text": "Task complete.",<br/>"type": "input_text"<br/>}<br/>],<br/>"recipient": "/root",<br/>"type": "agent_message"<br/>} |
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AgentMessageItemContentInputImage"
|
||||
---
|
||||
|
||||
Image input content item
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| `detail` | [components.AgentMessageItemDetail](../components/agentmessageitemdetail.mdx) | :heavy_check_mark: | N/A |
|
||||
| `image_url` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||
| `type` | [components.AgentMessageItemTypeInputImage](../components/agentmessageitemtypeinputimage.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
title: "AgentMessageItemContentUnion"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.InputText`
|
||||
|
||||
```python
|
||||
value: components.InputText = /* values here */
|
||||
```
|
||||
|
||||
### `components.AgentMessageItemContentInputImage`
|
||||
|
||||
```python
|
||||
value: components.AgentMessageItemContentInputImage = /* values here */
|
||||
```
|
||||
|
||||
### `components.ContentEncryptedContent`
|
||||
|
||||
```python
|
||||
value: components.ContentEncryptedContent = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
---
|
||||
title: "AgentMessageItemDetail"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AgentMessageItemDetail
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AgentMessageItemDetail = "auto"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"auto"`
|
||||
- `"high"`
|
||||
- `"low"`
|
||||
- `"original"`
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AgentMessageItemTypeInputImage"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AgentMessageItemTypeInputImage
|
||||
value: AgentMessageItemTypeInputImage = "input_image"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"input_image"`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "AllowedTools"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `read_only` | *Optional[bool]* | :heavy_minus_sign: | N/A |
|
||||
| `tool_names` | List[*str*] | :heavy_minus_sign: | N/A |
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
title: "AllowedToolsUnion"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `List[str]`
|
||||
|
||||
```python
|
||||
value: List[str] = /* values here */
|
||||
```
|
||||
|
||||
### `components.AllowedTools`
|
||||
|
||||
```python
|
||||
value: components.AllowedTools = /* values here */
|
||||
```
|
||||
|
||||
### `Any`
|
||||
|
||||
```python
|
||||
value: Any = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
title: "Always"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `tool_names` | List[*str*] | :heavy_minus_sign: | N/A |
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: "AnnotationAddedEvent"
|
||||
---
|
||||
|
||||
Event emitted when a text annotation is added to output
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
||||
| `annotation` | [components.OpenAIResponsesAnnotation](../components/openairesponsesannotation.mdx) | :heavy_check_mark: | N/A | \{<br/>"file_id": "file-abc123",<br/>"filename": "research_paper.pdf",<br/>"index": 0,<br/>"type": "file_citation"<br/>} |
|
||||
| `annotation_index` | *int* | :heavy_check_mark: | N/A | |
|
||||
| `content_index` | *int* | :heavy_check_mark: | N/A | |
|
||||
| `item_id` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `output_index` | *int* | :heavy_check_mark: | N/A | |
|
||||
| `sequence_number` | *int* | :heavy_check_mark: | N/A | |
|
||||
| `type` | [components.AnnotationAddedEventType](../components/annotationaddedeventtype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnnotationAddedEventType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnnotationAddedEventType
|
||||
value: AnnotationAddedEventType = "response.output_text.annotation.added"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"response.output_text.annotation.added"`
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicAdvisorMessageUsageIteration"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
|
||||
| `cache_creation` | [OptionalNullable[components.AnthropicIterationCacheCreation]](../components/anthropiciterationcachecreation.mdx) | :heavy_minus_sign: | N/A | \{<br/>"ephemeral_1h_input_tokens": 0,<br/>"ephemeral_5m_input_tokens": 0<br/>} |
|
||||
| `cache_creation_input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `cache_read_input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `output_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `model` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `type` | [components.AnthropicAdvisorMessageUsageIterationType](../components/anthropicadvisormessageusageiterationtype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicAdvisorMessageUsageIterationType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicAdvisorMessageUsageIterationType
|
||||
value: AnthropicAdvisorMessageUsageIterationType = "advisor_message"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"advisor_message"`
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
title: "AnthropicAllowedCallers"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicAllowedCallers
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AnthropicAllowedCallers = "direct"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"direct"`
|
||||
- `"code_execution_20250825"`
|
||||
- `"code_execution_20260120"`
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
title: "AnthropicBase64ImageSource"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| `data` | *str* | :heavy_check_mark: | N/A | |
|
||||
| `media_type` | [components.AnthropicImageMimeType](../components/anthropicimagemimetype.mdx) | :heavy_check_mark: | N/A | image/jpeg |
|
||||
| `type` | [components.AnthropicBase64ImageSourceType](../components/anthropicbase64imagesourcetype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicBase64ImageSourceType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicBase64ImageSourceType
|
||||
value: AnthropicBase64ImageSourceType = "base64"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"base64"`
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
title: "AnthropicBase64PdfSource"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
||||
| `data` | *str* | :heavy_check_mark: | N/A |
|
||||
| `media_type` | [components.AnthropicBase64PdfSourceMediaType](../components/anthropicbase64pdfsourcemediatype.mdx) | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicBase64PdfSourceType](../components/anthropicbase64pdfsourcetype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicBase64PdfSourceMediaType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicBase64PdfSourceMediaType
|
||||
value: AnthropicBase64PdfSourceMediaType = "application/pdf"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"application/pdf"`
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicBase64PdfSourceType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicBase64PdfSourceType
|
||||
value: AnthropicBase64PdfSourceType = "base64"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"base64"`
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCacheControlDirective"
|
||||
---
|
||||
|
||||
Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
||||
| `ttl` | [Optional[components.AnthropicCacheControlTTL]](../components/anthropiccachecontrolttl.mdx) | :heavy_minus_sign: | N/A | 5m |
|
||||
| `type` | [components.AnthropicCacheControlDirectiveType](../components/anthropiccachecontroldirectivetype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCacheControlDirectiveType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCacheControlDirectiveType
|
||||
value: AnthropicCacheControlDirectiveType = "ephemeral"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"ephemeral"`
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCacheControlTTL"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCacheControlTTL
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AnthropicCacheControlTTL = "5m"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"5m"`
|
||||
- `"1h"`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCacheCreation"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------- | --------------------------- | --------------------------- | --------------------------- |
|
||||
| `ephemeral_1h_input_tokens` | *int* | :heavy_check_mark: | N/A |
|
||||
| `ephemeral_5m_input_tokens` | *int* | :heavy_check_mark: | N/A |
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationCharLocationParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
||||
| `cited_text` | *str* | :heavy_check_mark: | N/A |
|
||||
| `document_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `document_title` | *Nullable[str]* | :heavy_check_mark: | N/A |
|
||||
| `end_char_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `start_char_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicCitationCharLocationParamType](../components/anthropiccitationcharlocationparamtype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationCharLocationParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCitationCharLocationParamType
|
||||
value: AnthropicCitationCharLocationParamType = "char_location"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"char_location"`
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationContentBlockLocationParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `cited_text` | *str* | :heavy_check_mark: | N/A |
|
||||
| `document_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `document_title` | *Nullable[str]* | :heavy_check_mark: | N/A |
|
||||
| `end_block_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `start_block_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicCitationContentBlockLocationParamType](../components/anthropiccitationcontentblocklocationparamtype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationContentBlockLocationParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCitationContentBlockLocationParamType
|
||||
value: AnthropicCitationContentBlockLocationParamType = "content_block_location"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"content_block_location"`
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationPageLocationParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
||||
| `cited_text` | *str* | :heavy_check_mark: | N/A |
|
||||
| `document_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `document_title` | *Nullable[str]* | :heavy_check_mark: | N/A |
|
||||
| `end_page_number` | *int* | :heavy_check_mark: | N/A |
|
||||
| `start_page_number` | *int* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicCitationPageLocationParamType](../components/anthropiccitationpagelocationparamtype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationPageLocationParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCitationPageLocationParamType
|
||||
value: AnthropicCitationPageLocationParamType = "page_location"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"page_location"`
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationSearchResultLocationParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `cited_text` | *str* | :heavy_check_mark: | N/A |
|
||||
| `end_block_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `search_result_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `source` | *str* | :heavy_check_mark: | N/A |
|
||||
| `start_block_index` | *int* | :heavy_check_mark: | N/A |
|
||||
| `title` | *Nullable[str]* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicCitationSearchResultLocationParamType](../components/anthropiccitationsearchresultlocationparamtype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationSearchResultLocationParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCitationSearchResultLocationParamType
|
||||
value: AnthropicCitationSearchResultLocationParamType = "search_result_location"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"search_result_location"`
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationWebSearchResultLocationParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `cited_text` | *str* | :heavy_check_mark: | N/A |
|
||||
| `encrypted_index` | *str* | :heavy_check_mark: | N/A |
|
||||
| `title` | *Nullable[str]* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicCitationWebSearchResultLocationParamType](../components/anthropiccitationwebsearchresultlocationparamtype.mdx) | :heavy_check_mark: | N/A |
|
||||
| `url` | *str* | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCitationWebSearchResultLocationParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCitationWebSearchResultLocationParamType
|
||||
value: AnthropicCitationWebSearchResultLocationParamType = "web_search_result_location"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"web_search_result_location"`
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCompactionUsageIteration"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
||||
| `cache_creation` | [OptionalNullable[components.AnthropicIterationCacheCreation]](../components/anthropiciterationcachecreation.mdx) | :heavy_minus_sign: | N/A | \{<br/>"ephemeral_1h_input_tokens": 0,<br/>"ephemeral_5m_input_tokens": 0<br/>} |
|
||||
| `cache_creation_input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `cache_read_input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `input_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `output_tokens` | *Optional[int]* | :heavy_minus_sign: | N/A | |
|
||||
| `type` | [components.AnthropicCompactionUsageIterationType](../components/anthropiccompactionusageiterationtype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicCompactionUsageIterationType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicCompactionUsageIterationType
|
||||
value: AnthropicCompactionUsageIterationType = "compaction"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"compaction"`
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "AnthropicDocumentBlockParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `cache_control` | [Optional[components.AnthropicCacheControlDirective]](../components/anthropiccachecontroldirective.mdx) | :heavy_minus_sign: | Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format. | \{<br/>"type": "ephemeral"<br/>} |
|
||||
| `citations` | [OptionalNullable[components.AnthropicDocumentBlockParamCitations]](../components/anthropicdocumentblockparamcitations.mdx) | :heavy_minus_sign: | N/A | |
|
||||
| `context` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | |
|
||||
| `source` | [components.AnthropicDocumentBlockParamSourceUnion](../components/anthropicdocumentblockparamsourceunion.mdx) | :heavy_check_mark: | N/A | |
|
||||
| `title` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | |
|
||||
| `type` | [components.TypeDocument](../components/typedocument.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
title: "AnthropicDocumentBlockParamCitations"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `enabled` | *Optional[bool]* | :heavy_minus_sign: | N/A |
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: "AnthropicDocumentBlockParamContent1"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.AnthropicImageBlockParam`
|
||||
|
||||
```python
|
||||
value: components.AnthropicImageBlockParam = /* values here */
|
||||
```
|
||||
|
||||
### `components.AnthropicTextBlockParam`
|
||||
|
||||
```python
|
||||
value: components.AnthropicTextBlockParam = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: "AnthropicDocumentBlockParamContent2"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `str`
|
||||
|
||||
```python
|
||||
value: str = /* values here */
|
||||
```
|
||||
|
||||
### `List[components.AnthropicDocumentBlockParamContent1]`
|
||||
|
||||
```python
|
||||
value: List[components.AnthropicDocumentBlockParamContent1] = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
title: "AnthropicDocumentBlockParamSourceUnion"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.AnthropicBase64PdfSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicBase64PdfSource = /* values here */
|
||||
```
|
||||
|
||||
### `components.AnthropicPlainTextSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicPlainTextSource = /* values here */
|
||||
```
|
||||
|
||||
### `components.SourceContent`
|
||||
|
||||
```python
|
||||
value: components.SourceContent = /* values here */
|
||||
```
|
||||
|
||||
### `components.AnthropicURLPdfSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicURLPdfSource = /* values here */
|
||||
```
|
||||
|
||||
### `components.AnthropicFileDocumentSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicFileDocumentSource = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "AnthropicFileDocumentSource"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| `file_id` | *str* | :heavy_check_mark: | N/A |
|
||||
| `type` | [components.AnthropicFileDocumentSourceType](../components/anthropicfiledocumentsourcetype.mdx) | :heavy_check_mark: | N/A |
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicFileDocumentSourceType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicFileDocumentSourceType
|
||||
value: AnthropicFileDocumentSourceType = "file"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"file"`
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
title: "AnthropicImageBlockParam"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `cache_control` | [Optional[components.AnthropicCacheControlDirective]](../components/anthropiccachecontroldirective.mdx) | :heavy_minus_sign: | Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format. | \{<br/>"type": "ephemeral"<br/>} |
|
||||
| `source` | [components.AnthropicImageBlockParamSource](../components/anthropicimageblockparamsource.mdx) | :heavy_check_mark: | N/A | |
|
||||
| `type` | [components.AnthropicImageBlockParamType](../components/anthropicimageblockparamtype.mdx) | :heavy_check_mark: | N/A | |
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: "AnthropicImageBlockParamSource"
|
||||
---
|
||||
|
||||
## Supported Types
|
||||
|
||||
### `components.AnthropicBase64ImageSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicBase64ImageSource = /* values here */
|
||||
```
|
||||
|
||||
### `components.AnthropicURLImageSource`
|
||||
|
||||
```python
|
||||
value: components.AnthropicURLImageSource = /* values here */
|
||||
```
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicImageBlockParamType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicImageBlockParamType
|
||||
value: AnthropicImageBlockParamType = "image"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"image"`
|
||||
@@ -1,22 +0,0 @@
|
||||
---
|
||||
title: "AnthropicImageMimeType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicImageMimeType
|
||||
|
||||
# Open enum: unrecognized values are captured as UnrecognizedStr
|
||||
value: AnthropicImageMimeType = "image/jpeg"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
This is an open enum. Unrecognized values will not fail type checks.
|
||||
|
||||
- `"image/jpeg"`
|
||||
- `"image/png"`
|
||||
- `"image/gif"`
|
||||
- `"image/webp"`
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "AnthropicInputTokensClearAtLeastType"
|
||||
---
|
||||
|
||||
## Example Usage
|
||||
|
||||
```python
|
||||
from openrouter.components import AnthropicInputTokensClearAtLeastType
|
||||
value: AnthropicInputTokensClearAtLeastType = "input_tokens"
|
||||
```
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
- `"input_tokens"`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: "AnthropicInputTokensTrigger"
|
||||
---
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| `type` | [components.AnthropicInputTokensTriggerType](../components/anthropicinputtokenstriggertype.mdx) | :heavy_check_mark: | N/A |
|
||||
| `value` | *int* | :heavy_check_mark: | N/A |
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user