You can import the VRChat Python SDK, build a Configuration, create an ApiClient, and then use endpoint-specific API classes.
import vrchatapi
from vrchatapi.api import authentication_api
configuration = vrchatapi.Configuration(
username="your_username_or_email",
password="your_password",
)
# Build an ApiClient from the configuration (credentials + HTTP session state).
with vrchatapi.ApiClient(configuration) as api_client:
# VRChat requires app name + version + contact info in User-Agent.
api_client.user_agent = "ExampleProgram/0.0.1 [email protected]"
# Create the AuthenticationApi endpoint client using this shared ApiClient.
# You can do this for other endpoint clients similarly.
auth_api = authentication_api.AuthenticationApi(api_client)
The Python SDK uses cookies behind the scenes in its API client. If you keep the same running process and API client alive, authenticated calls can reuse the existing session.
If your app restarts, you usually need to authenticate again unless you implement your own persistent cookie/session storage around the client.
In order to accomplish this, we persist cookies to disk with pickle and reload them on startup.
Note: do not pickle the live CookieJar object directly (it contains a lock and will fail). Instead, pickle the list of cookies and rebuild a jar on load.
import os
import pickle
from http.cookiejar import CookieJar
import vrchatapi
from vrchatapi.api import authentication_api
COOKIE_FILE = "vrchat_cookies.pkl"
configuration = vrchatapi.Configuration(
username="your_username_or_email",
password="your_password",
)
with vrchatapi.ApiClient(configuration) as api_client:
api_client.user_agent = "ExampleProgram/0.0.1 [email protected]"
# If a saved cookie file exists, rebuild a CookieJar and load it.
if os.path.exists(COOKIE_FILE):
with open(COOKIE_FILE, "rb") as fh:
cookies = pickle.load(fh)
jar = CookieJar()
for cookie in cookies:
jar.set_cookie(cookie)
api_client.rest_client.cookie_jar = jar
auth_api = authentication_api.AuthenticationApi(api_client)
user = auth_api.get_current_user()
print(f"Logged in as {user.display_name}")
# Save the cookies (not the jar object itself) after successful login/use.
with open(COOKIE_FILE, "wb") as fh:
pickle.dump(list(api_client.rest_client.cookie_jar), fh)
Use pyotp to generate authenticator (TOTP) codes from your account's secret key.
Obtain this during 2FA setup on the vrchat website by pressing "Copy" on the link displayed when scanning the 2FA QR code.
It will look like this: otpauth://totp/VRChat:your_email_here?secret=COPY_THIS_SECRET&issuer=VRChat
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.